Search in sources :

Example 1 with LineIntersector

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

the class SegmentIntersector method isBoundaryPoint.

private boolean isBoundaryPoint(final Collection<Node> boundaryNodes) {
    final LineIntersector lineIntersector = this.lineIntersector;
    for (final Node node : boundaryNodes) {
        final double x = node.getX();
        final double y = node.getY();
        if (lineIntersector.isIntersection(x, y)) {
            return true;
        }
    }
    return false;
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) Node(com.revolsys.geometry.geomgraph.Node)

Example 2 with LineIntersector

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

the class Buffer method buffer.

/**
 * Comutes the buffer for a geometry for a given buffer distance
 * and accuracy of approximation.
 *
 * @param g the geometry to buffer
 * @param distance the buffer distance
 * @param parameters the buffer parameters to use
 * @return the buffer of the input geometry
 */
@SuppressWarnings("unchecked")
public static <G extends Geometry> G buffer(final Geometry geometry, final double distance, final BufferParameters parameters) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    try {
        final MCIndexNoder noder = new MCIndexNoder();
        final LineIntersector li = new RobustLineIntersector(geometryFactory.getScaleXY());
        noder.setSegmentIntersector(new IntersectionAdder(li));
        return (G) buffer(noder, geometryFactory, geometry, distance, parameters);
    } catch (final RuntimeException e) {
        if (geometryFactory.isFloating()) {
            return (G) bufferReducedPrecision(geometry, distance, parameters);
        } else {
            return (G) bufferFixedPrecision(geometryFactory, geometry, distance, parameters);
        }
    }
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) IntersectionAdder(com.revolsys.geometry.noding.IntersectionAdder)

Example 3 with LineIntersector

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

the class RobustLineIntersectionTest method checkIntersection.

/**
 * Check that intersection of segment defined by points in pt array
 * is equal to the expectedIntPt value (up to the given distanceTolerance).
 *
 * @param pt
 * @param expectedIntersectionNum
 * @param distanceTolerance tolerance to use for equality test
 * @param expectedIntPt the expected intersection points (maybe null if not tested)
 */
void checkIntersection(final Point[] pt, final int expectedIntersectionNum, final double distanceTolerance, final Point... expectedIntPt) {
    final LineIntersector li = new RobustLineIntersector();
    li.computeIntersectionPoints(pt[0], pt[1], pt[2], pt[3]);
    final int intNum = li.getIntersectionCount();
    assertEquals("Number of intersections not as expected", expectedIntersectionNum, intNum);
    if (expectedIntPt != null) {
        assertEquals("Wrong number of expected int pts provided", intNum, expectedIntPt.length);
        // test that both points are represented here
        final boolean isIntPointsCorrect = true;
        if (intNum == 1) {
            checkIntPoints(expectedIntPt[0], li.getIntersection(0), distanceTolerance);
        } else if (intNum == 2) {
            checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
            checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
            if (!(equals(expectedIntPt[0], li.getIntersection(0), distanceTolerance) || equals(expectedIntPt[0], li.getIntersection(1), distanceTolerance))) {
                checkIntPoints(expectedIntPt[0], li.getIntersection(0), distanceTolerance);
                checkIntPoints(expectedIntPt[0], li.getIntersection(1), distanceTolerance);
            } else if (!(equals(expectedIntPt[1], li.getIntersection(0), distanceTolerance) || equals(expectedIntPt[1], li.getIntersection(1), distanceTolerance))) {
                checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
                checkIntPoints(expectedIntPt[1], li.getIntersection(1), distanceTolerance);
            }
        }
    }
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) Point(com.revolsys.geometry.model.Point)

Example 4 with LineIntersector

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

the class LineSegmentUtil method intersects.

public static boolean intersects(final Point line1p1, final Point line1p2, final Point line2p1, final Point line2p2) {
    final LineIntersector li = new RobustLineIntersector();
    li.computeIntersectionPoints(line1p1, line1p2, line2p1, line2p2);
    return li.hasIntersection();
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector)

Example 5 with LineIntersector

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

the class LineString method isOnLine.

default boolean isOnLine(final double x, final double y) {
    final LineIntersector lineIntersector = new RobustLineIntersector();
    double x1 = getX(0);
    double y1 = getY(0);
    final int vertexCount = getVertexCount();
    for (int i = 1; i < vertexCount; i++) {
        final double x2 = getX(i);
        final double y2 = getY(i);
        if (lineIntersector.computeIntersection(x, y, x1, y1, x2, y2)) {
            return true;
        } else {
            x1 = x2;
            y1 = y2;
        }
    }
    return false;
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector)

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