You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/01/25 14:46:41 UTC
[commons-geometry] 03/04: GEOMETRY-38: fixing issue where
PolyhedronsSet.firstIntersection does not detect intersections on
subhyperplane boundaries
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
commit 17833efe2b8f1b563e8c261a28d26af441a3778c
Author: Matt Juntunen <ma...@hotmail.com>
AuthorDate: Thu Jan 24 21:10:48 2019 -0500
GEOMETRY-38: fixing issue where PolyhedronsSet.firstIntersection does not detect intersections on subhyperplane boundaries
---
.../geometry/euclidean/threed/PolyhedronsSet.java | 4 +--
.../euclidean/threed/PolyhedronsSetTest.java | 38 +++++++++++++++++++++-
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java
index 58269fe..b52e3e5 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSet.java
@@ -548,11 +548,11 @@ public class PolyhedronsSet extends AbstractRegion<Vector3D, Vector2D> {
final BoundaryAttribute<Vector3D> attribute =
(BoundaryAttribute<Vector3D>) node.getAttribute();
if ((attribute.getPlusOutside() != null) &&
- (((SubPlane) attribute.getPlusOutside()).getRemainingRegion().checkPoint(Vector2D) == Location.INSIDE)) {
+ (((SubPlane) attribute.getPlusOutside()).getRemainingRegion().checkPoint(Vector2D) != Location.OUTSIDE)) {
return attribute.getPlusOutside();
}
if ((attribute.getPlusInside() != null) &&
- (((SubPlane) attribute.getPlusInside()).getRemainingRegion().checkPoint(Vector2D) == Location.INSIDE)) {
+ (((SubPlane) attribute.getPlusInside()).getRemainingRegion().checkPoint(Vector2D) != Location.OUTSIDE)) {
return attribute.getPlusInside();
}
return null;
diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java
index efc5a39..e4c1a3e 100644
--- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java
+++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/PolyhedronsSetTest.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
package org.apache.commons.geometry.euclidean.threed;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -891,6 +890,43 @@ public class PolyhedronsSetTest {
Assert.assertEquals(null, polySet.firstIntersection(Vector3D.of(0, 0, -1.1), zMinus));
}
+ // issue GEOMETRY-38
+ @Test
+ public void testFirstIntersection_linesPassThroughBoundaries() {
+ // arrange
+ Vector3D lowerCorner = Vector3D.ZERO;
+ Vector3D upperCorner = Vector3D.of(1, 1, 1);
+ Vector3D center = lowerCorner.lerp(upperCorner, 0.5);
+
+ List<SubHyperplane<Vector3D>> boundaries = createBoxBoundaries(center, 1.0, TEST_TOLERANCE);
+ PolyhedronsSet polySet = new PolyhedronsSet(boundaries, TEST_TOLERANCE);
+
+ Line upDiagonal = new Line(lowerCorner, upperCorner, TEST_TOLERANCE);
+ Line downDiagonal = upDiagonal.revert();
+
+ // act/assert
+ SubPlane upFromOutsideResult = (SubPlane) polySet.firstIntersection(Vector3D.of(-1, -1, -1), upDiagonal);
+ Assert.assertNotNull(upFromOutsideResult);
+ EuclideanTestUtils.assertCoordinatesEqual(lowerCorner,
+ ((Plane) upFromOutsideResult.getHyperplane()).intersection(upDiagonal), TEST_TOLERANCE);
+
+ SubPlane upFromCenterResult = (SubPlane) polySet.firstIntersection(center, upDiagonal);
+ Assert.assertNotNull(upFromCenterResult);
+ EuclideanTestUtils.assertCoordinatesEqual(upperCorner,
+ ((Plane) upFromCenterResult.getHyperplane()).intersection(upDiagonal), TEST_TOLERANCE);
+
+ SubPlane downFromOutsideResult = (SubPlane) polySet.firstIntersection(Vector3D.of(2, 2, 2), downDiagonal);
+ Assert.assertNotNull(downFromOutsideResult);
+ EuclideanTestUtils.assertCoordinatesEqual(upperCorner,
+ ((Plane) downFromOutsideResult.getHyperplane()).intersection(downDiagonal), TEST_TOLERANCE);
+
+ SubPlane downFromCenterResult = (SubPlane) polySet.firstIntersection(center, downDiagonal);
+ Assert.assertNotNull(downFromCenterResult);
+ EuclideanTestUtils.assertCoordinatesEqual(lowerCorner,
+ ((Plane) downFromCenterResult.getHyperplane()).intersection(downDiagonal), TEST_TOLERANCE);
+ }
+
+
// Issue 1211
// See https://issues.apache.org/jira/browse/MATH-1211
@Test