Пример #1
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");
        }