Search in sources :

Example 16 with Point

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;
}
Also used : Point(com.revolsys.geometry.model.Point)

Example 17 with Point

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);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 18 with Point

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;
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 19 with Point

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);
    }
}
Also used : Arrays(java.util.Arrays) ComparatorProxy(com.revolsys.comparator.ComparatorProxy) IdObjectIndex(com.revolsys.geometry.index.IdObjectIndex) LineSegmentUtil(com.revolsys.geometry.model.coordinates.LineSegmentUtil) EdgeEvent(com.revolsys.geometry.graph.event.EdgeEvent) PreDestroy(javax.annotation.PreDestroy) GeometryFactoryProxy(com.revolsys.geometry.model.GeometryFactoryProxy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PredicateProxy(com.revolsys.predicate.PredicateProxy) Method(java.lang.reflect.Method) PointComparators(com.revolsys.geometry.model.coordinates.comparator.PointComparators) NodeProperties(com.revolsys.geometry.graph.attribute.NodeProperties) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) IntHashMap(com.revolsys.collection.map.IntHashMap) EdgeEventListenerList(com.revolsys.geometry.graph.event.EdgeEventListenerList) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) List(java.util.List) NodeEventListener(com.revolsys.geometry.graph.event.NodeEventListener) Entry(java.util.Map.Entry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ExitLoopException(com.revolsys.util.ExitLoopException) Point(com.revolsys.geometry.model.Point) EdgeEventListener(com.revolsys.geometry.graph.event.EdgeEventListener) NodeWithinBoundingBoxVisitor(com.revolsys.geometry.graph.visitor.NodeWithinBoundingBoxVisitor) LineString(com.revolsys.geometry.model.LineString) HashMap(java.util.HashMap) CreateListVisitor(com.revolsys.visitor.CreateListVisitor) Record(com.revolsys.record.Record) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BPlusTreeMap(com.revolsys.collection.bplus.BPlusTreeMap) CoordinatesDistanceComparator(com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator) MapEx(com.revolsys.collection.map.MapEx) SerializablePageValueManager(com.revolsys.io.page.SerializablePageValueManager) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) PageValueManager(com.revolsys.io.page.PageValueManager) IsPointOnLineEdgeFilter(com.revolsys.geometry.graph.filter.IsPointOnLineEdgeFilter) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble) NodeEvent(com.revolsys.geometry.graph.event.NodeEvent) Consumer(java.util.function.Consumer) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) TreeMap(java.util.TreeMap) BoundingBoxProxy(com.revolsys.geometry.model.BoundingBoxProxy) Predicates(com.revolsys.predicate.Predicates) NodeDistanceComparator(com.revolsys.geometry.graph.comparator.NodeDistanceComparator) Comparator(java.util.Comparator) NodeEventListenerList(com.revolsys.geometry.graph.event.NodeEventListenerList) Geometry(com.revolsys.geometry.model.Geometry) BaseObjectWithProperties(com.revolsys.properties.BaseObjectWithProperties) Collections(java.util.Collections) BoundingBox(com.revolsys.geometry.model.BoundingBox) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 20 with Point

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;
}
Also used : Point(com.revolsys.geometry.model.Point)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14