private List <Vector2[]> TrianglesFromTessellator(Tess tess)
        {
            var triangles = new List <Vector2[]>();

            // Do the tessellation
            tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);

            // Extract the triangles
            int numTriangles = tess.ElementCount;

            for (int i = 0; i < numTriangles; i++)
            {
                var v0 = tess.Vertices[tess.Elements[i * 3 + 0]].Position;
                var v1 = tess.Vertices[tess.Elements[i * 3 + 1]].Position;
                var v2 = tess.Vertices[tess.Elements[i * 3 + 2]].Position;

                var triangle = new List <Vector2>()
                {
                    new Vector2(v0.X, v0.Y),
                    new Vector2(v1.X, v1.Y),
                    new Vector2(v2.X, v2.Y),
                };

                // Assume each triangle needs to be CCW
                float cross = GeoMath.Cross(triangle[0], triangle[1], triangle[2]);
                if (cross > 0)
                {
                    triangle.Reverse();
                }

                triangles.Add(triangle.ToArray());
            }

            return(triangles);
        }
Exemple #2
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);
        }