Esempio n. 1
0
 /**
  * Report neighbor opposite the given vertex of triangle.
  *
  * @param site a vertex of triangle
  * @param triangle we want the neighbor of this triangle
  * @return the neighbor opposite site in triangle; null if none
  * @throws IllegalArgumentException if site is not in this triangle
  */
 public Triangle neighborOpposite(Pnt site, Triangle triangle) {
   if (!triangle.contains(site))
     throw new IllegalArgumentException("Bad vertex; not in triangle");
   for (Triangle neighbor : triGraph.neighbors(triangle)) {
     if (!neighbor.contains(site)) return neighbor;
   }
   return null;
 }
Esempio n. 2
0
    /**
     * Place a new site into the DT. Nothing happens if the site matches an existing DT vertex.
     *
     * @param site the new Pnt
     * @throws IllegalArgumentException if site does not lie in any triangle
     */
    public void delaunayPlace(Pnt site) {
      // Uses straightforward scheme rather than best
      // asymptotic time

      // Locate containing triangle
      Triangle triangle = locate(site);
      // Give up if no containing triangle or if site is
      // already in DT
      if (triangle == null) throw new IllegalArgumentException("No containing triangle");
      if (triangle.contains(site)) return;

      // Determine the cavity and update the triangulation
      Set<Triangle> cavity = getCavity(site, triangle);

      lastCavity = cavity;

      mostRecent = update(site, cavity);
    }
Esempio n. 3
0
    /**
     * Report triangles surrounding site in order (cw or ccw).
     *
     * @param site we want the surrounding triangles for this site
     * @param triangle a "starting" triangle that has site as a vertex
     * @return all triangles surrounding site in order (cw or ccw)
     * @throws IllegalArgumentException if site is not in triangle
     */
    public List<Triangle> surroundingTriangles(Pnt site, Triangle triangle) {
      if (!triangle.contains(site)) throw new IllegalArgumentException("Site not in triangle");
      List<Triangle> list = new ArrayList<Triangle>();
      Triangle start = triangle;
      Pnt guide = triangle.getVertexButNot(site); // Affects
      // cw or
      // ccw
      while (true) {
        list.add(triangle);
        Triangle previous = triangle;

        ; // System.out.println(" site :" + site + " " + guide + " " + triangle);

        if (triangle == null) break;

        triangle = this.neighborOpposite(guide, triangle); // Next
        // triangle
        guide = previous.getVertexButNot(site, guide); // Update
        // guide
        if (triangle == start) break;
      }
      return list;
    }
Esempio n. 4
0
 /**
  * True iff triangles are neighbors. Two triangles are neighbors if they share a facet.
  *
  * @param triangle the other Triangle
  * @return true iff this Triangle is a neighbor of triangle
  */
 public boolean isNeighbor(Triangle triangle) {
   int count = 0;
   for (Pnt vertex : this) if (!triangle.contains(vertex)) count++;
   return count == 1;
 }