@@ -43,10 +43,7 @@ class BoundingBox {
43
43
* @return true if the point is inside the bounding box, false otherwise
44
44
*/
45
45
public boolean containsPoint (Point point ) {
46
- return point .x >= center .x - halfWidth
47
- && point .x <= center .x + halfWidth
48
- && point .y >= center .y - halfWidth
49
- && point .y <= center .y + halfWidth ;
46
+ return point .x >= center .x - halfWidth && point .x <= center .x + halfWidth && point .y >= center .y - halfWidth && point .y <= center .y + halfWidth ;
50
47
}
51
48
52
49
/**
@@ -56,10 +53,8 @@ public boolean containsPoint(Point point) {
56
53
* @return true if the bounding box intersects with the other bounding box, false otherwise
57
54
*/
58
55
public boolean intersectsBoundingBox (BoundingBox otherBoundingBox ) {
59
- return otherBoundingBox .center .x - otherBoundingBox .halfWidth <= center .x + halfWidth
60
- && otherBoundingBox .center .x + otherBoundingBox .halfWidth >= center .x - halfWidth
61
- && otherBoundingBox .center .y - otherBoundingBox .halfWidth <= center .y + halfWidth
62
- && otherBoundingBox .center .y + otherBoundingBox .halfWidth >= center .y - halfWidth ;
56
+ return otherBoundingBox .center .x - otherBoundingBox .halfWidth <= center .x + halfWidth && otherBoundingBox .center .x + otherBoundingBox .halfWidth >= center .x - halfWidth && otherBoundingBox .center .y - otherBoundingBox .halfWidth <= center .y + halfWidth
57
+ && otherBoundingBox .center .y + otherBoundingBox .halfWidth >= center .y - halfWidth ;
63
58
}
64
59
}
65
60
@@ -123,10 +118,21 @@ public boolean insert(Point point) {
123
118
}
124
119
125
120
// try to add the point in one of the four quadrants
126
- if (northWest .insert (point )) return true ;
127
- if (northEast .insert (point )) return true ;
128
- if (southWest .insert (point )) return true ;
129
- if (southEast .insert (point )) return true ;
121
+ if (northWest .insert (point )) {
122
+ return true ;
123
+ }
124
+
125
+ if (northEast .insert (point )) {
126
+ return true ;
127
+ }
128
+
129
+ if (southWest .insert (point )) {
130
+ return true ;
131
+ }
132
+
133
+ if (southEast .insert (point )) {
134
+ return true ;
135
+ }
130
136
131
137
return false ;
132
138
}
0 commit comments