use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class NonEncroachingSplitPointFinder method projectedSplitPoint.
/**
* Computes a split point which is the projection of the encroaching point on the segment
*
* @param seg
* @param encroachPt
* @return a split point on the segment
*/
public static Point projectedSplitPoint(final LineSegmentDoubleData seg, final Point encroachPt) {
final LineSegment lineSeg = seg;
final Point projPt = lineSeg.project(encroachPt);
return projPt;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class GeometryGraph method addEdges.
private void addEdges(final LineString points, final Map<String, Object> attributes) {
this.startPoints.add(points.getPoint(0).newPoint2D());
int index = 0;
for (LineSegment lineSegment : points.segments()) {
lineSegment = (LineSegment) lineSegment.clone();
final double fromX = lineSegment.getX(0);
final double fromY = lineSegment.getY(0);
final double toX = lineSegment.getX(1);
final double toY = lineSegment.getY(1);
final Edge<LineSegment> edge = addEdge(lineSegment, fromX, fromY, toX, toY);
attributes.put("segmentIndex", index++);
edge.setProperties(attributes);
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method setLineString.
private void setLineString(final LineString lineString) {
this.points = lineString;
int index = 0;
for (final LineSegment lineSegment : lineString.segments()) {
final double fromX = lineSegment.getX(0);
final double fromY = lineSegment.getY(0);
final double toX = lineSegment.getX(1);
final double toY = lineSegment.getY(1);
final Edge<LineSegment> edge = addEdge((LineSegment) lineSegment.clone(), fromX, fromY, toX, toY);
edge.setProperty(INDEX, Arrays.asList(index++));
}
this.fromPoint = lineString.getPoint(0).newPoint2D();
this.envelope = lineString.getBoundingBox();
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method splitEdge.
@Override
public <V extends Point> List<Edge<LineSegment>> splitEdge(final Edge<LineSegment> edge, final Collection<V> nodes) {
final List<Edge<LineSegment>> newEdges = new ArrayList<>();
if (!edge.isRemoved()) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
final CoordinatesDistanceComparator comparator = new CoordinatesDistanceComparator(fromNode.getX(), toNode.getY());
final Set<Point> newPoints = new TreeSet<>(comparator);
for (final Point point : nodes) {
newPoints.add(point);
}
newPoints.add(toNode);
final List<Integer> index = edge.getProperty(INDEX);
int i = 0;
Point previousPoint = fromNode;
for (final Point point : newPoints) {
final LineSegment lineSegment = new LineSegmentDoubleGF(previousPoint, point);
final Edge<LineSegment> newEdge = addEdge(lineSegment, previousPoint, point);
final List<Integer> newIndecies = new ArrayList<>(index);
newIndecies.add(i++);
newEdge.setProperty(INDEX, newIndecies);
newEdges.add(newEdge);
previousPoint = point;
}
remove(edge);
}
return newEdges;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method getLines.
public List<LineString> getLines() {
removeDuplicateEdges();
final EdgeAttributeValueComparator<LineSegment> comparator = new EdgeAttributeValueComparator<>("INDEX");
final List<LineString> lines = new ArrayList<>();
final List<Point> points = new ArrayList<>();
final Consumer<Edge<LineSegment>> action = new Consumer<Edge<LineSegment>>() {
private Node<LineSegment> previousNode = null;
@Override
public void accept(final Edge<LineSegment> edge) {
final LineSegment lineSegment = edge.getObject();
if (lineSegment.getLength() > 0) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
if (this.previousNode == null) {
points.add(lineSegment.getPoint(0));
points.add(lineSegment.getPoint(1));
} else if (fromNode == this.previousNode) {
if (edge.getLength() > 0) {
points.add(toNode);
}
} else {
if (points.size() > 1) {
final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
lines.add(line);
}
points.clear();
;
points.add(lineSegment.getPoint(0));
points.add(lineSegment.getPoint(1));
}
if (points.size() > 1) {
final int toDegree = toNode.getDegree();
if (toDegree != 2) {
final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
lines.add(line);
points.clear();
;
points.add(toNode);
}
}
this.previousNode = toNode;
}
}
};
forEachEdge(comparator, action);
if (points.size() > 1) {
final LineString line = this.geometryFactory.lineString(points);
lines.add(line);
}
return lines;
}
Aggregations