Example #1
0
        private void update_vertices(Point p)                 // called after finding a ear from a vertice
        {                                                     // removes the vertice from updates_vertices list
            ArrayList temp_points = new ArrayList();          // temp. location while updating the list

            for (int i = 0; i < updated_vertices.Length; i++) // loop through the list
            {
                if (p == updated_vertices[i])                 // if we found the vertice we'r lookig for
                {
                    mPolygon poly       = new mPolygon(updated_vertices);
                    Point    curr_point = p;
                    Point    next_point = poly.get_next_point(p); // find the vertices next neighboor
                    Point    prev_point = poly.get_prev_point(p); // find the vertices previous neighboor

                    Point[] ear = new Point[3];                   // create a 3 point triangle-polygon from these 3 points
                    ear[0] = prev_point;                          // previos vertice
                    ear[1] = curr_point;                          // current vertice
                    ear[2] = next_point;                          // next vertice

                    ears.Add(ear);                                // add this ear to ears list
                }
                else                                              // this is not the vertice we'r looking for
                {
                    temp_points.Add(updated_vertices[i]);         // so add it to temp. vertice list
                }
            }

            if ((updated_vertices.Length - temp_points.Count) == 1)        // we removed 1 vertice from the list, check the counts
            {
                updated_vertices = new Point[updated_vertices.Length - 1]; // redimension the list to -1 size, cause we removed 1 vertice
                for (int i = 0; i < temp_points.Count; i++)
                {
                    updated_vertices[i] = (Point)temp_points[i];    // update the newest updated_vertices from temp location
                }
            }
        }
Example #2
0
        private Boolean is_ear(Point p)                         // checks if given vertice is in a ear
        {
            mPolygon m = new mPolygon(updated_vertices);        // init. a polygon from the current vertices

            if (m.is_vertex(p) == true)                         // if given point is a vertex
            {
                if (m.vertex_type(p) == VertexType.ConvexPoint) // and it's a convex point
                {
                    Point curr_point = p;
                    Point prev_point = m.get_prev_point(p);                                                     // find previous adjacent point
                    Point next_point = m.get_next_point(p);                                                     // find next adjacent point

                    for (int i = updated_vertices.GetLowerBound(0); i < updated_vertices.GetUpperBound(0); i++) // loop through all other vertices
                    {
                        Point pt = updated_vertices[i];
                        if (!(is_points_equal(pt, curr_point) || is_points_equal(pt, prev_point) || is_points_equal(pt, next_point)))
                        {                                                                                     // if pt is not equal to checked vertice or its's next and prev adjacent vertices
                            if (is_point_in_triangle(new Point[] { prev_point, curr_point, next_point }, pt)) // check pt lies in triangle
                            {
                                return(false);                                                                // if another vertice lies in this triangle, then this is not an ear
                            }
                        }
                    }
                }
                else // concave
                {
                    return(false); // we cannot make ears from concave points
                }
                return(true); // if CS:IP reaches here, this means vertice passed the test and is an ear
            }
            return(false);    // if the given vertex is not an vertex, it's not related to an ear also!
        }