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 ccb1cbe  adding missing test cases
ccb1cbe is described below

commit ccb1cbea5fbb64e5fa03b1607a196e9a35918813
Author: Matt Juntunen <[email protected]>
AuthorDate: Fri Aug 13 08:17:41 2021 -0400

    adding missing test cases
---
 .../euclidean/twod/EmbeddedTreeLineSubsetTest.java | 63 ++++++++++++++++++++++
 .../geometry/euclidean/twod/path/LinePathTest.java |  2 +-
 .../twod/AbstractGreatArcPathConnectorTest.java    | 41 ++++++++++++++
 .../twod/EmbeddedTreeSubGreatCircleTest.java       | 53 +++++++++++++++++-
 .../geometry/spherical/twod/GreatArcTest.java      | 22 ++++++++
 5 files changed, 178 insertions(+), 3 deletions(-)

diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/EmbeddedTreeLineSubsetTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/EmbeddedTreeLineSubsetTest.java
index a2a32c7..25dadf3 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/EmbeddedTreeLineSubsetTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/EmbeddedTreeLineSubsetTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.geometry.euclidean.twod;
 import java.util.List;
 
 import org.apache.commons.geometry.core.GeometryTestUtils;
+import org.apache.commons.geometry.core.RegionLocation;
 import org.apache.commons.geometry.core.partitioning.Split;
 import org.apache.commons.geometry.core.partitioning.SplitLocation;
 import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
@@ -509,6 +510,68 @@ class EmbeddedTreeLineSubsetTest {
     }
 
     @Test
