/**
		 * Locate the triangle with point (a Pnt) inside (or on) it.
		 * @param point the Pnt to locate
		 * @return triangle (Simplex<Pnt>) that holds the point; null if no such triangle
		 */
		public Simplex locate(Pnt point) {
        Simplex triangle = mostRecent;
        if (!this.contains(triangle)) triangle = null;
        
        // Try a directed walk (this works fine in 2D, but can fail in 3D)
        Set visited = new HashSet();
        while (triangle != null) {
            if (visited.contains(triangle)) { // This should never happen
                Console.WriteLine("Warning: Caught in a locate loop");
                break;
            }
            visited.add(triangle);
            // Corner opposite point
            Pnt corner = point.isOutside((Pnt[]) triangle.toArray(new Pnt[0]));
            if (corner == null) return triangle;
            triangle = this.neighborOpposite(corner, triangle);
        }
        // No luck; try brute force
        Console.WriteLine("Warning: Checking all triangles for " + point);
        for (Iterator it = this.iterator(); it.hasNext();) {
            Simplex tri = (Simplex) it.next();
            if (point.isOutside((Pnt[]) tri.toArray(new Pnt[0])) == null) return tri;
        }
        // No such triangle
		Console.WriteLine("Warning: No triangle holds " + point);
        return null;
    }
Example #2
0
        /**
         * Locate the triangle with point (a Pnt) inside (or on) it.
         * @param point the Pnt to locate
         * @return triangle (Simplex<Pnt>) that holds the point; null if no such triangle
         */
        public Simplex locate(Pnt point)
        {
            Simplex triangle = mostRecent;

            if (!this.contains(triangle))
            {
                triangle = null;
            }

            // Try a directed walk (this works fine in 2D, but can fail in 3D)
            Set visited = new HashSet();

            while (triangle != null)
            {
                if (visited.contains(triangle)) // This should never happen
                {
                    Console.WriteLine("Warning: Caught in a locate loop");
                    break;
                }
                visited.add(triangle);
                // Corner opposite point
                Pnt corner = point.isOutside((Pnt[])triangle.toArray(new Pnt[0]));
                if (corner == null)
                {
                    return(triangle);
                }
                triangle = this.neighborOpposite(corner, triangle);
            }
            // No luck; try brute force
            Console.WriteLine("Warning: Checking all triangles for " + point);
            for (Iterator it = this.iterator(); it.hasNext();)
            {
                Simplex tri = (Simplex)it.next();
                if (point.isOutside((Pnt[])tri.toArray(new Pnt[0])) == null)
                {
                    return(tri);
                }
            }
            // No such triangle
            Console.WriteLine("Warning: No triangle holds " + point);
            return(null);
        }