use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class QuadEdge method isSwapRequired.
public boolean isSwapRequired(final double x, final double y) {
final QuadEdge previousEdge = oPrev();
final Point previousToPoint = previousEdge.getToPoint();
final double previousToX = previousToPoint.getX();
final double previousToY = previousToPoint.getY();
final Point fromPoint = this.fromPoint;
final double fromX = fromPoint.getX();
final double fromY = fromPoint.getY();
final Point toPoint = getToPoint();
final double toX = toPoint.getX();
final double toY = toPoint.getY();
final double orientationIndex = (fromX - previousToX) * (toY - previousToY) - (fromY - previousToY) * (toX - previousToX);
if (orientationIndex < 0) {
// On right side
final double fromDeltaX = fromX - x;
final double fromDeltaY = fromY - y;
final double toDeltaX = toX - x;
final double toDeltaY = toY - y;
final double previousToDeltaX = previousToX - x;
final double previousToDeltaY = previousToY - y;
final double abdet = fromDeltaX * previousToDeltaY - previousToDeltaX * fromDeltaY;
final double bcdet = previousToDeltaX * toDeltaY - toDeltaX * previousToDeltaY;
final double cadet = toDeltaX * fromDeltaY - fromDeltaX * toDeltaY;
final double alift = fromDeltaX * fromDeltaX + fromDeltaY * fromDeltaY;
final double blift = previousToDeltaX * previousToDeltaX + previousToDeltaY * previousToDeltaY;
final double clift = toDeltaX * toDeltaX + toDeltaY * toDeltaY;
final double disc = alift * bcdet + blift * cadet + clift * abdet;
final boolean inCircle = disc > 0;
if (inCircle) {
return true;
}
}
return false;
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class Graph method moveToMidpoint.
public void moveToMidpoint(final Map<Point, Point> movedNodes, final Graph<T> graph1, final Node<T> node1, final Node<T> node2) {
final GeometryFactory precisionModel = graph1.getPrecisionModel();
final Point midPoint = LineSegmentUtil.midPoint(precisionModel, node1, node2);
if (!node1.equals(2, midPoint)) {
if (movedNodes != null) {
movedNodes.put(node1.newPoint2D(), midPoint);
}
node1.moveNode(midPoint);
}
if (!node2.equals(2, midPoint)) {
if (movedNodes != null) {
movedNodes.put(node2.newPoint2D(), midPoint);
}
node2.moveNode(midPoint);
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class Graph method getNode.
/**
* Get the node by point coordinates, creating one if it did not exist.
*
* @param point The point coordinates to get the node for.
* @return The node.
*/
public Node<T> getNode(final double x, final double y) {
final PointDoubleXY point = new PointDoubleXY(x, y);
Node<T> node = findNode(point);
if (node == null) {
final int nodeId = ++this.nextNodeId;
node = new Node<>(nodeId, this, x, y);
this.nodesIdsByPoint.put(point, nodeId);
this.nodesById.put(nodeId, node);
if (this.nodeIndex != null) {
this.nodeIndex.add(node);
}
this.nodeListeners.nodeEvent(node, null, null, NodeEvent.NODE_ADDED, null);
}
return node;
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class Graph method getEdges.
public List<Edge<T>> getEdges(final Point point, final double maxDistance) {
if (point == null) {
return Collections.emptyList();
} else {
BoundingBox boundingBox = point.getBoundingBox();
boundingBox = boundingBox.expand(maxDistance);
final double x = point.getX();
final double y = point.getY();
final Predicate<Edge<T>> filter = (edge) -> {
final LineString line = edge.getLineString();
final double distance = line.distance(x, y);
if (distance <= maxDistance) {
return true;
} else {
return false;
}
};
return BoundingBox.newArraySorted(this::forEachEdge, boundingBox, filter);
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class Graph method getEdge.
public Edge<T> getEdge(final T object, final LineString line) {
if (object != null) {
final Point fromPoint = line.getPoint(0);
final Node<T> fromNode = findNode(fromPoint);
if (fromNode != null) {
for (final Edge<T> edge : fromNode.getEdges()) {
if (edge.getObject() == object) {
return edge;
}
}
}
}
return null;
}
Aggregations