You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2020/08/10 11:43:01 UTC

[commons-geometry] branch master updated: GEOMETRY-63: method simplification and misc cleanup

This is an automated email from the ASF dual-hosted git repository.

mattjuntunen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e6a7f4  GEOMETRY-63: method simplification and misc cleanup
0e6a7f4 is described below

commit 0e6a7f48b449675ef1391e8491efc4a826a41bf3
Author: Matt Juntunen <ma...@apache.org>
AuthorDate: Mon Aug 10 07:22:59 2020 -0400

    GEOMETRY-63: method simplification and misc cleanup
---
 .../AbstractConvexHyperplaneBoundedRegion.java     |  7 +---
 .../bsp/AbstractPartitionedRegionBuilder.java      | 14 +------
 .../geometry/euclidean/threed/shape/Sphere.java    |  2 +-
 .../geometry/euclidean/twod/ConvexArea.java        |  4 +-
 .../geometry/spherical/oned/RegionBSPTree1S.java   | 44 ++++++++++++++--------
 5 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/AbstractConvexHyperplaneBoundedRegion.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/AbstractConvexHyperplaneBoundedRegion.java
index 01b9a1d..20e7f7b 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/AbstractConvexHyperplaneBoundedRegion.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/AbstractConvexHyperplaneBoundedRegion.java
@@ -225,22 +225,19 @@ public abstract class AbstractConvexHyperplaneBoundedRegion<P extends Point<P>,
             final Function<List<S>, R> factory) {
 
         return isFull() ?
-                splitInternalFull(splitter, thisInstance, boundaryType, factory) :
+                splitInternalFull(splitter, boundaryType, factory) :
                 splitInternalNonFull(splitter, thisInstance, boundaryType, factory);
     }
 
     /** Internal split method for use with full regions, i.e. regions that cover the entire space.
      * @param splitter splitting hyperplane
-     * @param thisInstance a reference to the current instance; this is passed as
-     *      an argument in order to allow it to be a generic type
      * @param boundaryType the type used for the boundary hyperplane subsets
      * @param factory function used to create new convex region instances
      * @param <R> Region implementation type
      * @return the result of the split operation
      */
     private <R extends AbstractConvexHyperplaneBoundedRegion<P, S>> Split<R> splitInternalFull(
-            final Hyperplane<P> splitter, final R thisInstance, final Class<S> boundaryType,
-            final Function<List<S>, R> factory) {
+            final Hyperplane<P> splitter, final Class<S> boundaryType, final Function<List<S>, R> factory) {
 
         final R minus = factory.apply(Collections.singletonList(boundaryType.cast(splitter.span())));
         final R plus = factory.apply(Collections.singletonList(boundaryType.cast(splitter.reverse().span())));
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractPartitionedRegionBuilder.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractPartitionedRegionBuilder.java
index 9af05a5..b99e6a9 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractPartitionedRegionBuilder.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractPartitionedRegionBuilder.java
@@ -149,24 +149,12 @@ public abstract class AbstractPartitionedRegionBuilder<
     private void insertBoundaryRecursive(final N node, final HyperplaneConvexSubset<P> insert,
             final HyperplaneConvexSubset<P> trimmed, final BiConsumer<N, HyperplaneConvexSubset<P>> leafFn) {
         if (node.isLeaf()) {
-            insertBoundaryRecursiveLeafNode(node, insert, trimmed, leafFn);
+            leafFn.accept(node, trimmed);
         } else {
             insertBoundaryRecursiveInternalNode(node, insert, trimmed, leafFn);
         }
     }
 
-    /** Recursive boundary insertion method for leaf nodes.
-     * @param node node to insert into
-     * @param insert the hyperplane convex subset to insert
-     * @param trimmed version of the hyperplane convex subset filling the entire space of {@code node}
-     * @param leafFn function to apply to leaf nodes
-     * @see #insertBoundaryRecursive(AbstractRegionNode, HyperplaneConvexSubset, HyperplaneConvexSubset, BiConsumer)
-     */
-    private void insertBoundaryRecursiveLeafNode(final N node, final HyperplaneConvexSubset<P> insert,
-            final HyperplaneConvexSubset<P> trimmed, final BiConsumer<N, HyperplaneConvexSubset<P>> leafFn) {
-        leafFn.accept(node, trimmed);
-    }
-
     /** Recursive boundary insertion method for internal nodes.
      * @param node node to insert into
      * @param insert the hyperplane convex subset to insert
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/shape/Sphere.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/shape/Sphere.java
index 2186a7a..352f67e 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/shape/Sphere.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/shape/Sphere.java
@@ -419,7 +419,7 @@ public final class Sphere extends AbstractNSphere<Vector3D> implements Linecasta
          * @throws IllegalStateException if no portion of the cutter plane intersects the node
          */
         private void checkedCut(final RegionNode3D node, final Plane cutter, final RegionCutRule cutRule) {
-            if (!node.insertCut(cutter)) {
+            if (!node.insertCut(cutter, cutRule)) {
                 throw new IllegalStateException("Failed to cut BSP tree node with plane: " + cutter);
             }
         }
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/ConvexArea.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/ConvexArea.java
index 7c57d2c..01dbbf1 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/ConvexArea.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/ConvexArea.java
@@ -230,8 +230,8 @@ public class ConvexArea extends AbstractConvexHyperplaneBoundedRegion<Vector2D,
                     "Cannot construct convex polygon from path with less than 3 elements: " + path);
         }
 
