]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/models/BoundingBoxSphere.java
0fdb1f1c0bed39f659be912b4d007283e34931c0
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / models / BoundingBoxSphere.java
1 package com.irtimaled.bbor.client.models;
2
3 import com.irtimaled.bbor.common.BoundingBoxType;
4 import com.irtimaled.bbor.common.models.AbstractBoundingBox;
5 import com.irtimaled.bbor.common.models.Coords;
6
7 public class BoundingBoxSphere extends AbstractBoundingBox {
8     private final double radius;
9     private final double minX;
10     private final double minZ;
11     private final double maxX;
12     private final double maxZ;
13     private final Point point;
14
15     public BoundingBoxSphere(Point point, double radius, BoundingBoxType type) {
16         super(type);
17         this.radius = radius;
18         this.point = point;
19
20         Coords center = point.getCoords();
21         this.minX = center.getX() - radius;
22         this.minZ = center.getZ() - radius;
23         this.maxX = center.getX() + radius;
24         this.maxZ = center.getZ() + radius;
25     }
26
27     @Override
28     public Boolean intersectsBounds(int minX, int minZ, int maxX, int maxZ) {
29         return this.maxX >= minX &&
30                 this.maxZ >= minZ &&
31                 this.minX <= maxX &&
32                 this.minZ <= maxZ;
33     }
34
35     @Override
36     protected double getDistanceX(double x) {
37         return x - point.getX();
38     }
39
40     @Override
41     protected double getDistanceY(double y) {
42         return y - point.getY();
43     }
44
45     @Override
46     protected double getDistanceZ(double z) {
47         return z - point.getZ();
48     }
49
50     public double getRadius() {
51         return radius;
52     }
53
54     public Point getPoint() {
55         return point;
56     }
57 }