Esempio n. 1
0
        public void AvailableRandom()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var grid     = new CoordinateGrid(perimeter);
            var allocate = new Polygon
                           (
                new[]
            {
                new Vector3(10, 10),
                new Vector3(20, 10),
                new Vector3(20, 20),
                new Vector3(10, 20)
            }
                           );

            grid.Allocate(allocate);
            var point = grid.AvailableRandom();

            Assert.Contains(point, grid.Available);
        }
Esempio n. 2
0
        public void AllocatedNearTo()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var allocated = new List <Polygon>
            {
                new Polygon
                (
                    new []
                {
                    Vector3.Origin,
                    new Vector3(8, 0),
                    new Vector3(8, 9),
                    new Vector3(0, 9)
                }
                ),
                new Polygon
                (
                    new []
                {
                    new Vector3(52, 0),
                    new Vector3(60, 0),
                    new Vector3(60, 6),
                    new Vector3(52, 6)
                }
                ),
                new Polygon
                (
                    new []
                {
                    new Vector3(24, 33),
                    new Vector3(32, 33),
                    new Vector3(32, 36),
                    new Vector3(24, 36)
                }
                )
            };
            var grid = new CoordinateGrid(perimeter);

            foreach (Polygon polygon in allocated)
            {
                grid.Allocate(polygon);
            }
            var nearPoint = grid.AllocatedNearTo(new Vector3(26.6, 34.1));

            Assert.Equal(26.5, nearPoint.X);
            Assert.Equal(35.5, nearPoint.Y);
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            MyraEnvironment.Game = this;
            _spriteBatch         = new SpriteBatch(GraphicsDevice);

            _grid = new CoordinateGrid(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, Unit);

            _figure = new Figure(_grid);

            _gui = new Gui(_figure, _grid);
        }
Esempio n. 4
0
        public void Allocate()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var grid = new CoordinateGrid(perimeter);

            Assert.Equal(2160, grid.Available.Count);
            var allocate1 = new Polygon
                            (
                new[]
            {
                new Vector3(10, 10),
                new Vector3(20, 10),
                new Vector3(20, 20),
                new Vector3(10, 20)
            }
                            );

            grid.Allocate(allocate1);
            Assert.Equal(2060, grid.Available.Count);
            var allocate2 = new Polygon
                            (
                new[]
            {
                new Vector3(30, 10),
                new Vector3(40, 10),
                new Vector3(40, 30),
                new Vector3(30, 30)
            }
                            );

            grid = new CoordinateGrid(perimeter);
            var allocate = new List <Polygon> {
                allocate1, allocate2
            };

            grid.Allocate(allocate);
            Assert.Equal(1860, grid.Available.Count);
        }
Esempio n. 5
0
        public void AvailableNearTo()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(60, 0),
                new Vector3(60, 36),
                new Vector3(0, 36)
            }
                            );
            var grid      = new CoordinateGrid(perimeter);
            var nearPoint = grid.AvailableNearTo(new Vector3(50.6, 40.1));

            Assert.Equal(29.5, nearPoint.X);
            Assert.Equal(17.5, nearPoint.Y);
        }
Esempio n. 6
0
        public void AvailableMin()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(5.0, 5.0),
                new Vector3(60.0, 5.0),
                new Vector3(60.0, 36.0),
                new Vector3(5.0, 36.0)
            }
                            );
            var grid = new CoordinateGrid(perimeter);
            var min  = grid.AvailableMin();

            Assert.Equal(6.0, min.X);
            Assert.Equal(6.0, min.Y);
        }
Esempio n. 7
0
        public void AvailableMax()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(5, 5),
                new Vector3(60, 5),
                new Vector3(60, 36),
                new Vector3(5, 36)
            }
                            );
            var grid = new CoordinateGrid(perimeter);
            var max  = grid.AvailableMax();

            Assert.Equal(60, max.X);
            Assert.Equal(36, max.Y);
        }
Esempio n. 8
0
        public void CoordinateGrid()
        {
            var perimeter = new Polygon
                            (
                new[]
            {
                new Vector3(0, 0),
                new Vector3(20, 0),
                new Vector3(20, 30),
                new Vector3(0, 30)
            }
                            );
            var grid  = new CoordinateGrid(perimeter);
            var model = new Model();

            foreach (var point in grid.Available)
            {
                model.AddElement(new Column(point, 4.0, new Profile(Polygon.Rectangle(0.1, 0.1))));
            }
            model.ToGlTF("../../../../GeometryExTests/output/CoordinateGrid.glb");
            Assert.Equal(600, grid.Available.Count);
        }
