Search in sources :

Example 6 with LineIntersector

use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.

the class SegmentIntersector method addIntersections.

/**
 * This method is called by clients of the EdgeIntersector class to test for and add
 * intersections for two segments of the edges being intersected.
 * Note that clients (such as MonotoneChainEdges) may choose not to intersect
 * certain pairs of segments for efficiency reasons.
 */
public void addIntersections(final Edge edge1, final LineString line1, final int segIndex0, final Edge edge2, final LineString line2, final int segIndex1) {
    if (edge1 == edge2 && segIndex0 == segIndex1) {
        return;
    } else {
        this.numTests++;
        final double line1x1 = line1.getX(segIndex0);
        final double line1y1 = line1.getY(segIndex0);
        final double line1x2 = line1.getX(segIndex0 + 1);
        final double line1y2 = line1.getY(segIndex0 + 1);
        final double line2x1 = line2.getX(segIndex1);
        final double line2y1 = line2.getY(segIndex1);
        final double line2x2 = line2.getX(segIndex1 + 1);
        final double line2y2 = line2.getY(segIndex1 + 1);
        final LineIntersector lineIntersector = this.lineIntersector;
        lineIntersector.computeIntersection(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
        /**
         *  Always record any non-proper intersections.
         *  If includeProper is true, record any proper intersections as well.
         */
        if (lineIntersector.hasIntersection()) {
            if (this.recordIsolated) {
                edge1.setIsolated(false);
                edge2.setIsolated(false);
            }
            // if the segments are adjacent they have at least one trivial
            // intersection,
            // the shared endpoint. Don't bother adding it if it is the
            // only intersection.
            boolean trivialIntersection = false;
            if (edge1 == edge2) {
                if (lineIntersector.getIntersectionCount() == 1) {
                    if (Math.abs(segIndex0 - segIndex1) == 1) {
                        trivialIntersection = true;
                    } else if (line1.isClosed()) {
                        final int maxSegIndex = line1.getVertexCount() - 1;
                        if (segIndex0 == 0 && segIndex1 == maxSegIndex || segIndex1 == 0 && segIndex0 == maxSegIndex) {
                            trivialIntersection = true;
                        }
                    }
                }
            }
            if (!trivialIntersection) {
                this.hasIntersection = true;
                if (this.includeProper || !lineIntersector.isProper()) {
                    edge1.addIntersections(lineIntersector, segIndex0, 0);
                    edge2.addIntersections(lineIntersector, segIndex1, 1);
                }
                if (lineIntersector.isProper()) {
                    this.properIntersectionPoint = lineIntersector.getIntersection(0);
                    this.hasProper = true;
                    if (!isBoundaryPoint()) {
                        this.hasProperInterior = true;
                    }
                }
            }
        }
    }
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector)

Example 7 with LineIntersector

use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.

the class IsValidOp method checkValidLinearRing.

/**
 * Checks validity of a LinearRing.
 */
private boolean checkValidLinearRing(final LinearRing ring) {
    boolean valid = true;
    if (checkTooFewVertices(ring, 4)) {
        valid &= checkClosedRing(ring);
        if (isErrorReturn()) {
            return false;
        }
        final GeometryGraph graph = new GeometryGraph(0, ring);
        final LineIntersector li = new RobustLineIntersector();
        graph.computeSelfNodes(li, true);
        valid &= checkNoSelfIntersectingRings(graph);
        return valid;
    }
    return false;
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) GeometryGraph(com.revolsys.geometry.geomgraph.GeometryGraph)

Example 8 with LineIntersector

use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.

the class NodingFunctions method MCIndexNodingWithPrecision.

public static Geometry MCIndexNodingWithPrecision(final Geometry geom, final double scaleFactor) {
    final List segs = newNodedSegmentStrings(geom);
    final LineIntersector li = new RobustLineIntersector(scaleFactor);
    final Noder noder = new MCIndexNoder(new IntersectionAdder(li));
    noder.computeNodes(segs);
    final Collection nodedSegStrings = noder.getNodedSubstrings();
    return fromSegmentStrings(nodedSegStrings);
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) IntersectionAdder(com.revolsys.geometry.noding.IntersectionAdder) MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) Noder(com.revolsys.geometry.noding.Noder) ScaledNoder(com.revolsys.geometry.noding.ScaledNoder)

Aggregations

LineIntersector (com.revolsys.geometry.algorithm.LineIntersector)8 RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)6 IntersectionAdder (com.revolsys.geometry.noding.IntersectionAdder)2 MCIndexNoder (com.revolsys.geometry.noding.MCIndexNoder)2 GeometryGraph (com.revolsys.geometry.geomgraph.GeometryGraph)1 Node (com.revolsys.geometry.geomgraph.Node)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 Noder (com.revolsys.geometry.noding.Noder)1 ScaledNoder (com.revolsys.geometry.noding.ScaledNoder)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1