Skip to content

Commit

Permalink
Initial commit for RelateNG
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <[email protected]>

Move to src dir

Signed-off-by: Martin Davis <[email protected]>

More code

Signed-off-by: Martin Davis <[email protected]>

Get it running

Signed-off-by: Martin Davis <[email protected]>

Fix conflict

Add more short-circuits

Signed-off-by: Martin Davis <[email protected]>

Refactoring, add collinear intersection

Signed-off-by: Martin Davis <[email protected]>

Add license, more predicates

Signed-off-by: Martin Davis <[email protected]>

Renaming

Signed-off-by: Martin Davis <[email protected]>

Renaming, fix L/L short-circuit

Signed-off-by: Martin Davis <[email protected]>

WIP - more detailed intersection info

Signed-off-by: Martin Davis <[email protected]>

Add geometry dimensionality checks

Signed-off-by: Martin Davis <[email protected]>

Add LinearBoundary

Signed-off-by: Martin Davis <[email protected]>

Add header, fix imports

Rename IMPredicate methods

Refactoring

Refactoring

remove dead code

Refactor predicate model

Refactor predicate model

refactoring

Add point support

Simplify builder logic

Fix proper intersection logic

renaming

code reorg

Refactoring

refactoring

Fix order of EdgeIntersector comparison

Add AreaArea crossing test

Enhance PolygonNodeTopology to handle collinear

Add predicates

Javadoc

Add node edge handling

cleanup

fix imports

Add node evaluation

Various improvements

Various improvements

Fix touches bug

Renaming, fixes

Renaming, fixes

Improve tests

Improve perf test

Add PredicateTracer

Add short-circuit

Fix some bugs

Renaming

Refactoring

refactoring

Avoid check for empty element

Fix area-vertex evaluation

Remove unused import

Renaming

Renames

Renames

Refactor constants

Renaming, refactoring

refactoring

refactoring

rename TopologyPredicateValue

renaming

use constant

renaming

initial commit for self-noding

Add RelateNG functions

Refactor addAreaEdge

Add AB geometry edge intersection test

formatting

Refactoring to simplify

Remove single-call method

Refactoring

Renaming

various improvements

typo in comment

various improvements

refactoring

Chg addEdge method sig

Fix unit test

Improve tracing output

Finish self-intersection handling

Expose constants

javadoc, refactoring

Switch to HPRtree

Refactoring

formatting

Refactor predicate logic functions

Improve predicate logic shortcut methods

simplify code

add method

improve msg

add tests

Add relate function

Various fixes

change evaluation order

Rework point topology evaluation

refactoring

refactoring

javadoc, renaming

remove dead code

Improve relate predicate code

improve internal API

rename TopologyPredicate.value

add perf tests

refactoring

Add BoundaryNodeRule support

Fix SegmentString method usage

Align with master

Align with master

Add headers

Change classes to package-private

Javadoc

Improve TopologyPredicate API

Refactor predicate API

Refactor Predicate API

Remove return value, rename

javadoc

Remove TopologyPredicateValue

Refactor predicates

renaming

Add more functions

Add RelateNG unit test base class

Javadoc

Refactoring, add GC handling

various improvements

Imrove GC point locating

Add simple relate test

renaming, testing

renaming

Improve node location computation

Minor changes

Introduce node sections to pass intersections

refactoring

Refactoring

remove dead code

refactoring

TopologyBuilder refactoring

Refactor topology logic

simplify topology building logic

reafactoring

fix unit test

Javadoc, refactoring

refactor

refactoring, modularization

Add equalsTopo function

Add polygon id

Add tests

doc

refactoring

Fix adjacent function

Refactor out MaskPredicate

Refactoring

Fix RelateMaskPredicate logic

cleanup

Fix Relate mask predicate

Improve node evaluation logic

Add constants for relate patterns

Fix adjacent test

Improve RelateNG functions

Improve AdjacentPolygons perf test

Renaming

Modularize NodeSections

minor code cleanup

Javadoc

Regularize code

Add tests

Simplify intersection handling

remove unused method

disambiguate method

Add node section inversion

Improve NodeSection sorting

refactoring, code cleanup

Improve unit test

Add PolygonNodeInverter unit test

Generalize node conversion algorithm

Fix headers

Add PolygonNodeConverter unit test

rename collect method

javadoc

Add NG functions

code cleanup

Javadoc

Javadoc

Code cleanup

remove dead code

Handle point location on GC adjacent edges

Renaming

Change to using MCIndexSegmentSetMutualIntersector

Fix bug in AdjacentEdgeLocator

Switch to using isOnSegment

Minor code improvements

Add unit test

Change to package visible

Fix how nodes are located on boundaries

Javadoc

Javadoc

Add fix for overlapping GCs with hole

Fix polygon touching interior endpoint

Add area-line at point interaction update

Javadoc, arg order

Code cleanup, naming, refactoring

Refactor

Refactor DimensionLocation.EXTERIOR

Implement prepared RelatePointLocator

Change to using pattern from mask

Change to pattern from mask

Improve performance tests

Improve point testing performance

Javadoc

Update copyright

Add XML GC tests

