]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/common/models/Point.java
a049d8379770ed61f3c1f6dd671761a9013c17d2
[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.MathHelper;
4 import com.irtimaled.bbor.common.TypeHelper;
5 import net.minecraft.util.math.Vec3d;
6
7 public class Point {
8     private final double x;
9     private final double y;
10     private final double z;
11
12     public Point(double x, double y, double z) {
13         this.x = x;
14         this.y = y;
15         this.z = z;
16     }
17
18     public Point(Coords Coords) {
19         this.x = Coords.getX();
20         this.y = Coords.getY();
21         this.z = Coords.getZ();
22     }
23
24     public Point(Vec3d pos) {
25         this.x = pos.x;
26         this.y = pos.y;
27         this.z = pos.z;
28     }
29
30     public double getX() {
31         return x;
32     }
33
34     public double getY() {
35         return y;
36     }
37
38     public double getZ() {
39         return z;
40     }
41
42     public Point offset(double x, double y, double z) {
43         return new Point(this.x + x, this.y + y, this.z + z);
44     }
45
46     public Point snapXZ(double nearest) {
47         double x = MathHelper.snapToNearest(this.x, nearest);
48         double z = MathHelper.snapToNearest(this.z, nearest);
49         return new Point(x, this.y, z);
50     }
51
52     public double getDistance(Point point) {
53         double dx = this.x - point.x;
54         double dy = this.y - point.y;
55         double dz = this.z - point.z;
56         return Math.sqrt(dx * dx + dy * dy + dz * dz);
57     }
58
59     public Coords getCoords() {
60         return new Coords(x, y, z);
61     }
62
63     @Override
64     public int hashCode() {
65         return TypeHelper.combineHashCodes(Double.hashCode(z), Double.hashCode(y), Double.hashCode(x));
66     }
67
68     @Override
69     public boolean equals(Object obj) {
70         if (this == obj) return true;
71         if (obj == null || getClass() != obj.getClass()) return false;
72         Point point = (Point) obj;
73         return getX() == point.getX() && getY() == point.getY() && getZ() == point.getZ();
74     }
75 }