Esempio n. 9
0
        /// <summary>
        /// The ColumnsByFloors function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A ColumnsByFloorsOutputs instance containing computed results and the model with any new elements.</returns>
        public static ColumnsByFloorsOutputs Execute(Dictionary <string, Model> inputModels, ColumnsByFloorsInputs input)
        {
            var allFloors = new List <Floor>();

            inputModels.TryGetValue("Floors", out var flrModel);
            if (flrModel == null || flrModel.AllElementsOfType <Floor>().Count() == 0)
            {
                throw new ArgumentException("No Floors found.");
            }
            allFloors.AddRange(flrModel.AllElementsOfType <Floor>());
            var floorGroups = new List <List <Floor> >();

            while (allFloors.Count > 0)
            {
                var testPerimeter = allFloors.First().Profile.Perimeter;
                var floors        = new List <Floor>();
                foreach (var floor in allFloors.ToList())
                {
                    if (testPerimeter.Intersects(floor.Profile.Perimeter))
                    {
                        floors.Add(floor);
                        allFloors.Remove(floor);
                    }
                }
                floorGroups.Add(floors);
            }
            var columns = new List <Column>();

            foreach (var floorGroup in floorGroups)
            {
                var floors = floorGroup.OrderBy(f => f.Elevation).ToList();
                for (var i = 0; i < floors.Count() - 1; i++)
                {
                    var   floor   = floors.ElementAt(i);
                    int   next    = 1;
                    Floor ceiling = null;
                    do
                    {
                        ceiling = floors.ElementAt(i + next);
                        next++;
                    } while (!floor.Profile.Perimeter.Intersects(ceiling.Profile.Perimeter));

                    var height = ceiling.Elevation - floor.Elevation - floor.Thickness;
                    var grid   = new CoordinateGrid(ceiling.Profile.Perimeter, input.GridXAxisInterval, input.GridYAxisInterval, input.GridRotation);
                    foreach (var point in grid.Available)
                    {
                        var colPerim = Polygon.Rectangle(input.ColumnDiameter, input.ColumnDiameter).MoveFromTo(Vector3.Origin, point);
                        if (!floor.Profile.Perimeter.Covers(colPerim) ||
                            !ceiling.Profile.Perimeter.Covers(colPerim))
                        {
                            continue;
                        }
                        columns.Add(new Column(point, height,
                                               new Profile(Polygon.Rectangle(input.ColumnDiameter, input.ColumnDiameter)),
                                               BuiltInMaterials.Concrete,
                                               new Transform(0.0, 0.0, floor.Elevation + floor.Thickness),
                                               0.0, 0.0, input.GridRotation,
                                               false, Guid.NewGuid(), ""));
                    }
                }
            }
            var output = new ColumnsByFloorsOutputs(columns.Count());

            foreach (var column in columns)
            {
                output.model.AddElement(column);
            }
            return(output);
        }
