Ejemplo n.º 1
0
        public void AlreadySplitGridsThrowsExceptionWhenDividedByN()
        {
            var grid = new Grid1d();

            grid.SplitAtParameter(0.25);
            var ex = Assert.Throws <Exception>(() => grid.DivideByCount(10));

            Assert.Equal("This grid already has subdivisions. Maybe you meant to select a subgrid to divide?", ex.Message);
        }
Ejemplo n.º 2
0
        public void GetSeparators()
        {
            var grid = new Grid1d(100);

            grid.DivideByCount(5);
            var pts = grid.GetCellSeparators();

            Assert.Equal(6, pts.Count);
            Assert.Equal(pts[0], new Vector3(0, 0, 0));
            Assert.Equal(pts[1], new Vector3(20, 0, 0));
            Assert.Equal(pts[5], new Vector3(100, 0, 0));

            grid[1].DivideByCount(3);
            var pts2 = grid.GetCellSeparators(true);

            Assert.Equal(8, pts2.Count);
        }
Ejemplo n.º 3
0
        public void Grid1dSerializes()
        {
            var polyline = new Polyline(new[] {
                new Vector3(0, 0, 0),
                new Vector3(10, 2, 0),
                new Vector3(30, 4, 0),
            });
            var grid = new Grid1d(polyline);

            grid.DivideByCount(4);
            grid[3].DivideByFixedLength(0.4);
            var json         = JsonConvert.SerializeObject(grid);
            var deserialized = JsonConvert.DeserializeObject <Grid1d>(json);

            Assert.Equal(grid.GetCells().Count, deserialized.GetCells().Count);
            Assert.Equal(0, (grid.Curve as Polyline).Start.DistanceTo((deserialized.Curve as Polyline).Start));
        }
