/** * If the point with specified (x,y) coordinates is nearer to the * specified node than the nearest node found so far, then replaces * the nearest node (and the node root) with the specified node. * Does nothing if the specified node is marked. * (Currently unused.) */ private void updateNodeNearest(double x, double y, Node n) { if (!isMarked(n)) { mark(n); double d = distanceSquared(n,x,y); if (d<_dmin) { _dmin = d; _nmin = n; _nroot = n; } } }
private void addNode(TriMesh.Node node) { if (_mesh.isMarked(node)) return; _mesh.mark(node); _nodeList.add(node); NodeData data = data(node); data.area = 0.0; } private boolean needTri(double xp, double yp, TriMesh.Tri tri) {
/** * Recursively finds the node nabor of the specified node that is * nearest to the specified point, beginning with the nabors in the * specified tri, which must reference the specified node. * Both tri and node marks must be cleared before calling this method. */ private void findNodeNaborNearest( double x, double y, Node node, Tri tri) { mark(tri); Node n0 = tri._n0; Node n1 = tri._n1; Node n2 = tri._n2; Tri t0 = tri._t0; Tri t1 = tri._t1; Tri t2 = tri._t2; if (node==n0) { findNodeNaborNearest(x,y,node,n1,n2,t1,t2); } else if (node==n1) { findNodeNaborNearest(x,y,node,n2,n0,t2,t0); } else if (node==n2) { findNodeNaborNearest(x,y,node,n0,n1,t0,t1); } else { assert false:"node is referenced by tri"; } } private void findNodeNaborNearest(
private void findNodeNaborNearest( double x, double y, Node node, Node na, Node nb, Tri ta, Tri tb) { if (!isMarked(na)) { mark(na); double da = distanceSquared(na,x,y); if (da<_dmin) { _dmin = da; _nmin = na; } } if (!isMarked(nb)) { mark(nb); double db = distanceSquared(nb,x,y); if (db<_dmin) { _dmin = db; _nmin = nb; } } if (ta!=null && !isMarked(ta)) findNodeNaborNearest(x,y,node,ta); if (tb!=null && !isMarked(tb)) findNodeNaborNearest(x,y,node,tb); }
mark(tri); Node n0 = tri._n0; Node n1 = tri._n1; if (node==n0) { if (!isMarked(n1)) { mark(n1); nabors.add(n1); mark(n2); nabors.add(n2); } else if (node==n1) { if (!isMarked(n2)) { mark(n2); nabors.add(n2); mark(n0); nabors.add(n0); } else if (node==n2) { if (!isMarked(n0)) { mark(n0); nabors.add(n0); mark(n1); nabors.add(n1);
/** * Recursively updates the node nearest to a point with specified (x,y) * coordinates inside the mesh, beginning with the nodes referenced by * the specified tri. Both node and tri marks must be cleared before * calling this method. The logic is much like that for adding a node. * (Currently unused.) */ private void findNodeNearestInside(double x, double y, Tri tri) { if (tri!=null && !isMarked(tri)) { mark(tri); Node n0 = tri._n0; Node n1 = tri._n1; Node n2 = tri._n2; updateNodeNearest(x,y,n0); updateNodeNearest(x,y,n1); updateNodeNearest(x,y,n2); if (inCircle(n0,n1,n2,x,y)) { Tri t0 = tri._t0; Tri t1 = tri._t1; Tri t2 = tri._t2; findNodeNearestInside(x,y,t0); findNodeNearestInside(x,y,t1); findNodeNearestInside(x,y,t2); } } }
mark(node);
mark(tri); killTri(tri); Node n0 = tri._n0;
/** * Beginning with a tri that contains a node located inside the * mesh, recursively adds Delaunay edges to the edge set. * The tri marks must be cleared before calling this method. */ private void getDelaunayEdgesInside(Node node, Tri tri) { if (tri!=null && !isMarked(tri)) { mark(tri); Node n0 = tri._n0; Node n1 = tri._n1; Node n2 = tri._n2; if (inCircle(n0,n1,n2,node)) { killTri(tri); Tri t0 = tri._t0; Tri t1 = tri._t1; Tri t2 = tri._t2; _edgeSet.addMate(tri,n0); _edgeSet.addMate(tri,n1); _edgeSet.addMate(tri,n2); getDelaunayEdgesInside(node,t0); getDelaunayEdgesInside(node,t1); getDelaunayEdgesInside(node,t2); } } }
/** * Beginning with any tri, searches for an edge on the hull. * Because this method recursively marks the tris, all tri marks must * be cleared before calling this method. */ private Edge getEdgeOnHull(Tri tri) { mark(tri); if (tri._t0==null) return new Edge(tri,tri._n0); if (tri._t1==null) return new Edge(tri,tri._n1); if (tri._t2==null) return new Edge(tri,tri._n2); if (!isMarked(tri._t0)) { Edge edge = getEdgeOnHull(tri._t0); if (edge!=null) return edge; } if (!isMarked(tri._t1)) { Edge edge = getEdgeOnHull(tri._t1); if (edge!=null) return edge; } if (!isMarked(tri._t2)) { Edge edge = getEdgeOnHull(tri._t2); if (edge!=null) return edge; } return null; }
private void addTri(double xp, double yp, TriMesh.Tri tri) { _mesh.mark(tri); _triList.add(tri); addNode(tri.nodeA()); addNode(tri.nodeB()); addNode(tri.nodeC()); TriMesh.Tri ta = tri.triA(); TriMesh.Tri tb = tri.triB(); TriMesh.Tri tc = tri.triC(); if (needTri(xp,yp,ta)) addTri(xp,yp,ta); if (needTri(xp,yp,tb)) addTri(xp,yp,tb); if (needTri(xp,yp,tc)) addTri(xp,yp,tc); } private void addNode(TriMesh.Node node) {
mark(tri); Node n0 = tri._n0; Node n1 = tri._n1;
mark(tri); nabors.add(tri); Node n0 = tri._n0;
mark(tri); Node n0 = tri._n0; Node n1 = tri._n1;
mark(tri); Node n0 = tri._n0; Node n1 = tri._n1;
mark(tri); Node n0 = tri._n0; Node n1 = tri._n1;