Esempio n. 1
0
 public void DifferencesTests()
 {
     for (var i = 0; i < 10; i++)
     {
         var ROTATE    = Shaper.RandomDouble(0.0, 360.0);
         var polygon   = Polygon.Rectangle(Vector3.Origin, new Vector3(100.0, 50.0)).Rotate(Vector3.Origin, ROTATE);
         var subtract  = Polygon.Rectangle(Vector3.Origin, new Vector3(1.0, 20.0));
         var subtracts = new List <Polygon>();
         for (var j = 1; j < 99; j++)
         {
             subtracts.Add(subtract.MoveFromTo(Vector3.Origin, new Vector3(j, 0.0)).Rotate(Vector3.Origin, ROTATE));
         }
         subtract = Polygon.Rectangle(new Vector3(0.0, 30.0), new Vector3(1.0, 50.0));
         for (var j = 1; j < 99; j++)
         {
             subtracts.Add(subtract.MoveFromTo(Vector3.Origin, new Vector3(j, 0.0)).Rotate(Vector3.Origin, ROTATE));
         }
         var polygons = Shaper.Differences(polygon.ToList(), subtracts, 0.01);
         var matl     = new Material(Palette.Aqua, 0.0, 0.0, false, null, false, Guid.NewGuid(), "space");
         var model    = new Model();
         var count    = 0;
         foreach (var shape in polygons)
         {
             model.AddElement(new Space(shape, 0.1, BuiltInMaterials.Concrete));
             count++;
         }
         foreach (var shape in subtracts)
         {
             model.AddElement(new Space(shape, 4.0, matl));
             count++;
         }
         Assert.True(count > 196);
         var fileName = "../../../../GeometryExTests/output/Shaper.DifferenceTest" + ROTATE.ToString() + ".glb";
         model.ToGlTF(fileName);
     }
 }
Esempio n. 2
0
        public void Adjacent()
        {
            var perimeter =
                new Polygon
                (
                    new[]
            {
                new Vector3(0.0, 0.0),
                new Vector3(20.0, 0.0),
                new Vector3(20.0, 20.0),
                new Vector3(14.0, 20.0),
                new Vector3(14.0, 11.0),
                new Vector3(11.0, 11.0),
                new Vector3(11.0, 20.0),
                new Vector3(0.0, 20.0)
            }
                );
            var Rooms = new List <Polygon>();
            var among = new List <Polygon>();

            for (int i = 0; i < 3; i++)
            {
                Rooms.Add(new Polygon(new[] { Vector3.Origin,
                                              new Vector3(10.0, 0.0),
                                              new Vector3(10.0, 5.0),
                                              new Vector3(0.0, 5.0) }));
            }
            for (int i = 0; i < 8; i++)
            {
                Rooms.Add(new Polygon(new[] { Vector3.Origin,
                                              new Vector3(5.0, 0.0),
                                              new Vector3(5.0, 5.0),
                                              new Vector3(0.0, 5.0) }));
            }
            var boxPlace = new TopoBox(Rooms.First());
            var boxPerim = new TopoBox(perimeter);

            among.Add(Rooms.First().MoveFromTo(boxPlace.SW, boxPerim.SW));
            foreach (Polygon place in Rooms)
            {
                Polygon polygon = null;
                foreach (Polygon inPlace in among)
                {
                    polygon = Place.Adjacent(place, inPlace, perimeter, among);
                    if (polygon != null)
                    {
                        break;
                    }
                }
                if (polygon != null)
                {
                    among.Add(polygon);
                }
            }
            var model = new Model();

            model.AddElement(new Space(perimeter, elevation: -0.02, height: 0.1, material: BuiltInMaterials.Concrete));
            foreach (Polygon polygon in among)
            {
                var color = new Color((float)Shaper.RandomDouble(0, 1),
                                      (float)Shaper.RandomDouble(0, 1),
                                      (float)Shaper.RandomDouble(0, 1), 0.7f);
                model.AddElement(new Space(polygon, height: 4.0, material: new Material(Guid.NewGuid().ToString(), color)));
            }
            model.SaveGlb("../../../../adjacent.glb");
        }