Ejemplo n.º 4
0
        public void TryToSplitButAlreadySplitAtLowerLevel()
        {
            //var grid = new Grid1d(100);
            //grid.DivideByCount(2); //now split at 50
            //grid[1].SplitAtParameter(0.5); // splitting child cell at halfway mark = 75 on the parent
            //grid.SplitAtPosition(75); // should silently do nothing.
            //Assert.Equal(3, grid.GetCells().Count);

            var grid2 = new Grid1d(256);

            grid2.DivideByCount(2);          //split at 128
            grid2[0].DivideByCount(2);       // split at 64
            grid2[0][0].DivideByCount(2);    // split at 32
            grid2[0][0][0].DivideByCount(2); // split at 16
            grid2.SplitAtPosition(32);
            Assert.Equal(5, grid2.GetCells().Count);
            Assert.Equal(3, grid2.Cells.Count);
            Assert.Single(grid2[0].Cells);
            Assert.Equal(2, grid2[1].Cells.Count);
            Assert.Single(grid2[0][0].Cells);
            Assert.Equal(2, grid2[0][0][0].Cells.Count);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Construct a set of elements from this rule for a given definition.
        /// </summary>
        /// <param name="definition">The definition to instantiate.</param>
        public List <Element> Instantiate(ComponentDefinition definition)
        {
            var arrayElements = new List <Element>();
            var newVertices   = PolylinePlacementRule.TransformPolyline(this, definition);

            var path = IsClosed ? new Polygon(newVertices) : new Polyline(newVertices);

            var grid1d = new Grid1d(path);

            switch (SpacingRule.SpacingMode)
            {
            case SpacingMode.ByLength:
                grid1d.DivideByFixedLength(SpacingRule.Value);
                break;

            case SpacingMode.ByApproximateLength:
                grid1d.DivideByApproximateLength(SpacingRule.Value);
                break;

            case SpacingMode.ByCount:
                grid1d.DivideByCount((int)SpacingRule.Value);
                break;
            }

            var separators = grid1d.GetCellSeparators();

            foreach (var sep in separators)
            {
                ElementDefinition.IsElementDefinition = true;
                var transform = new Transform(definition.OrientationGuide);
                transform.Concatenate(new Transform(sep));
                var instance = ElementDefinition.CreateInstance(transform, Guid.NewGuid().ToString());
                arrayElements.Add(instance);
            }
            return(arrayElements);
        }
Ejemplo n.º 6
0
        private Representation ConstructRepresentation()
        {
            if (CellCount == 0)
            {
                return(null);
            }

            JoistPoints.Clear();

            var ll = Construct2LProfile(TopChordProfile, true);

            var topSweepR = new Sweep(ll[0],
                                      Curve,
                                      StartSetback,
                                      EndSetback,
                                      Rotation,
                                      false);
            var topSweepL = new Sweep(ll[1],
                                      Curve,
                                      StartSetback,
                                      EndSetback,
                                      Rotation,
                                      false);

            var  startT = Curve.TransformAt(0);
            Line line   = (Line)Curve;

            var topStart = line.Start - startT.ZAxis * DistanceToFirstPanel;
            var topEnd   = line.End + startT.ZAxis * DistanceToFirstPanel;

            var bottomStart = line.Start - startT.YAxis * Depth - startT.ZAxis * DistanceToFirstPanel;
            var bottomEnd   = line.End - startT.YAxis * Depth + startT.ZAxis * DistanceToFirstPanel;

            ll = Construct2LProfile(BottomChordProfile);

            var bottomChord  = new Line(bottomStart, bottomEnd);
            var bottomSweepR = new Sweep(ll[0],
                                         bottomChord,
                                         0,
                                         0,
                                         Rotation,
                                         false);
            var bottomSweepL = new Sweep(ll[1],
                                         bottomChord,
                                         0,
                                         0,
                                         Rotation,
                                         false);

            // Use a line that is shorter than the curve length.
            var topGrid = new Grid1d(new Line(topStart, topEnd));

            topGrid.DivideByCount(CellCount);

            var bottomGrid = new Grid1d(bottomChord);

            bottomGrid.DivideByCount(CellCount);

            var topPts    = topGrid.GetCellSeparators();
            var bottomPts = bottomGrid.GetCellSeparators();

            var solidOperations = new List <SolidOperation>()
            {
                topSweepL, topSweepR, bottomSweepL, bottomSweepR
            };

            Vector3 prevTop    = default;
            Vector3 prevBottom = default;

            var wll = Construct2LProfile(WebProfile);

            for (var i = 0; i < topPts.Count; i++)
            {
                var topPt    = topPts[i];
                var bottomPt = bottomPts[i];
                if (i % 2 == 0)
                {
                    prevTop = topPt;

                    // Vertical web
                    if (i != 0 && i != topPts.Count - 1)
                    {
                        var v1 = new Sweep(wll[0],
                                           new Line(topPt, bottomPt),
                                           0,
                                           0,
                                           0,
                                           false);
                        solidOperations.Add(v1);
                        var v2 = new Sweep(wll[1],
                                           new Line(topPt, bottomPt),
                                           0,
                                           0,
                                           0,
                                           false);
                        solidOperations.Add(v2);

                        JoistPoints.Add(topPt);
                    }

                    // Forward leaning web
                    if (i > 0)
                    {
                        var fl1 = new Sweep(wll[0],
                                            new Line(prevBottom, topPt),
                                            0,
                                            0,
                                            0,
                                            false);
                        solidOperations.Add(fl1);
                        var fl2 = new Sweep(wll[1],
                                            new Line(prevBottom, topPt),
                                            0,
                                            0,
                                            0,
                                            false);
                        solidOperations.Add(fl2);
                    }
                }
                else
                {
                    // Backward leaning web
                    var bl1 = new Sweep(wll[0],
                                        new Line(bottomPt, prevTop),
                                        0,
                                        0,
                                        0,
                                        false);
                    solidOperations.Add(bl1);
                    var bl2 = new Sweep(wll[1],
                                        new Line(bottomPt, prevTop),
                                        0,
                                        0,
                                        0,
                                        false);
                    solidOperations.Add(bl2);

                    prevBottom = bottomPt;
                }
            }

            var rep = new Representation(solidOperations);

            return(rep);
        }