+    void testClosest() {
+        // arrange
+        final RegionBSPTree1D subRegion = RegionBSPTree1D.empty();
+        subRegion.add(Interval.of(0, 2, TEST_PRECISION));
+        subRegion.add(Interval.of(3, 4, TEST_PRECISION));
+
+        final Line line = Lines.fromPointAndAngle(Vector2D.of(0, 2), 0.0, 
TEST_PRECISION);
+        final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, 
subRegion);
+
+        // act/assert
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(0, 2), 
subset.closest(Vector2D.of(0, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(0, 2), 
subset.closest(Vector2D.of(0, 3)), TEST_EPS);
+
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 2), 
subset.closest(Vector2D.of(1, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 2), 
subset.closest(Vector2D.of(1, 3)), TEST_EPS);
+
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), 
subset.closest(Vector2D.of(2, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), 
subset.closest(Vector2D.of(2, 3)), TEST_EPS);
+
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), 
subset.closest(Vector2D.of(2.4, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), 
subset.closest(Vector2D.of(2.4, 3)), TEST_EPS);
+
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(3, 2), 
subset.closest(Vector2D.of(2.6, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(3, 2), 
subset.closest(Vector2D.of(2.6, 3)), TEST_EPS);
+
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(4, 2), 
subset.closest(Vector2D.of(5, 1)), TEST_EPS);
+        EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(4, 2), 
subset.closest(Vector2D.of(5, 3)), TEST_EPS);
+    }
+
+    @Test
+    void testClosest_empty() {
+        // arrange
+        final Line line = Lines.fromPointAndAngle(Vector2D.ZERO, 0.0, 
TEST_PRECISION);
+        final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, 
RegionBSPTree1D.empty());
+
+        // act/assert
+        Assertions.assertNull(subset.closest(Vector2D.ZERO));
+    }
+
+    @Test
+    void testClassify() {
+        // arrange
+        final RegionBSPTree1D subRegion = RegionBSPTree1D.empty();
+        subRegion.add(Interval.of(0, 2, TEST_PRECISION));
+        subRegion.add(Interval.of(3, 4, TEST_PRECISION));
+
+        final Line line = Lines.fromPointAndAngle(Vector2D.of(0, 2), 0.0, 
TEST_PRECISION);
+        final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, 
subRegion);
+
+        // act/assert
+        EuclideanTestUtils.assertRegionLocation(subset, RegionLocation.INSIDE,
+                Vector2D.of(1, 2), Vector2D.of(3.5, 2));
+
+        EuclideanTestUtils.assertRegionLocation(subset, 
RegionLocation.BOUNDARY,
+                Vector2D.of(0, 2), Vector2D.of(2, 2), Vector2D.of(3, 2), 
Vector2D.of(4, 2));
+
+        EuclideanTestUtils.assertRegionLocation(subset, RegionLocation.OUTSIDE,
+                Vector2D.of(-1, 2), Vector2D.of(2.5, 2), Vector2D.of(5, 2),
+                Vector2D.of(1, 3), Vector2D.of(3.5, 1));
+    }
+
+    @Test
     void testToString() {
         // arrange
         final EmbeddedTreeLineSubset sub = new 
EmbeddedTreeLineSubset(DEFAULT_TEST_LINE);
diff --git 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/path/LinePathTest.java
 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/path/LinePathTest.java
index ce67b1e..35e532d 100644
--- 
a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/path/LinePathTest.java
+++ 
b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/path/LinePathTest.java
@@ -1097,7 +1097,7 @@ class LinePathTest {
 
         // act/assert
         Assertions.assertThrows(IllegalStateException.class, () -> 
builder.prepend(p));
-        Assertions.assertThrows(IllegalStateException.class, () -> 
builder.prepend(p));
+        Assertions.assertThrows(IllegalStateException.class, () -> 
builder.append(p));
     }
 
     @Test
diff --git 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/AbstractGreatArcPathConnectorTest.java
 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/AbstractGreatArcPathConnectorTest.java
index c173acc..ca3d52f 100644
--- 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/AbstractGreatArcPathConnectorTest.java
+++ 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/AbstractGreatArcPathConnectorTest.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.commons.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.geometry.spherical.SphericalTestUtils;
+import 
org.apache.commons.geometry.spherical.twod.AbstractGreatArcConnector.ConnectableGreatArc;
 import org.apache.commons.numbers.angle.Angle;
 import org.apache.commons.numbers.core.Precision;
 import org.junit.jupiter.api.Assertions;
@@ -260,6 +261,46 @@ class AbstractGreatArcPathConnectorTest {
     }
 
     @Test
+    void testConnectableSegment_hashCode() {
+        // arrange
+        final GreatArc arcA = GreatCircles.arcFromPoints(Point2S.PLUS_I, 
Point2S.PLUS_J, TEST_PRECISION);
+        final GreatArc arcB = GreatCircles.arcFromPoints(Point2S.PLUS_J, 
Point2S.MINUS_I, TEST_PRECISION);
+
+        final ConnectableGreatArc a = new ConnectableGreatArc(arcA);
+
+        // act
+        final int hash = a.hashCode();
+
+        // assert
+        Assertions.assertEquals(hash, a.hashCode());
+
+        Assertions.assertNotEquals(hash, new 
ConnectableGreatArc(arcB).hashCode());
+        Assertions.assertNotEquals(hash, new 
ConnectableGreatArc(Point2S.MINUS_I).hashCode());
+
+        Assertions.assertEquals(hash, new 
ConnectableGreatArc(arcA).hashCode());
+    }
+
+    @Test
+    void testConnectableSegment_equals() {
+        // arrange
+        final GreatArc arcA = GreatCircles.arcFromPoints(Point2S.PLUS_I, 
Point2S.PLUS_J, TEST_PRECISION);
+        final GreatArc arcB = GreatCircles.arcFromPoints(Point2S.PLUS_J, 
Point2S.MINUS_I, TEST_PRECISION);
+
+        final ConnectableGreatArc a = new ConnectableGreatArc(arcA);
+
+        // act/assert
+        Assertions.assertEquals(a, a);
+
+        Assertions.assertFalse(a.equals(null));
+        Assertions.assertFalse(a.equals(new Object()));
+
+        Assertions.assertNotEquals(a, new ConnectableGreatArc(arcB));
+        Assertions.assertNotEquals(a, new 
ConnectableGreatArc(Point2S.MINUS_I));
+
+        Assertions.assertEquals(a, new ConnectableGreatArc(arcA));
+    }
+
+    @Test
     void testConnectorCanBeReused() {
         // arrange
         final GreatArc a = GreatCircles.arcFromPoints(Point2S.PLUS_I, 
Point2S.PLUS_J, TEST_PRECISION);
diff --git 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/EmbeddedTreeSubGreatCircleTest.java
 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/EmbeddedTreeSubGreatCircleTest.java
index 981e67c..f5453fd 100644
--- 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/EmbeddedTreeSubGreatCircleTest.java
+++ 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/EmbeddedTreeSubGreatCircleTest.java
@@ -26,14 +26,14 @@ import 
org.apache.commons.geometry.core.partitioning.SplitLocation;
 import org.apache.commons.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.geometry.spherical.SphericalTestUtils;
 import org.apache.commons.geometry.spherical.oned.AngularInterval;
+import org.apache.commons.geometry.spherical.oned.Point1S;
 import org.apache.commons.geometry.spherical.oned.RegionBSPTree1S;
 import org.apache.commons.numbers.angle.Angle;
 import org.apache.commons.numbers.core.Precision;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-
-class    EmbeddedTreeSubGreatCircleTest {
+class EmbeddedTreeSubGreatCircleTest {
 
     private static final double TEST_EPS = 1e-10;
 
@@ -49,6 +49,8 @@ class    EmbeddedTreeSubGreatCircleTest {
         final EmbeddedTreeGreatCircleSubset sub = new 
EmbeddedTreeGreatCircleSubset(XY_CIRCLE);
 
         // assert
+        Assertions.assertSame(XY_CIRCLE, sub.getHyperplane());
+        Assertions.assertSame(TEST_PRECISION, sub.getPrecision());
         Assertions.assertFalse(sub.isFull());
         Assertions.assertTrue(sub.isEmpty());
         Assertions.assertTrue(sub.isFinite());
@@ -137,6 +139,53 @@ class    EmbeddedTreeSubGreatCircleTest {
     }
 
     @Test
+    void testToSubspace() {
+        // arrange
+        final EmbeddedTreeGreatCircleSubset sub = new 
EmbeddedTreeGreatCircleSubset(XY_CIRCLE);
+
+        // act/assert
+        SphericalTestUtils.assertPointsEqual(Point1S.of(1), 
sub.toSubspace(Point2S.of(1, 0.5)), TEST_EPS);
+        SphericalTestUtils.assertPointsEqual(Point1S.of(1), 
sub.toSubspace(Point2S.of(1, 0.75)), TEST_EPS);
+    }
+
+    @Test
+    void testToSpace() {
+        // arrange
+        final EmbeddedTreeGreatCircleSubset sub = new 
EmbeddedTreeGreatCircleSubset(XY_CIRCLE);
+
+        // act/assert
+        SphericalTestUtils.assertPointsEqual(Point2S.of(0, 0.5 * Math.PI), 
sub.toSpace(Point1S.of(0)), TEST_EPS);
+        SphericalTestUtils.assertPointsEqual(Point2S.of(1, 0.5 * Math.PI), 
sub.toSpace(Point1S.of(1)), TEST_EPS);
+    }
+
+    @Test
+    void testClosest() {
+        // arrange
+        final RegionBSPTree1S tree = 
RegionBSPTree1S.fromInterval(AngularInterval.of(1, 2, TEST_PRECISION));
+        final EmbeddedTreeGreatCircleSubset sub = new 
EmbeddedTreeGreatCircleSubset(XY_CIRCLE, tree);
+
+        final double halfPi = 0.5 * Math.PI;
+        final double above = halfPi - 0.1;
+        final double below = halfPi + 0.1;
+
+        // act/assert
+        SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), 
sub.closest(Point2S.of(0, above)), TEST_EPS);
+        SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), 
sub.closest(Point2S.of(0, below)), TEST_EPS);
+
+        SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), 
sub.closest(Point2S.of(1, above)), TEST_EPS);
+        SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), 
sub.closest(Point2S.of(1, below)), TEST_EPS);
+
+        SphericalTestUtils.assertPointsEq(Point2S.of(1.5, halfPi), 
sub.closest(Point2S.of(1.5, above)), TEST_EPS);
+        SphericalTestUtils.assertPointsEq(Point2S.of(1.5, halfPi), 
sub.closest(Point2S.of(1.5, below)), TEST_EPS);
+
+        SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), 
sub.closest(Point2S.of(2, above)), TEST_EPS);
+        SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), 
sub.closest(Point2S.of(2, below)), TEST_EPS);
+
+        SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), 
sub.closest(Point2S.of(3, above)), TEST_EPS);
+        SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), 
sub.closest(Point2S.of(3, below)), TEST_EPS);
+    }
+
+    @Test
     void testTransform() {
         // arrange
         final GreatCircle circle = GreatCircles.fromPoints(Point2S.PLUS_K, 
Point2S.MINUS_I, TEST_PRECISION);
diff --git 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/GreatArcTest.java
 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/GreatArcTest.java
index 6e3b035..93d41f4 100644
--- 
a/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/GreatArcTest.java
+++ 
b/commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/GreatArcTest.java
@@ -172,6 +172,28 @@ class GreatArcTest {
     }
 
     @Test
+    void testGetMidPoint() {
+        // arrange
+        final GreatArc arc = GreatCircles.arcFromInterval(
+                GreatCircles.fromPoints(Point2S.PLUS_I, Point2S.PLUS_J, 
TEST_PRECISION),
+                AngularInterval.Convex.of(0.8 * Math.PI, 0.9 * Math.PI, 
TEST_PRECISION));
+
+        // act/assert
+        SphericalTestUtils.assertPointsEqual(Point2S.of(0.85 * Math.PI, 0.5 * 
Math.PI), arc.getMidPoint(), TEST_EPS);
+    }
+
+    @Test
+    void testGetMidPoint_full() {
+        // arrange
+        final GreatArc arc = GreatCircles.arcFromInterval(
+                GreatCircles.fromPoints(Point2S.PLUS_I, Point2S.PLUS_J, 
TEST_PRECISION),
+                AngularInterval.full());
+
+        // act/assert
+        Assertions.assertNull(arc.getMidPoint());
+    }
+
+    @Test
     void testReverse_full() {
         // arrange
         final GreatArc arc = GreatCircles.arcFromInterval(

Reply via email to