]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java
Upgrade to 1.13.2
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / common / models / BoundingBoxSphere.java
1 package com.irtimaled.bbor.common.models;
2
3 import com.irtimaled.bbor.common.BoundingBoxType;
4
5 public class BoundingBoxSphere extends AbstractBoundingBox {
6     private final Coords center;
7     private final Integer radius;
8     private final int minX;
9     private final int minZ;
10     private final int maxX;
11     private final int maxZ;
12
13     private Double centerOffsetX = 0d;
14     private Double centerOffsetY = 0d;
15     private Double centerOffsetZ = 0d;
16
17     protected BoundingBoxSphere(BoundingBoxType type, Coords center, Integer radius) {
18         super(type);
19         this.center = center;
20         this.radius = radius;
21
22         this.minX = center.getX() - radius;
23         this.minZ = center.getZ() - radius;
24         this.maxX = center.getX() + radius;
25         this.maxZ = center.getZ() + radius;
26     }
27
28     @Override
29     public Boolean intersectsBounds(int minX, int minZ, int maxX, int maxZ) {
30         return this.maxX >= minX &&
31                 this.maxZ >= minZ &&
32                 this.minX <= maxX &&
33                 this.minZ <= maxZ;
34     }
35
36     @Override
37     public String toString() {
38         return "(" + center.toString() + "; " + radius.toString() + ")";
39     }
40
41     public Integer getRadius() {
42         return radius;
43     }
44
45     public Coords getCenter() {
46         return center;
47     }
48
49     public Double getCenterOffsetX() {
50         return centerOffsetX;
51     }
52
53     public Double getCenterOffsetY() {
54         return centerOffsetY;
55     }
56
57     public Double getCenterOffsetZ() {
58         return centerOffsetZ;
59     }
60
61     void setCenterOffsets(double x, double y, double z) {
62         this.centerOffsetX = x;
63         this.centerOffsetY = y;
64         this.centerOffsetZ = z;
65     }
66 }