Esempio n. 1
0
        public void AbsorbPolygon(int q, CompositionPolygon minor, int pMinor)
        {
            // Insert Minor points Minor[P+1] ... Minor[Q-1] into Major, inserted at Major[Q]
            // Same as inserting numPoints-2 starting at index qMinor+1
            int numMinorPoints = minor.Points.Count - 2;

            List <PointF> pointsToInsert = new List <PointF>();

            for (int i = 0; i < numMinorPoints; ++i)
            {
                int qInsert = (pMinor + 1 + i) % minor.Points.Count;
                pointsToInsert.Add(minor.Points[qInsert]);
            }

            this.Points.InsertRange(q, pointsToInsert);

            // Absorb the edges from our minor polygon too so that future absoptions carry through
            foreach (var minorEdge in minor.Edges)
            {
                if (!this.Edges.Contains(minorEdge))
                {
                    this.Edges.Add(minorEdge);
                }
            }
        }
Esempio n. 2
0
        public void AssignMinorPartner(CompositionPolygon polygon)
        {
            Debug.Assert(this.MinorPartner == null);
            Debug.Assert(this.MajorPartner != null);

            ReplaceMinor(polygon);
        }
Esempio n. 3
0
        public void Initialize(List <PointF[]> polygons)
        {
            this.PolygonEdges = new List <PolygonEdge>();

            foreach (var polygon in polygons)
            {
                // Our polygon will be added to each edge
                CompositionPolygon compPolygon = new CompositionPolygon(polygon);

                // Process all edges of the polygon
                for (int p = polygon.Length - 1, q = 0; q < polygon.Length; p = q++)
                {
                    PointF P = polygon[p];
                    PointF Q = polygon[q];

                    // The clockwise edge may already exist if it was added by an earlier polygon as the counter-clockwise edge
                    // If so, add this polygon as the CW partner of that edge
                    PolygonEdge edge = this.PolygonEdges.FirstOrDefault(e => e.P == Q && e.Q == P);
                    if (edge != null)
                    {
                        // Add ourselves as the Minor/CW partner
                        edge.AssignMinorPartner(compPolygon);
                        compPolygon.AddEdge(edge);
                    }
                    else
                    {
                        // If this edge is new to the collection then add it with this polygon being the CCW partner
                        PolygonEdge newEdge = new PolygonEdge(compPolygon, p);
                        compPolygon.AddEdge(newEdge);
                        this.PolygonEdges.Add(newEdge);
                    }
                }
            }
        }
Esempio n. 4
0
 public void UpdateIndices(CompositionPolygon polygon)
 {
     if (polygon == this.MajorPartner)
     {
         this.MajorPartner_pIndex = polygon.Points.IndexOf(this.P);
         this.MajorPartner_qIndex = polygon.Points.IndexOf(this.Q);
     }
     else if (polygon == MinorPartner)
     {
         this.MinorPartner_pIndex = polygon.Points.IndexOf(this.P);
         this.MinorPartner_qIndex = polygon.Points.IndexOf(this.Q);
     }
 }
Esempio n. 5
0
 public void UpdateIndices(CompositionPolygon polygon)
 {
     if (polygon == MajorPartner)
     {
         MajorPartner_pIndex = polygon.Points.IndexOf(P);
         MajorPartner_qIndex = polygon.Points.IndexOf(Q);
     }
     else if (polygon == MinorPartner)
     {
         MinorPartner_pIndex = polygon.Points.IndexOf(P);
         MinorPartner_qIndex = polygon.Points.IndexOf(Q);
     }
 }
Esempio n. 6
0
        public void AbsorbPolygon(int q, CompositionPolygon minor, int pMinor)
        {
            // Insert Minor points Minor[P+1] ... Minor[Q-1] into Major, inserted at Major[Q]
            // Same as inserting numPoints-2 starting at index qMinor+1
            int numMinorPoints = minor.Points.Count - 2;

            List <PointF> pointsToInsert = new List <PointF>();

            for (int i = 0; i < numMinorPoints; ++i)
            {
                int qInsert = (pMinor + 1 + i) % minor.Points.Count;
                pointsToInsert.Add(minor.Points[qInsert]);
            }

            this.Points.InsertRange(q, pointsToInsert);
        }
Esempio n. 7
0
 public void ReplaceEdgesWithPolygon(CompositionPolygon replacement, PolygonEdge ignoreEdge)
 {
     foreach (PolygonEdge edge in Edges)
     {
         if (edge != ignoreEdge)
         {
             if (edge.MajorPartner == this)
             {
                 edge.ReplaceMajor(replacement);
             }
             else if (edge.MinorPartner == this)
             {
                 edge.ReplaceMinor(replacement);
             }
         }
     }
 }
