public Vertex getVertex(int i) { return edge[i].orig(); }
/** * Gets the index for the edge that starts at vertex v. * * @param v * the vertex to find the edge for * @return the index of the edge starting at the vertex * or -1 if the vertex is not in the triangle */ public int getEdgeIndex(Vertex v) { for (int i = 0; i < 3; i++) { if (edge[i].orig() == v) return i; } return -1; }
public Coordinate[] getCoordinates() { Coordinate[] pts = new Coordinate[4]; for (int i = 0; i < 3; i++) { pts[i] = edge[i].orig().getCoordinate(); } pts[3] = new Coordinate(pts[0]); return pts; }
/** * Gets the vertex for the edge's destination * * @return the destination vertex */ public final Vertex dest() { return sym().orig(); }
public Coordinate getCoordinate(int i) { return edge[i].orig().getCoordinate(); }
public static Geometry toPolygon(QuadEdge[] e) { Coordinate[] ringPts = new Coordinate[] { e[0].orig().getCoordinate(), e[1].orig().getCoordinate(), e[2].orig().getCoordinate(), e[0].orig().getCoordinate() }; GeometryFactory fact = new GeometryFactory(); LinearRing ring = fact.createLinearRing(ringPts); Polygon tri = fact.createPolygon(ring, null); return tri; }
/** * Tests whether the point pt is contained in the triangle defined by 3 * {@link QuadEdge}es. * * @param tri * an array containing at least 3 QuadEdges * @param pt * the point to test * @return true if the point is contained in the triangle */ public static boolean contains(QuadEdge[] tri, Coordinate pt) { Coordinate[] ring = new Coordinate[] { tri[0].orig().getCoordinate(), tri[1].orig().getCoordinate(), tri[2].orig().getCoordinate(), tri[0].orig().getCoordinate() }; return CGAlgorithms.isPointInRing(pt, ring); }
public final boolean rightOf(QuadEdge e) { return isCCW(e.dest(), e.orig()); }
public final boolean leftOf(QuadEdge e) { return isCCW(e.orig(), e.dest()); }
public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); // TODO: choose the most accurate circumcentre based on the edges Coordinate cc = Triangle.circumcentre(a, b, c); Vertex ccVertex = new Vertex(cc); // save the circumcentre as the origin for the dual edges originating in this triangle for (int i = 0; i < 3; i++) { triEdges[i].rot().setOrig(ccVertex); } } }
/** * Tests whether a QuadEdge is an edge incident on a frame triangle vertex. * * @param e * the edge to test * @return true if the edge is connected to the frame triangle */ public boolean isFrameEdge(QuadEdge e) { if (isFrameVertex(e.orig()) || isFrameVertex(e.dest())) return true; return false; }
/** * Tests whether a {@link Vertex} is the start or end vertex of a * {@link QuadEdge}, up to the subdivision tolerance distance. * * @param e * @param v * @return true if the vertex is a endpoint of the edge */ public boolean isVertexOfEdge(QuadEdge e, Vertex v) { if ((v.equals(e.orig(), tolerance)) || (v.equals(e.dest(), tolerance))) { return true; } return false; }
/** * Gets the length of the geometry of this quadedge. * * @return the length of the quadedge */ public double getLength() { return orig().getCoordinate().distance(dest().getCoordinate()); }
/** * Tests if this quadedge and another have the same line segment geometry * with the same orientation. * * @param qe a quadege * @return true if the quadedges are based on the same line segment */ public boolean equalsOriented(QuadEdge qe) { if (orig().getCoordinate().equals2D(qe.orig().getCoordinate()) && dest().getCoordinate().equals2D(qe.dest().getCoordinate())) return true; return false; }
public void visit(QuadEdge[] triEdges) { coordList.clear(); for (int i = 0; i < 3; i++) { Vertex v = triEdges[i].orig(); coordList.add(v.getCoordinate()); } if (coordList.size() > 0) { coordList.closeRing(); Coordinate[] pts = coordList.toCoordinateArray(); if (pts.length != 4) { //checkTriangleSize(pts); return; } triCoords.add(pts); } }
/** * Gets the primary edge of this quadedge and its <tt>sym</tt>. * The primary edge is the one for which the origin * and destination coordinates are ordered * according to the standard {@link Coordinate} ordering * * @return the primary quadedge */ public QuadEdge getPrimary() { if (orig().getCoordinate().compareTo(dest().getCoordinate()) <= 0) return this; else return sym(); }
/** * Tests whether a {@link Coordinate} lies on a {@link QuadEdge}, up to a * tolerance determined by the subdivision tolerance. * * @param e * a QuadEdge * @param p * a point * @return true if the vertex lies on the edge */ public boolean isOnEdge(QuadEdge e, Coordinate p) { seg.setCoordinates(e.orig().getCoordinate(), e.dest().getCoordinate()); double dist = seg.distance(p); // heuristic (hack?) return dist < edgeCoincidenceTolerance; }
/** * Creates a new QuadEdge connecting the destination of a to the origin of * b, in such a way that all three have the same left face after the * connection is complete. Additionally, the data pointers of the new edge * are set. * * @return the connected edge. */ public static QuadEdge connect(QuadEdge a, QuadEdge b) { QuadEdge e = makeEdge(a.dest(), b.orig()); splice(e, a.lNext()); splice(e.sym(), b); return e; }