예제 #1
0
        internal gPolygon AddVertex(gVertex v, gEdge intersectingEdge)
        {
            //Assumes that vertex v intersects one of polygons edges.
            gPolygon newPolygon = (gPolygon)this.Clone();

            // Assign the polygon Id to the new vertex.
            v.polygonId = this.id;

            // Getting the index of the intersecting edge's start vertex and
            // inserting the new vertex at the following index.
            int index = newPolygon.vertices.IndexOf(intersectingEdge.StartVertex);

            newPolygon.vertices.Insert(index + 1, v);

            // Rebuilding edges.
            newPolygon.edges.Clear();
            int verticesCount = newPolygon.vertices.Count;

            for (var i = 0; i < verticesCount; i++)
            {
                int nextIndex = (i + 1) % verticesCount;
                newPolygon.edges.Add(new gEdge(newPolygon.vertices[i], newPolygon.vertices[nextIndex]));
            }

            return(newPolygon);
        }
예제 #2
0
        public object Clone()
        {
            gPolygon newPolygon = new gPolygon(this.id, this.isBoundary);

            newPolygon.edges    = new List <gEdge>(this.edges);
            newPolygon.vertices = new List <gVertex>(this.vertices);
            return(newPolygon);
        }
예제 #3
0
        public static gPolygon ByVertices(List <gVertex> vertices, bool isExternal)
        {
            gPolygon polygon = new gPolygon(-1, isExternal);

            polygon.vertices = vertices;
            int vertexCount = vertices.Count;

            for (var j = 0; j < vertexCount; j++)
            {
                int     next_index  = (j + 1) % vertexCount;
                gVertex vertex      = vertices[j];
                gVertex next_vertex = vertices[next_index];
                polygon.edges.Add(new gEdge(vertex, next_vertex));
            }
            return(polygon);
        }