Пример #1
0
        public void ContainsPoint()
        {
            Polygon2f polygon = CreatePolygon2.FromBox(new Vector2f(-2), new Vector2f(2));
            Polygon2f hole    = CreatePolygon2.FromBox(new Vector2f(-1), new Vector2f(1));

            hole.MakeCW();

            polygon.AddHole(hole);

            PolygonIntersection2.PushPolygon(polygon);

            //in polygon
            Assert.IsTrue(PolygonIntersection2.ContainsPoint(new Vector2f(1.5f, 1.5f)));
            Assert.IsTrue(PolygonIntersection2.ContainsPoint(new Vector2f(1.5f, -1.5f)));
            Assert.IsTrue(PolygonIntersection2.ContainsPoint(new Vector2f(-1.5f, 1.5f)));
            Assert.IsTrue(PolygonIntersection2.ContainsPoint(new Vector2f(-1.5f, -1.5f)));

            //in hole
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(0, 0)));

            //on polygon boundary
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(2, 2)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(2, -2)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(-2, 2)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(-2, -2)));

            //on hole boundary
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(1, 1)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(1, -1)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(-1, 1)));
            Assert.IsFalse(PolygonIntersection2.ContainsPoint(new Vector2f(-1, -1)));

            PolygonIntersection2.PopPolygon();
        }
Пример #2
0
        protected override void OnLeftClick(Vector2f point)
        {
            if (MadePolygon)
            {
                PolygonIntersection2.PushPolygon(polygon);

                result          = new IntersectionResult();
                result.contains = PolygonIntersection2.ContainsPoint(point);
                result.point    = point;

                PolygonIntersection2.PopPolygon();
            }
        }
Пример #3
0
        public static void Triangulate <MESH>(Polygon2f polygon, IMeshConstructor <MESH> constructor)
        {
            Insert(polygon);

            MeshDescriptor descriptor;

            if (CGAL_Triangulate(out descriptor) != SUCCESS)
            {
                throw new Exception("Error triangulating points.");
            }

            PolygonIntersection2.PushPolygon(polygon);
            CreateMesh(constructor, descriptor);
            PolygonIntersection2.PopPolygon();

            CGAL_Clear();
        }
Пример #4
0
        private static void CreateMesh <MESH>(IMeshConstructor <MESH> constructor, MeshDescriptor des)
        {
            constructor.PushTriangleMesh(des.Vertices, des.Faces);

            for (int i = 0; i < des.Vertices; i++)
            {
                constructor.AddVertex(CGAL_GetPoint2f(i));
            }

            for (int i = 0; i < des.Faces; i++)
            {
                TriangleIndex triangle = CGAL_GetTriangle(i);
                Vector2f      a        = CGAL_GetPoint2f(triangle.i0);
                Vector2f      b        = CGAL_GetPoint2f(triangle.i1);
                Vector2f      c        = CGAL_GetPoint2f(triangle.i2);

                Vector2f p = (a + b + c) / 3.0f;

                if (PolygonIntersection2.ContainsPoint(p))
                {
                    constructor.AddFace(triangle);
                }
            }
        }