Add package Javadoc

Update package Javadoc

Rename RelateNG method

Add RelatePatternPredicate short-circuit

remove debug lines

change method visibility

Refactor RelateNG API

Refactor API

Move LinearBoundary into RelatePointLocator

Refactor Locator

Improve GC scanning

Code cleanup, refactoring

Javadoc

Change API

Refactor IM pattern API

javadoc, method renaming

Javadoc

Refactoring

renaming

Renaming

change visibility to package

Renaming

Javadoc

Javavdoc

Add Relate issue tests

Add unit tests

Improve Tracer API

Cache geometry empty status

Add potential optimization

Add unit tests for zero-len line

Remove bad test

Javadoc

Javadoc

Fix handling of repeated points

Javadoc

Add optimization to skip disjoint geoms in point tests

Fix EdgeSegmentIntersector deduplication

Javadoc, refactoring

Add unit test

Add zero-length line test

Javadoc

Javadoc

Javadoc
  • Loading branch information
dr-jts committed May 13, 2024
1 parent 93f0e35 commit 75c4d13
Show file tree
Hide file tree
Showing 43 changed files with 7,573 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024 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.Geometry;
import org.locationtech.jts.operation.relateng.IntersectionMatrixPattern;
import org.locationtech.jts.operation.relateng.RelateNG;
import org.locationtech.jts.operation.relateng.RelatePredicate;

public class SelectionNGFunctions
{
public static Geometry intersects(Geometry a, final Geometry mask)
{
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return RelateNG.relate(mask, g, RelatePredicate.intersects());
}
});
}

public static Geometry intersectsPrep(Geometry a, final Geometry mask)
{
RelateNG relateNG = RelateNG.prepare(mask);
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return relateNG.evaluate(g, RelatePredicate.intersects());
}
});
}

public static Geometry covers(Geometry a, final Geometry mask)
{
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return RelateNG.relate(mask, g, RelatePredicate.covers());
}
});
}

public static Geometry coversPrep(Geometry a, final Geometry mask)
{
RelateNG relateNG = RelateNG.prepare(mask);
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return relateNG.evaluate(g, RelatePredicate.covers());
}
});
}

public static Geometry adjacent(Geometry a, final Geometry mask)
{
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return RelateNG.relate(mask, g, RelatePredicate.matches(IntersectionMatrixPattern.ADJACENT));
}
});
}

