@@ -171,12 +171,20 @@ private WorldViewerBucket(int initialCapacity, boolean pointStorage) {
171171
172172 private void add (double x , double y , double z ) {
173173 if (pointStorage ) {
174- if (size == points .length ) {
175- points = grow (points , grownCapacity (size ));
176- }
177- points [size ++] = new Point (x , y , z );
174+ addPoint (x , y , z );
178175 return ;
179176 }
177+ addCoordinates (x , y , z );
178+ }
179+
180+ private void addPoint (double x , double y , double z ) {
181+ if (size == points .length ) {
182+ points = grow (points , grownCapacity (size ));
183+ }
184+ points [size ++] = new Point (x , y , z );
185+ }
186+
187+ private void addCoordinates (double x , double y , double z ) {
180188 if (size == xCoordinates .length ) {
181189 int capacity = grownCapacity (size );
182190 xCoordinates = grow (xCoordinates , capacity );
@@ -190,18 +198,25 @@ private void add(double x, double y, double z) {
190198 }
191199
192200 private boolean hasViewerWithin (double x , double y , double z , double rangeSquared ) {
193- if (pointStorage ) {
194- for (int index = 0 ; index < size ; index ++) {
195- Point point = points [index ];
196- double deltaX = point .x () - x ;
197- double deltaY = point .y () - y ;
198- double deltaZ = point .z () - z ;
199- if (deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ <= rangeSquared ) {
200- return true ;
201- }
201+ return pointStorage
202+ ? hasPointWithin (x , y , z , rangeSquared )
203+ : hasCoordinatesWithin (x , y , z , rangeSquared );
204+ }
205+
206+ private boolean hasPointWithin (double x , double y , double z , double rangeSquared ) {
207+ for (int index = 0 ; index < size ; index ++) {
208+ Point point = points [index ];
209+ double deltaX = point .x () - x ;
210+ double deltaY = point .y () - y ;
211+ double deltaZ = point .z () - z ;
212+ if (deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ <= rangeSquared ) {
213+ return true ;
202214 }
203- return false ;
204215 }
216+ return false ;
217+ }
218+
219+ private boolean hasCoordinatesWithin (double x , double y , double z , double rangeSquared ) {
205220 for (int index = 0 ; index < size ; index ++) {
206221 double deltaX = xCoordinates [index ] - x ;
207222 double deltaY = yCoordinates [index ] - y ;
0 commit comments