-        // go through the elements and validate that the produced area is convex and finite;
-        // use the precision context from the first path element
+        // go through the elements and validate that the produced area is convex and finite
+        // using the precision context from the first path element
         final LineConvexSubset startElement = elements.get(0);
         final Vector2D startVertex = startElement.getStartPoint();
         final DoublePrecisionContext precision = startElement.getPrecision();
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/RegionBSPTree1S.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/RegionBSPTree1S.java
index a976dce..f63a29f 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/RegionBSPTree1S.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/RegionBSPTree1S.java
@@ -214,22 +214,8 @@ public class RegionBSPTree1S extends AbstractRegionBSPTree<Point1S, RegionBSPTre
 
         final int boundaryPairCount = insideBoundaryPairs.size();
 
-        // Find the index of the first boundary pair that is not connected to pair before it.
-        // This will be our start point for merging intervals together.
-        int startOffset = 0;
-        if (boundaryPairCount > 1) {
-            BoundaryPair current = null;
-            BoundaryPair previous = insideBoundaryPairs.get(boundaryPairCount - 1);
-
-            for (int i = 0; i < boundaryPairCount; ++i, previous = current) {
-                current = insideBoundaryPairs.get(i);
-
-                if (!Objects.equals(current.getMin(), previous.getMax())) {
-                    startOffset = i;
-                    break;
-                }
-            }
-        }
+        // Get the start point for merging intervals together.
+        int startOffset = getIntervalStartIndex(insideBoundaryPairs);
 
         // Go through the pairs starting at the start offset and create intervals
         // for each set of adjacent pairs.
@@ -265,6 +251,32 @@ public class RegionBSPTree1S extends AbstractRegionBSPTree<Point1S, RegionBSPTre
         return intervals;
     }
 
+    /** Get the index that should be used as the starting point for combining adjacent boundary pairs
+     * into contiguous intervals. This is computed as the first boundary pair found that is not connected
+     * to the pair before it, or {@code 0} if no such entry exists.
+     * @param boundaryPairs list of boundary pairs to search; must be ordered by increasing azimuth
+     * @return the index to use as a starting place for combining adjacent boundary pairs
+     *      into contiguous intervals
+     */
+    private int getIntervalStartIndex(final List<BoundaryPair> boundaryPairs) {
+        final int size = boundaryPairs.size();
+
+        if (size > 0) {
+            BoundaryPair current = null;
+            BoundaryPair previous = boundaryPairs.get(size - 1);
+
+            for (int i = 0; i < size; ++i, previous = current) {
+                current = boundaryPairs.get(i);
+
+                if (!Objects.equals(current.getMin(), previous.getMax())) {
+                    return i;
+                }
+            }
+        }
+
+        return 0;
+    }
+
     /** Create an interval instance from the min boundary from the start boundary pair and
      * the max boundary from the end boundary pair. The hyperplane directions are adjusted
      * as needed.