Loading...
Searching...
No Matches
Vector3d.java
Go to the documentation of this file.
1package com.navigine.idl.java;
2
7public final class Vector3d implements Comparable<Vector3d> {
8
9
10 /*package*/ final float x;
11
12 /*package*/ final float y;
13
14 /*package*/ final float z;
15
19 public Vector3d(
20 float x,
21 float y,
22 float z) {
23 this.x = x;
24 this.y = y;
25 this.z = z;
26 }
27
28 public float getX() {
29 return x;
30 }
31
32 public float getY() {
33 return y;
34 }
35
36 public float getZ() {
37 return z;
38 }
39
40 @Override
41 public boolean equals(Object obj) {
42 if (!(obj instanceof Vector3d)) {
43 return false;
44 }
45 Vector3d other = (Vector3d) obj;
46 return this.x == other.x &&
47 this.y == other.y &&
48 this.z == other.z;
49 }
50
51 @Override
52 public int hashCode() {
53 // Pick an arbitrary non-zero starting value
54 int hashCode = 17;
55 hashCode = hashCode * 31 + Float.floatToIntBits(x);
56 hashCode = hashCode * 31 + Float.floatToIntBits(y);
57 hashCode = hashCode * 31 + Float.floatToIntBits(z);
58 return hashCode;
59 }
60
61 @Override
62 public String toString() {
63 return "Vector3d{" +
64 "x=" + x +
65 "," + "y=" + y +
66 "," + "z=" + z +
67 "}";
68 }
69
70
71 @Override
72 public int compareTo(Vector3d other) {
73 int tempResult;
74 if (this.x < other.x) {
75 tempResult = -1;
76 } else if (this.x > other.x) {
77 tempResult = 1;
78 } else {
79 tempResult = 0;
80 }
81 if (tempResult != 0) {
82 return tempResult;
83 }
84 if (this.y < other.y) {
85 tempResult = -1;
86 } else if (this.y > other.y) {
87 tempResult = 1;
88 } else {
89 tempResult = 0;
90 }
91 if (tempResult != 0) {
92 return tempResult;
93 }
94 if (this.z < other.z) {
95 tempResult = -1;
96 } else if (this.z > other.z) {
97 tempResult = 1;
98 } else {
99 tempResult = 0;
100 }
101 if (tempResult != 0) {
102 return tempResult;
103 }
104 return 0;
105 }
106}