示例#1
0
        public void AddSupportPolygonsTest()
        {
            PlanarSlice slice = new PlanarSlice();
            Polygon2d   p2d   = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(0, 1),
                new Vector2d(1, 1)
            });
            GeneralPolygon2d poly = new GeneralPolygon2d(p2d);
            Polygon2d        p2d2 = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(-1, 0),
                new Vector2d(0, -1),
                new Vector2d(-1, -1)
            });
            GeneralPolygon2d poly2 = new GeneralPolygon2d(p2d2);

            slice.AddSupportPolygons(new List <GeneralPolygon2d>()
            {
                poly, poly2
            });

            Assert.AreEqual(slice.SupportSolids[0], poly);
            Assert.AreEqual(slice.SupportSolids[1], poly2);
        }
示例#2
0
        public void ResolveTest()
        {
            PlanarSlice slice = new PlanarSlice();
            Polygon2d   p2d   = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(0, 1),
                new Vector2d(1, 1)
            });
            GeneralPolygon2d poly = new GeneralPolygon2d(p2d);
            Polygon2d        p2d2 = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(-1, 0),
                new Vector2d(0, -1),
                new Vector2d(-1, -1)
            });
            GeneralPolygon2d poly2 = new GeneralPolygon2d(p2d2);

            slice.AddPolygons(new List <GeneralPolygon2d>()
            {
                poly, poly2
            });

            Assert.AreEqual(slice.InputSolids[0], poly);
            Assert.AreEqual(slice.InputSolids[1], poly2);

            PolyLine2d line = new PolyLine2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(-1, 0)
            });

            slice.AddEmbeddedPath(line);
            slice.EmbeddedPathWidth = 1;

            Polygon2d supportp2d = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(0, 1),
                new Vector2d(1, 1)
            });
            GeneralPolygon2d supportpoly = new GeneralPolygon2d(supportp2d);
            Polygon2d        supportp2d2 = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(-1, 0),
                new Vector2d(0, -1),
                new Vector2d(-1, -1)
            });
            GeneralPolygon2d supportpoly2 = new GeneralPolygon2d(supportp2d2);

            slice.AddSupportPolygons(new List <GeneralPolygon2d>()
            {
                supportpoly, supportpoly2
            });

            Polygon2d cavp2d = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(0, 1),
                new Vector2d(1, 1)
            });
            GeneralPolygon2d cavpoly = new GeneralPolygon2d(cavp2d);
            Polygon2d        cavp2d2 = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(-1, 0),
                new Vector2d(0, -1),
                new Vector2d(-1, -1)
            });
            GeneralPolygon2d cavpoly2 = new GeneralPolygon2d(cavp2d2);

            slice.AddCavityPolygons(new List <GeneralPolygon2d>()
            {
                cavpoly, cavpoly2
            });

            Polygon2d cropp2d = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(1, 0),
                new Vector2d(0, 1),
                new Vector2d(1, 1)
            });
            GeneralPolygon2d croppoly = new GeneralPolygon2d(cropp2d);
            Polygon2d        cropp2d2 = new Polygon2d(new List <Vector2d>()
            {
                new Vector2d(-1, 0),
                new Vector2d(0, -1),
                new Vector2d(-1, -1)
            });
            GeneralPolygon2d croppoly2 = new GeneralPolygon2d(cropp2d2);

            slice.AddCropRegions(new List <GeneralPolygon2d>()
            {
                croppoly, croppoly2
            });

            slice.Resolve();

            slice.BuildSpatialCaches();

            double dist = slice.DistanceSquared(new Vector2d(5, 5));

            Assert.AreEqual(41, dist);
        }