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);
}
}
}
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());
}
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);
}
}
}
}
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();
}
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);
}
Aggregations