Search in sources :

Example 1 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector 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 2 with RobustLineIntersector

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

the class RobustLineIntersectorTest method testCollinear1.

public void testCollinear1() {
    final RobustLineIntersector i = new RobustLineIntersector();
    final Point p1 = new PointDoubleXY(10, 10);
    final Point p2 = new PointDoubleXY(20, 10);
    final Point q1 = new PointDoubleXY(22, 10);
    final Point q2 = new PointDoubleXY(30, 10);
    i.computeIntersectionPoints(p1, p2, q1, q2);
    assertEquals(LineIntersector.NO_INTERSECTION, i.getIntersectionCount());
    assertTrue(!i.isProper());
    assertTrue(!i.hasIntersection());
}
Also used : RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 3 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector 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 RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector 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 RobustLineIntersector

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

the class CGAlgorithmFunctions method segmentIntersectionDD.

public static Geometry segmentIntersectionDD(final Geometry g1, final Geometry g2) {
    final Point[] pt1 = CoordinatesListUtil.getPointArray(g1);
    final Point[] pt2 = CoordinatesListUtil.getPointArray(g2);
    // first check if there actually is an intersection
    final RobustLineIntersector ri = new RobustLineIntersector();
    ri.computeIntersectionPoints(pt1[0], pt1[1], pt2[0], pt2[1]);
    if (!ri.hasIntersection()) {
        // no intersection => return empty point
        return g1.getGeometryFactory().point();
    }
    final Point intPt = CGAlgorithmsDD.intersection(pt1[0], pt1[1], pt2[0], pt2[1]);
    return g1.getGeometryFactory().point(intPt);
}
Also used : Point(com.revolsys.geometry.model.Point) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector)

Aggregations

RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)17 Point (com.revolsys.geometry.model.Point)10 LineIntersector (com.revolsys.geometry.algorithm.LineIntersector)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)5 IntersectionAdder (com.revolsys.geometry.noding.IntersectionAdder)3 MCIndexNoder (com.revolsys.geometry.noding.MCIndexNoder)3 Noder (com.revolsys.geometry.noding.Noder)2 ScaledNoder (com.revolsys.geometry.noding.ScaledNoder)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 NonRobustLineIntersector (com.revolsys.geometry.algorithm.NonRobustLineIntersector)1 GeometryGraph (com.revolsys.geometry.geomgraph.GeometryGraph)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 LineString (com.revolsys.geometry.model.LineString)1