Esempio n. 8
0
        public PolygonEdge(CompositionPolygon compPolygon, int p)
        {
            HasBeenMerged = false;
            int num = (p + 1) % compPolygon.Points.Count;

            P                   = compPolygon.Points[p];
            Q                   = compPolygon.Points[num];
            MajorPartner        = compPolygon;
            MajorPartner_pIndex = p;
            MajorPartner_qIndex = num;
            float num2 = P.X - Q.X;
            float num3 = P.Y - Q.Y;
            float num4 = num2;
            float num5 = num4 * num4;
            float num6 = num3;

            Length2 = num5 + num6 * num6;
        }
Esempio n. 9
0
        public void AbsorbPolygon(int q, CompositionPolygon minor, int pMinor)
        {
            int           num  = minor.Points.Count - 2;
            List <PointF> list = new List <PointF>();

            for (int i = 0; i < num; i++)
            {
                int index = (pMinor + 1 + i) % minor.Points.Count;
                list.Add(minor.Points[index]);
            }
            Points.InsertRange(q, list);
            foreach (PolygonEdge edge in minor.Edges)
            {
                if (!Edges.Contains(edge))
                {
                    Edges.Add(edge);
                }
            }
        }
Esempio n. 10
0
        public void ReplaceEdgesWithPolygon(CompositionPolygon replacement, PolygonEdge ignoreEdge)
        {
            // This polygon is going away as it was merged with another
            // All edges this polygon referenced will need to reference the replacement instead
            foreach (var edge in this.Edges)
            {
                if (edge == ignoreEdge)
                {
                    continue;
                }

                Debug.Assert(!(edge.MajorPartner == this && edge.MinorPartner == this));

                if (edge.MajorPartner == this)
                {
                    edge.ReplaceMajor(replacement);
                }
                else if (edge.MinorPartner == this)
                {
                    edge.ReplaceMinor(replacement);
                }
            }
        }
Esempio n. 11
0
        public PolygonEdge(CompositionPolygon compPolygon, int p)
        {
            Debug.Assert(compPolygon.Points.Count >= 3);

            this.HasBeenMerged = false;

            // P and Q make up our edge
            int q = (p + 1) % compPolygon.Points.Count;

            this.P = compPolygon.Points[p];
            this.Q = compPolygon.Points[q];

            // Create a compositional polygon with our edge
            this.MajorPartner        = compPolygon;
            this.MajorPartner_pIndex = p;
            this.MajorPartner_qIndex = q;

            // Calculate the squared length
            float x = (this.P.X - this.Q.X);
            float y = (this.P.Y - this.Q.Y);

            this.Length2 = (x * x) + (y * y);
        }
Esempio n. 12
0
        public void Initialize(List <PointF[]> polygons)
        {
            PolygonEdges = new List <PolygonEdge>();
            int num = 0;

            foreach (PointF[] polygon in polygons)
            {
                CompositionPolygon compositionPolygon = new CompositionPolygon(polygon, num++);
                int num3 = polygon.Length - 1;
                int num4 = 0;
                while (num4 < polygon.Length)
                {
                    PointF      P           = polygon[num3];
                    PointF      Q           = polygon[num4];
                    PolygonEdge polygonEdge = PolygonEdges.FirstOrDefault(delegate(PolygonEdge e)
                    {
                        if (e.P == Q)
                        {
                            return(e.Q == P);
                        }
                        return(false);
                    });
                    if (polygonEdge != null)
                    {
                        polygonEdge.AssignMinorPartner(compositionPolygon);
                        compositionPolygon.AddEdge(polygonEdge);
                    }
                    else
                    {
                        PolygonEdge polygonEdge2 = new PolygonEdge(compositionPolygon, num3);
                        compositionPolygon.AddEdge(polygonEdge2);
                        PolygonEdges.Add(polygonEdge2);
                    }
                    num3 = num4++;
                }
            }
        }
Esempio n. 13
0
 public void ReplaceMinor(CompositionPolygon polygon)
 {
     this.MinorPartner        = polygon;
     this.MinorPartner_pIndex = this.MinorPartner.Points.IndexOf(this.P);
     this.MinorPartner_qIndex = this.MinorPartner.Points.IndexOf(this.Q);
 }
Esempio n. 14
0
 public void ReplaceMinor(CompositionPolygon polygon)
 {
     MinorPartner        = polygon;
     MinorPartner_pIndex = MinorPartner.Points.IndexOf(P);
     MinorPartner_qIndex = MinorPartner.Points.IndexOf(Q);
 }
Esempio n. 15
0
 public void AssignMinorPartner(CompositionPolygon polygon)
 {
     ReplaceMinor(polygon);
 }