use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class PlanarPolygon3D method intersects.
public boolean intersects(final Point pt, final LineString ring) {
final LineString seq = ring;
final LineString seqProj = project(seq, this.facingPlane);
final Point ptProj = project(pt, this.facingPlane);
return Location.EXTERIOR != RayCrossingCounter.locatePointInRing(ptProj, seqProj);
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class Distance3DOp method computeMinDistancePolygonPoint.
private void computeMinDistancePolygonPoint(final PlanarPolygon3D polyPlane, final Point point, final boolean flip) {
final Point pt = point.getPoint();
final LineString shell = polyPlane.getPolygon().getShell();
if (polyPlane.intersects(pt, shell)) {
// point is either inside or in a hole
final int nHole = polyPlane.getPolygon().getHoleCount();
for (int i = 0; i < nHole; i++) {
final LineString hole = polyPlane.getPolygon().getHole(i);
if (polyPlane.intersects(pt, hole)) {
computeMinDistanceLinePoint(hole, point, flip);
return;
}
}
// point is in interior of polygon
// distance is distance to polygon plane
final double dist = Math.abs(polyPlane.getPlane().orientedDistance(pt));
updateDistance(dist, new GeometryLocation(polyPlane.getPolygon(), 0, pt), new GeometryLocation(point, 0, pt), flip);
}
// point is outside polygon, so compute distance to shell linework
computeMinDistanceLinePoint(shell, point, flip);
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class Distance3DOp method intersection.
private Point intersection(final PlanarPolygon3D poly, final LineString line) {
final LineString seq = line;
if (seq.getVertexCount() == 0) {
return null;
}
// start point of line
Point p0 = seq.getPoint(0);
double d0 = poly.getPlane().orientedDistance(p0);
// for each segment in the line
for (int i = 0; i < seq.getVertexCount() - 1; i++) {
p0 = seq.getPoint(i);
final Point p1 = seq.getPoint(i + 1);
final double d1 = poly.getPlane().orientedDistance(p1);
/**
* If the oriented distances of the segment endpoints have the same sign,
* the segment does not cross the plane, and is skipped.
*/
if (d0 * d1 > 0) {
continue;
}
/**
* Compute segment-plane intersection point
* which is then used for a point-in-polygon test.
* The endpoint distances to the plane d0 and d1
* give the proportional distance of the intersection point
* along the segment.
*/
final Point intPt = segmentPoint(p0, p1, d0, d1);
// Point intPt = polyPlane.intersection(p0, p1, s0, s1);
if (poly.intersects(intPt)) {
return intPt;
}
// shift to next segment
d0 = d1;
}
return null;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineMergeGraph method addEdge.
/**
* Adds an Edge, DirectedEdges, and Nodes for the given LineString representation
* of an edge.
* Empty lines or lines with all coordinates equal are not added.
*
* @param line the linestring to add to the graph
*/
public void addEdge(final LineString line) {
if (line.isEmpty()) {
return;
}
final LineString points = line.removeDuplicatePoints();
final int vertexCount = points.getVertexCount();
if (vertexCount > 1) {
final Point fromPoint = points.getPoint(0);
final Point toPoint = points.getPoint(vertexCount - 1);
final Node startNode = getNode(fromPoint);
final Node endNode = getNode(toPoint);
final DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode, points.getPoint(1).newPoint(), true);
final DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode, points.getPoint(vertexCount - 2).newPoint(), false);
final Edge edge = new LineMergeEdge(line);
edge.setDirectedEdges(directedEdge0, directedEdge1);
add(edge);
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineSequencer method isSequenced.
/**
* Tests whether a {@link Geometry} is sequenced correctly.
* {@link LineString}s are trivially sequenced.
* {@link Lineal}s are checked for correct sequencing.
* Otherwise, <code>isSequenced</code> is defined
* to be <code>true</code> for geometries that are not lineal.
*
* @param geom the geometry to test
* @return <code>true</code> if the geometry is sequenced or is not lineal
*/
public static boolean isSequenced(final Geometry geom) {
if (!(geom instanceof Lineal) || geom instanceof LineString) {
return true;
}
final Lineal lineal = (Lineal) geom;
// the nodes in all subgraphs which have been completely scanned
final Set prevSubgraphNodes = new TreeSet();
Point lastNode = null;
final List currNodes = new ArrayList();
for (int i = 0; i < lineal.getGeometryCount(); i++) {
final LineString line = (LineString) lineal.getGeometry(i);
final Point startNode = line.getPoint(0);
final Point endNode = line.getPoint(line.getVertexCount() - 1);
/**
* If this linestring is connected to a previous subgraph, geom is not sequenced
*/
if (prevSubgraphNodes.contains(startNode)) {
return false;
}
if (prevSubgraphNodes.contains(endNode)) {
return false;
}
if (lastNode != null) {
if (!startNode.equals(lastNode)) {
// start new connected sequence
prevSubgraphNodes.addAll(currNodes);
currNodes.clear();
}
}
currNodes.add(startNode);
currNodes.add(endNode);
lastNode = endNode;
}
return true;
}
Aggregations