Esempio n. 10
0
        public Gui(Figure figure, CoordinateGrid coordinateGrid)
        {
            _figure         = figure;
            _coordinateGrid = coordinateGrid;

            CreateParametersWindow();
            CreateEuclideanWindow();
            CreateHomographyWindow();
            CreateAffineWindow();

            var grid = new Grid
            {
                RowSpacing    = 6,
                ColumnSpacing = 8
            };

            _desktop = new Desktop
            {
                Root = grid
            };

            grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
            grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
            grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
            grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
            grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
            grid.RowsProportions.Add(new Proportion(ProportionType.Auto));

            var button = new TextButton
            {
                GridColumn = 0,
                GridRow    = 0,
                Text       = "Parameters"
            };

            button.Click += (sender, args) =>
            {
                _parametersWindow.ShowModal(_desktop);
            };
            grid.Widgets.Add(button);

            button = new TextButton
            {
                GridColumn = 0,
                GridRow    = 1,
                Text       = "Euclidean"
            };
            button.Click += (sender, args) =>
            {
                _euclideanWindow.ShowModal(_desktop);
            };
            grid.Widgets.Add(button);

            button = new TextButton
            {
                GridColumn = 0,
                GridRow    = 2,
                Text       = "Affine"
            };
            button.Click += (sender, args) =>
            {
                _affineWindow.ShowModal(_desktop);
            };
            grid.Widgets.Add(button);

            button = new TextButton
            {
                GridColumn = 0,
                GridRow    = 3,
                Text       = "Homography"
            };
            button.Click += (sender, args) =>
            {
                _homographyWindow.ShowModal(_desktop);
            };
            grid.Widgets.Add(button);

            button = new TextButton
            {
                GridColumn = 0,
                GridRow    = 4,
                Text       = "Clear"
            };
            button.Click += (sender, args) =>
            {
                _figure.Reset();
                _coordinateGrid.Reset();

                CreateParametersWindow();
                CreateEuclideanWindow();
                CreateHomographyWindow();
                CreateAffineWindow();
            };
            grid.Widgets.Add(button);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates the shell of a building service core by attempting to place a footprint of various side ratios and rotations within the smallest envelope of the building. If the specified service core cannot fit within the building, the core is displaced to the exterior at the midpoint of the longest side of the highest envelope.
        /// </summary>
        /// <param name="inputs">Inputs from the UI.</param>
        /// <param name="envelopes">List of Envelopes from an incoming model.</param>
        /// <returns>A CoreDef structure specifying a service core.</returns>
        public static CoreDef MakeCore(CoreByEnvelopeInputs inputs, List <Envelope> envelopes)
        {
            var height = 0.0;

            envelopes = envelopes.OrderBy(e => e.Elevation).ToList();
            envelopes.ForEach(e => height += e.Height);
            height += inputs.ServiceCorePenthouseHeight;
            var footprint = envelopes.First().Profile.Perimeter;
            var ftArea    = Math.Abs(footprint.Area());
            var area      = ftArea * inputs.PercentageArea;
            var crown     = envelopes.Last().Profile.Perimeter;
            var crownOff  = crown.Offset(inputs.MinimumPerimeterOffset * -1.0);

            if (crownOff.Count() > 0)
            {
                crown = crownOff.First();
            }
            var angLine   = crown.Segments().OrderByDescending(s => s.Length()).ToList().First();
            var angle     = Math.Atan2(angLine.End.Y - angLine.Start.Y, angLine.End.X - angLine.Start.X) * (180 / Math.PI);
            var perimeter = Shaper.RectangleByArea(area, inputs.LengthToWidthRatio);

            perimeter = perimeter.Rotate(perimeter.Centroid(), angle);
            var compass = new CompassBox(perimeter);
            var coreDef = new CoreDef
            {
                perimeter = perimeter,
                elevation = envelopes.First().Elevation,
                height    = height,
                length    = compass.SizeX,
                width     = compass.SizeY,
                rotation  = angle
            };
            var positions = new List <Vector3>();
            var centroid  = crown.Centroid();
            var coordGrid = new CoordinateGrid(crown);

            positions.AddRange(coordGrid.Available);
            if (crown.Covers(centroid))
            {
                positions = positions.OrderBy(p => p.DistanceTo(centroid)).ToList();
                positions.Insert(0, centroid);
            }
            foreach (var position in positions)
            {
                perimeter = perimeter.MoveFromTo(perimeter.Centroid(), position);
                var rotation = coreDef.rotation;
                while (rotation <= angle + 90.0)
                {
                    perimeter = perimeter.Rotate(position, rotation);
                    if (crown.Covers(perimeter))
                    {
                        coreDef.perimeter = perimeter;
                        coreDef.rotation  = rotation;
                        return(coreDef); // Return the first successful interior placement.
                    }
                    rotation += CORE_ROTATE_INCREMENT;
                }
            }

            // If no internal position found, place the service core to penetrate all envelopes along their longest side.

            angLine   = footprint.Segments().OrderByDescending(s => s.Length()).ToList().First();
            angle     = Math.Atan2(angLine.End.Y - angLine.Start.Y, angLine.End.X - angLine.Start.X) * (180 / Math.PI);
            perimeter = Shaper.RectangleByArea(area, inputs.LengthToWidthRatio);
            perimeter = perimeter.MoveFromTo(perimeter.Centroid(), angLine.Midpoint()).Rotate(angLine.Midpoint(), angle);
            crown     = envelopes.Last().Profile.Perimeter;
            if (!perimeter.Intersects(crown))
            {
                angLine   = crown.Segments().OrderByDescending(s => s.Length()).ToList().First();
                angle     = Math.Atan2(angLine.End.Y - angLine.Start.Y, angLine.End.X - angLine.Start.X) * (180 / Math.PI);
                perimeter = Shaper.RectangleByArea(area, inputs.LengthToWidthRatio);
                perimeter = perimeter.MoveFromTo(perimeter.Centroid(), angLine.Midpoint()).Rotate(angLine.Midpoint(), angle);
            }
            coreDef.perimeter = perimeter;
            return(coreDef);
        }