Skip to content

Commit

Permalink
Add OrientationFP functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed May 27, 2024
1 parent e751aa2 commit 3d75eb1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3d75eb1

Please sign in to comment.