Loading...
Searching...
No Matches
Vector3d.java
Go to the documentation of this file.
1package com.navigine.idl.java;
2
15public final class Vector3d implements Comparable<Vector3d> {
16
17
18 /*package*/ final float x;
19
20 /*package*/ final float y;
21
22 /*package*/ final float z;
23
27 public Vector3d(
28 float x,
29 float y,
30 float z) {
31 this.x = x;
32 this.y = y;
33 this.z = z;
34 }
35
39 public float getX() {
40 return x;
41 }
42
46 public float getY() {
47 return y;
48 }
49
53 public float getZ() {
54 return z;
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (!(obj instanceof Vector3d)) {
60 return false;
61 }
62 Vector3d other = (Vector3d) obj;
63 return this.x == other.x &&
64 this.y == other.y &&
65 this.z == other.z;
66 }
67
68 @Override
69 public int hashCode() {
70 // Pick an arbitrary non-zero starting value
71 int hashCode = 17;
72 hashCode = hashCode * 31 + Float.floatToIntBits(x);
73 hashCode = hashCode * 31 + Float.floatToIntBits(y);
74 hashCode = hashCode * 31 + Float.floatToIntBits(z);
75 return hashCode;
76 }
77
78 @Override
79 public String toString() {
80 return "Vector3d{" +
81 "x=" + x +
82 "," + "y=" + y +
83 "," + "z=" + z +
84 "}";
85 }
86
87
88 @Override
89 public int compareTo(Vector3d other) {
90 int tempResult;
91 if (this.x < other.x) {
92 tempResult = -1;
93 } else if (this.x > other.x) {
94 tempResult = 1;
95 } else {
96 tempResult = 0;
97 }
98 if (tempResult != 0) {
99 return tempResult;
100 }
101 if (this.y < other.y) {
102 tempResult = -1;
103 } else if (this.y > other.y) {
104 tempResult = 1;
105 } else {
106 tempResult = 0;
107 }
108 if (tempResult != 0) {
109 return tempResult;
110 }
111 if (this.z < other.z) {
112 tempResult = -1;
113 } else if (this.z > other.z) {
114 tempResult = 1;
115 } else {
116 tempResult = 0;
117 }
118 if (tempResult != 0) {
119 return tempResult;
120 }
121 return 0;
122 }
123}