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