public static Geometry adjacentPrep(Geometry a, final Geometry mask)
{
RelateNG relateNG = RelateNG.prepare(mask);
return SelectionFunctions.select(a, new GeometryPredicate() {
public boolean isTrue(Geometry g) {
return relateNG.evaluate(g, RelatePredicate.matches(IntersectionMatrixPattern.ADJACENT));
}
});
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.locationtech.jts.algorithm.BoundaryNodeRule;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.operation.relate.RelateOp;
import org.locationtech.jts.operation.relateng.IntersectionMatrixPattern;
import org.locationtech.jts.operation.relateng.RelateNG;

/**
* Implementations for spatial predicate functions.
Expand All @@ -34,12 +36,24 @@ public class SpatialPredicateFunctions {
public static boolean overlaps(Geometry a, Geometry b) { return a.overlaps(b); }
public static boolean touches(Geometry a, Geometry b) { return a.touches(b); }

public static boolean interiorIntersects(Geometry a, Geometry b) { return a.relate(b, "T********"); }
public static boolean adjacentTo(Geometry a, Geometry b) { return a.relate(b, "F***T****"); }

public static String relate(Geometry a, Geometry b) {
public static boolean interiorIntersects(Geometry a, Geometry b) {
return a.relate(b, IntersectionMatrixPattern.INTERIOR_INTERSECTS);
}

public static boolean adjacent(Geometry a, Geometry b) {
return a.relate(b, IntersectionMatrixPattern.ADJACENT);
}

public static boolean containsProperly(Geometry a, Geometry b) {
return a.relate(b, IntersectionMatrixPattern.CONTAINS_PROPERLY);
}

public static String relateMatrix(Geometry a, Geometry b) {
return a.relate(b).toString();
}
public static boolean relate(Geometry a, Geometry b, String mask) {
return a.relate(b, mask);
}
public static String relateEndpoint(Geometry a, Geometry b) {
return RelateOp.relate(a, b, BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE).toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2023 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.algorithm.BoundaryNodeRule;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.operation.relateng.IntersectionMatrixPattern;
import org.locationtech.jts.operation.relateng.RelateNG;
import org.locationtech.jts.operation.relateng.RelatePredicate;

public class SpatialPredicateNGFunctions {
public static boolean contains(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.contains());
}
public static boolean covers(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.covers());
}
public static boolean coveredBy(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.coveredBy());
}
public static boolean disjoint(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.disjoint());
}
public static boolean equals(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.equalsTopo());
}
public static boolean equalsTopo(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.equalsTopo());
}
public static boolean intersects(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.intersects());
}
public static boolean crosses(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.crosses());
}
public static boolean overlaps(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.overlaps());
}
public static boolean touches(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.touches());
}
public static boolean within(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.within());
}

public static boolean adjacent(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.matches(IntersectionMatrixPattern.ADJACENT));
}

public static boolean containsProperly(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.matches(IntersectionMatrixPattern.CONTAINS_PROPERLY));
}

public static boolean interiorIntersects(Geometry a, Geometry b) {
return RelateNG.relate(a, b, RelatePredicate.matches(IntersectionMatrixPattern.INTERIOR_INTERSECTS));
}

public static boolean relate(Geometry a, Geometry b, String mask) {
return RelateNG.relate(a, b, mask);
}
public static String relateMatrix(Geometry a, Geometry b) {
return RelateNG.relate(a, b).toString();
}
public static String relateEndpoint(Geometry a, Geometry b) {
return RelateNG.relate(a, b, BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE).toString();
}
public static String relateMultiValent(Geometry a, Geometry b) {
return RelateNG.relate(a, b, BoundaryNodeRule.MULTIVALENT_ENDPOINT_BOUNDARY_RULE).toString();
}
public static String relateMonoValent(Geometry a, Geometry b) {
return RelateNG.relate(a, b, BoundaryNodeRule.MONOVALENT_ENDPOINT_BOUNDARY_RULE).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
import org.locationtech.jtstest.function.PrecisionFunctions;
import org.locationtech.jtstest.function.PreparedGeometryFunctions;
import org.locationtech.jtstest.function.SelectionFunctions;
import org.locationtech.jtstest.function.SelectionNGFunctions;
import org.locationtech.jtstest.function.SimplificationFunctions;
import org.locationtech.jtstest.function.SnappingFunctions;
import org.locationtech.jtstest.function.SortingFunctions;
import org.locationtech.jtstest.function.SpatialIndexFunctions;
import org.locationtech.jtstest.function.SpatialPredicateFunctions;
import org.locationtech.jtstest.function.SpatialPredicateNGFunctions;
import org.locationtech.jtstest.function.TriangleFunctions;
import org.locationtech.jtstest.function.TriangulatePolyFunctions;
import org.locationtech.jtstest.function.TriangulationFunctions;
Expand Down Expand Up @@ -102,6 +104,7 @@ public static GeometryFunctionRegistry createTestBuilderRegistry()
funcRegistry.add(PrecisionFunctions.class);
funcRegistry.add(PreparedGeometryFunctions.class);
funcRegistry.add(SelectionFunctions.class);
funcRegistry.add(SelectionNGFunctions.class);
funcRegistry.add(SimplificationFunctions.class);
funcRegistry.add(AffineTransformationFunctions.class);
funcRegistry.add(DiffFunctions.class);
Expand All @@ -112,6 +115,7 @@ public static GeometryFunctionRegistry createTestBuilderRegistry()
funcRegistry.add(CreateRandomShapeFunctions.class);
funcRegistry.add(SpatialIndexFunctions.class);
funcRegistry.add(SpatialPredicateFunctions.class);
funcRegistry.add(SpatialPredicateNGFunctions.class);
funcRegistry.add(JTSFunctions.class);
//funcRegistry.add(MemoryFunctions.class);
funcRegistry.add(OffsetCurveFunctions.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private static boolean isAngleGreater(Coordinate origin, Coordinate p, Coordinat
/**
* Compares the angles of two vectors
* relative to the positive X-axis at their origin.
* Angles increase CCW from the X-axis.
*
* @param origin the origin of the vectors
* @param p the endpoint of the vector P
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MCIndexSegmentSetMutualIntersector implements SegmentSetMutualInter
*/
private STRtree index = new STRtree();
private double overlapTolerance = 0.0;
private Envelope envelope = null;

/**
* Constructs a new intersector for a given set of {@link SegmentString}s.
Expand All @@ -53,6 +54,12 @@ public MCIndexSegmentSetMutualIntersector(Collection baseSegStrings)
initBaseSegments(baseSegStrings);
}

public MCIndexSegmentSetMutualIntersector(Collection baseSegStrings, Envelope env)
{
this.envelope = env;
initBaseSegments(baseSegStrings);
}

public MCIndexSegmentSetMutualIntersector(Collection baseSegStrings, double overlapTolerance)
{
initBaseSegments(baseSegStrings);
Expand Down Expand Up @@ -84,7 +91,9 @@ private void addToIndex(SegmentString segStr)
List segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
for (Iterator i = segChains.iterator(); i.hasNext(); ) {
MonotoneChain mc = (MonotoneChain) i.next();
index.insert(mc.getEnvelope(overlapTolerance), mc);
if (envelope == null || envelope.intersects(mc.getEnvelope())) {
index.insert(mc.getEnvelope(overlapTolerance), mc);
}
}
}

Expand Down Expand Up @@ -114,7 +123,9 @@ private void addToMonoChains(SegmentString segStr, List monoChains)
List segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
for (Iterator i = segChains.iterator(); i.hasNext(); ) {
MonotoneChain mc = (MonotoneChain) i.next();
monoChains.add(mc);
if (envelope == null || envelope.intersects(mc.getEnvelope())) {
monoChains.add(mc);
}
}
}

Expand Down
Loading

0 comments on commit 75c4d13

Please sign in to comment.