]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/common/models/Point.java
Change Sphere center to use Point not Coords and Offsets
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / common / models / Point.java
1 package com.irtimaled.bbor.common.models;
2
3 import com.irtimaled.bbor.common.TypeHelper;
4
5 public class Point {
6     private final double x;
7     private final double y;
8     private final double z;
9
10     public Point(double x, double y, double z) {
11         this.x = x;
12         this.y = y;
13         this.z = z;
14     }
15
16     public Point(Coords Coords) {
17         this.x = Coords.getX();
18         this.y = Coords.getY();
19         this.z = Coords.getZ();
20     }
21
22     public double getX() {
23         return x;
24     }
25
26     public double getY() {
27         return y;
28     }
29
30     public double getZ() {
31         return z;
32     }
33
34     public Point offset(double x, double y, double z) {
35         return new Point(this.x + x, this.y + y, this.z + z);
36     }
37
38     public double getDistance(Point point) {
39         double dx = this.x - point.x;
40         double dy = this.y - point.y;
41         double dz = this.z - point.z;
42         return Math.sqrt(dx * dx + dy * dy + dz * dz);
43     }
44
45     public Coords getCoords() {
46         return new Coords(x, y, z);
47     }
48
49     @Override
50     public int hashCode() {
51         return TypeHelper.combineHashCodes(Double.hashCode(z), Double.hashCode(y), Double.hashCode(x));
52     }
53
54     @Override
55     public boolean equals(Object obj) {
56         if (this == obj) return true;
57         if (obj == null || getClass() != obj.getClass()) return false;
58         Point point = (Point) obj;
59         return getX() == point.getX() && getY() == point.getY() && getZ() == point.getZ();
60     }
61 }