diff --git a/modules/app/src/main/java/org/locationtech/jtstest/function/OrientationFPFunctions.java b/modules/app/src/main/java/org/locationtech/jtstest/function/OrientationFPFunctions.java new file mode 100644 index 0000000000..a0c8ed77b5 --- /dev/null +++ b/modules/app/src/main/java/org/locationtech/jtstest/function/OrientationFPFunctions.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Martin Davis. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * and Eclipse Distribution License v. 1.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html + * and the Eclipse Distribution License is available at + * + * http://www.eclipse.org/org/documents/edl-v10.php. + */ +package org.locationtech.jtstest.function; + +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; + +public class OrientationFPFunctions { + + public static int orientationIndex(Geometry segment, Geometry ptGeom) { + if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) { + throw new IllegalArgumentException("A must have two points and B must have one"); + } + Coordinate[] segPt = segment.getCoordinates(); + + Coordinate p = ptGeom.getCoordinate(); + int index = orientationIndex(segPt[0], segPt[1], p); + return index; + } + + private static int orientationIndex(Coordinate p1, Coordinate p2, Coordinate q) + { + double dx1 = p2.x - p1.x; + double dy1 = p2.y - p1.y; + double dx2 = q.x - p2.x; + double dy2 = q.y - p2.y; + double det = dx1*dy2 - dx2*dy1; + if (det > 0.0) return 1; + if (det < 0.0) return -1; + return 0; + } +} diff --git a/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/GeometryFunctionRegistry.java b/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/GeometryFunctionRegistry.java index 319bfb67a3..c7f02cc2a2 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/GeometryFunctionRegistry.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/GeometryFunctionRegistry.java @@ -45,6 +45,7 @@ import org.locationtech.jtstest.function.LinearReferencingFunctions; import org.locationtech.jtstest.function.NodingFunctions; import org.locationtech.jtstest.function.OffsetCurveFunctions; +import org.locationtech.jtstest.function.OrientationFPFunctions; import org.locationtech.jtstest.function.OrientationFunctions; import org.locationtech.jtstest.function.OverlayFunctions; import org.locationtech.jtstest.function.OverlayNGFunctions; @@ -120,6 +121,7 @@ public static GeometryFunctionRegistry createTestBuilderRegistry() //funcRegistry.add(MemoryFunctions.class); funcRegistry.add(OffsetCurveFunctions.class); funcRegistry.add(OrientationFunctions.class); + funcRegistry.add(OrientationFPFunctions.class); funcRegistry.add(LineSegmentFunctions.class); funcRegistry.add(OverlayFunctions.class);