예제 #1
0
        public static Polygon GetBigSample()
        {
            Polygon p = new Polygon();

            p.AddVertex(new Point(0, 0));
            p.AddVertex(new Point(150, 0));
            p.AddVertex(new Point(350, 150));
            p.AddVertex(new Point(570, 440));
            p.AddVertex(new Point(550, 620));
            p.AddVertex(new Point(450, 540));
            p.AddVertex(new Point(370, 490));
            p.AddVertex(new Point(100, 200));
            p.AddVertex(new Point(0, 0));
            p.Move(new Point(150, 50));

            var edges     = p.GetEdges();
            var relations = new List <RelationInfo> {
                new RelationInfo(edges[0], edges[3], EdgeRelation.EqualLength),
                new RelationInfo(edges[2], edges[4], EdgeRelation.Perpendicular),
                new RelationInfo(edges[5], edges[7], EdgeRelation.EqualLength)
            };

            foreach (var relation in relations)
            {
                p.AddRelation(relation);
            }

            return(p);
        }
예제 #2
0
        private Polygon Clone()
        {
            var polygon     = new Polygon();
            var newVertices = polygon.GetVertices();
            var newEdges    = polygon.GetEdges();

            foreach (var vertex in vertices)
            {
                newVertices.Add(new Vertex(vertex.Position, vertex.Radius, polygon));
            }

            for (int i = 0; i < newVertices.Count; i++)
            {
                newEdges.Add(new Edge(newVertices[i], newVertices[(i + 1) % newVertices.Count], polygon));
            }

            for (int i = 0; i < edges.Count; i++)
            {
                if (edges[i].RelationType == EdgeRelation.None)
                {
                    continue;
                }

                var newEdge = newEdges[i];
                newEdge.RelationType = edges[i].RelationType;

                var pairIndex = edges.IndexOf(edges[i].RelationEdge);
                newEdge.RelationEdge = newEdges[pairIndex];
            }

            return(polygon);
        }
예제 #3
0
        public static Polygon GetSampleSquare()
        {
            Polygon p = new Polygon();

            p.AddVertex(new Point(0, 0));
            p.AddVertex(new Point(0, 150));
            p.AddVertex(new Point(150, 150));
            p.AddVertex(new Point(150, 0));
            p.AddVertex(new Point(0, 0));

            var edges = p.GetEdges();
            var r1    = new RelationInfo(edges[0], edges[1], EdgeRelation.EqualLength);

            p.AddRelation(r1);

            return(p);
        }
예제 #4
0
        public static bool CorrectRelation(Polygon clonedPolygon, Vertex startingVertex)
        {
            var edges = clonedPolygon.GetEdges();
            var i     = GetStartingEdgeIndex(edges, startingVertex);

            //forward iteration
            for (int j = 0; j < edges.Count; j++)
            {
                if (CheckRelationForEdge(edges[i]))
                {
                    break;
                }
                else
                if (!CorrectRelationForEdge(edges[i]))
                {
                    return(false);
                }

                i = (i + 1) % edges.Count;
            }

            //backward iteration
            SwapEdges(edges);
            i = GetStartingEdgeIndex(edges, startingVertex);
            for (int j = 0; j < edges.Count; j++)
            {
                if (CheckRelationForEdge(edges[i]))
                {
                    break;
                }
                else
                if (!CorrectRelationForEdge(edges[i]))
                {
                    return(false);
                }

                i = (i - 1 + edges.Count) % edges.Count;
            }

            SwapEdges(edges);
            return(true);
        }