This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit d2bee492a2455afa5039a4593abeab78ef9bd298 Author: jsorel <[email protected]> AuthorDate: Fri Nov 27 09:34:15 2026 +0100 fix(Geometry): reject unsupported ray intersections --- .../main/org/apache/sis/geometries/operation/Intersection.java | 8 ++++---- .../org/apache/sis/geometries/operation/IntersectionTest.java | 10 ++++++++++ .../org/apache/sis/geometries/operation/IntersectsTest.java | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java index 0be92c7798..302c708547 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java @@ -967,9 +967,10 @@ public final class Intersection { * * @param ray the ray. * @param other the geometry to intersect with the ray. - * @return the intersection, or {@code null} if the type of the other geometry is not supported. + * @return the intersection. * @throws OperationException if the geometries are not in the same reference system, * or if the intersection with that geometry cannot be computed. + * @throws UnsupportedOperationException if the type of the other geometry is not supported. */ static Geometry rayIntersection(final Ray ray, final Geometry other) throws OperationException { final List<RayHit> hits; @@ -980,9 +981,8 @@ public final class Intersection { case Triangle triangle -> hits = triangleHits(ray, triangle); case Line line -> hits = polylineHits(ray, line, line.getDataPoints()); case LineString line -> hits = polylineHits(ray, line, line.getDataPoints()); - default -> { - return null; - } + default -> throw new UnsupportedOperationException( + "The intersection of a ray with a " + other.getGeometryType() + " is not supported."); } final CoordinateReferenceSystem crs = ray.getCoordinateReferenceSystem(); final GeometryFactory factory = GeometryFactory.DEFAULT; diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectionTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectionTest.java index 46f1c8c909..6c05e98d7e 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectionTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectionTest.java @@ -388,4 +388,14 @@ public class IntersectionTest extends AbstractD9IMTest { assertTrue(processor.intersection(ray(-1, 2, 2, 1, 0, 0), RING_3D).isEmpty()); } + + /** + * The intersection of a ray with a geometry type which is not supported throws an exception. + */ + @Test + public void testIntersectionOfRayAndUnsupported() { + final GeometryProcessor processor = new GeometryProcessor(); + assertThrows(UnsupportedOperationException.class, () -> processor.intersection(ray(1, 2, 0, 0, 0, 1), SQUARE)); + assertThrows(UnsupportedOperationException.class, () -> processor.intersection(SQUARE, ray(1, 2, 0, 0, 0, 1))); + } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectsTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectsTest.java index 57e06e5bca..ca6b0a4783 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectsTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/IntersectsTest.java @@ -113,7 +113,8 @@ public class IntersectsTest extends AbstractD9IMTest { new TestCase(ray(1, 2, 0, 0, 0, -1), PLANE_Z5, false, null), new TestCase(ray(-1, 2, 1, 1, 0, 0), RING_3D, true, null), new TestCase(ray(-1, 2, 2, 1, 0, 0), RING_3D, false, null), - new TestCase(ray(1, 2, 0, 0, 0, 1), quad(), null, OperationException.class) + new TestCase(ray(1, 2, 0, 0, 0, 1), quad(), null, OperationException.class), + new TestCase(ray(1, 2, 0, 0, 0, 1), SQUARE, null, UnsupportedOperationException.class) }; /**
