Beispiel #1
0
        public bool CanMergePolygons()
        {
            // The two polygon partners can be merged if the two vectors on each point where they would merge don't create a concave polygon
            // Concave testing is done through a cross product and assumes CCW winding of the polyon points

            // Can merge point P of the Major/CCW partner?
            {
                // A = CWW[P - 1]
                // B = CWW[P]
                // C = CW[P + 1]
                var   A     = this.MajorPartner.PrevPoint(this.MajorPartner_pIndex);
                var   B     = this.MajorPartner.Points[this.MajorPartner_pIndex];
                var   C     = this.MinorPartner.NextPoint(this.MinorPartner_pIndex);
                float cross = GeoMath.Cross(A, B, C);
                if (cross > 0)
                {
                    return(false);
                }
            }

            // Can merge point Q of Major/CCW partner?
            {
                // A = CWW[Q + 1]
                // B = CWW[Q]
                // C = CW[Q-1]
                var   A     = this.MajorPartner.NextPoint(this.MajorPartner_qIndex);
                var   B     = this.MajorPartner.Points[this.MajorPartner_qIndex];
                var   C     = this.MinorPartner.PrevPoint(this.MinorPartner_qIndex);
                float cross = GeoMath.Cross(A, B, C);
                if (cross < 0)
                {
                    return(false);
                }
            }

            return(true);
        }