public void TrimmedCellProfile() { var outer = new Polygon(new List <Vector3> { new Vector3(0, 0, 0), new Vector3(10, 0, 0), new Vector3(10, 0, 10), new Vector3(0, 0, 10) }); var inner1 = new Polygon(new List <Vector3> { new Vector3(3, 0, 9), new Vector3(3, 0, 7), new Vector3(1, 0, 7), new Vector3(1, 0, 9) }); var inner2 = new Polygon(new List <Vector3> { new Vector3(9, 0, 3), new Vector3(9, 0, 1), new Vector3(7, 0, 1), new Vector3(7, 0, 3) }); var inner3 = new Polygon(new List <Vector3> { new Vector3(6, 0, 6), new Vector3(6, 0, 3), new Vector3(3, 0, 3), new Vector3(3, 0, 6) }); var polygons = new List <Polygon>(); polygons.Add(outer); polygons.Add(inner1); polygons.Add(inner2); polygons.Add(inner3); var grid = new Grid2d(polygons); var profiles = grid.GetTrimmedCellProfiles(); Assert.Single(profiles); var profile = profiles.FirstOrDefault(); Assert.Equal(3, profile.Voids.Count()); Assert.Equal(100, profile.Perimeter.Area()); Assert.Equal(4, profile.Voids[0].Area()); Assert.Equal(9, profile.Voids[1].Area()); Assert.Equal(4, profile.Voids[2].Area()); }
public void TrimBehavior() { Name = "TrimBehavior"; var polygonjson = "[{\"discriminator\":\"Elements.Geometry.Polygon\",\"Vertices\":[{\"X\":-14.371519985751306,\"Y\":-4.8816304299427005,\"Z\":0.0},{\"X\":-17.661873645682569,\"Y\":9.2555712951713573,\"Z\":0.0},{\"X\":12.965610421927806,\"Y\":9.2555712951713573,\"Z\":0.0},{\"X\":12.965610421927806,\"Y\":3.5538269529982784,\"Z\":0.0},{\"X\":6.4046991240848143,\"Y\":3.5538269529982784,\"Z\":0.0},{\"X\":1.3278034769444158,\"Y\":-4.8816304299427005,\"Z\":0.0}]},{\"discriminator\":\"Elements.Geometry.Polygon\",\"Vertices\":[{\"X\":-9.4508365123690652,\"Y\":0.20473478280229102,\"Z\":0.0},{\"X\":-1.8745460850979974,\"Y\":0.20473478280229102,\"Z\":0.0},{\"X\":-1.8745460850979974,\"Y\":5.4378426037008651,\"Z\":0.0},{\"X\":-9.4508365123690652,\"Y\":5.4378426037008651,\"Z\":0.0}]}]\r\n"; var polygons = JsonConvert.DeserializeObject <List <Polygon> >(polygonjson); var grid = new Grid2d(polygons); foreach (var pt in polygons[1].Vertices) { grid.SplitAtPoint(pt); } grid.CellsFlat.ForEach(c => c.U.DivideByApproximateLength(1.0, EvenDivisionMode.RoundDown)); var trimmedCells = grid.GetCells().Select(c => (TrimmedGeometry: c.GetTrimmedCellGeometry(), BaseRect: c.GetCellGeometry(), IsTrimmed: c.IsTrimmed())); foreach (var trimGeometry in trimmedCells) { var trimGeo = trimGeometry.TrimmedGeometry.OfType <Polygon>(); var material = trimGeometry.IsTrimmed ? BuiltInMaterials.XAxis : BuiltInMaterials.ZAxis; foreach (var t in trimGeo) { Model.AddElement(new ModelCurve(t)); Model.AddElement(new Mass(t, 1, material, new Transform(0, 0, -1.001))); } } Assert.Equal(87, trimmedCells.Count()); Assert.Equal(18, trimmedCells.Count(c => c.IsTrimmed)); }
public void CellSeparatorsTrimmed() { Name = "CellSeparatorsTrimmed"; var polygon = new Polygon(new[] { Vector3.Origin, new Vector3(4, 2), new Vector3(5, 3), new Vector3(7, 7), new Vector3(3, 6) }); var polygon2 = new Polygon(new[] { new Vector3(1.1, 1), new Vector3(1.5, 1), new Vector3(1.5, 2), new Vector3(1.1, 2) }); var polygons = new[] { polygon, polygon2 }; var grid2d = new Grid2d(polygons); grid2d.U.DivideByCount(10); grid2d.V.DivideByFixedLength(1); var csu = grid2d.GetCellSeparators(GridDirection.U, true); var csv = grid2d.GetCellSeparators(GridDirection.V, true); Assert.Equal(10, csu.Count); Assert.Equal(10, csv.Count); Model.AddElements(polygons.Select(p => new ModelCurve(p, BuiltInMaterials.XAxis))); Model.AddElements(csu.Union(csv).Select(l => new ModelCurve(l as Line))); }
private static void PanelGroundFloor(double bottomElevation, double topElevation, Line[] boundarySegments, double panelWidth, Model model) { foreach (var segment in boundarySegments) { var u = new Grid1d(segment); var v = new Grid1d(new Line(segment.Start, new Vector3(segment.Start.X, segment.Start.Y, segment.Start.Z + topElevation))); var grid2d = new Grid2d(u, v); grid2d.U.DivideByFixedLength(1.5); grid2d.V.DivideByCount(2); foreach (var sep in grid2d.GetCellSeparators(GridDirection.U)) { var mullion = new Beam((Line)sep, Polygon.Rectangle(0.05, 0.05), BuiltInMaterials.Black); model.AddElement(mullion); } foreach (var sep in grid2d.GetCellSeparators(GridDirection.V)) { var mullion = new Beam((Line)sep, Polygon.Rectangle(0.05, 0.05), BuiltInMaterials.Black); model.AddElement(mullion); } var panel = new Panel(new Polygon(new[] { segment.Start, segment.End, new Vector3(segment.End.X, segment.End.Y, segment.End.Z + topElevation), new Vector3(segment.Start.X, segment.Start.Y, segment.Start.Z + topElevation) }), BuiltInMaterials.Glass); model.AddElement(panel); } }
public void CellComplexExample() { this.Name = "Elements_Spatial_CellComplex_CellComplex"; // <example> // Assemble CellComplex from Grid2d var numLevels = 10; var levelHeight = 1; var cellSize = 2; var complex = new CellComplex(); var boundary = new Circle(new Vector3(), 10).ToPolygon(); var grid = new Grid2d(boundary, Vector3.Origin, Vector3.XAxis, Vector3.YAxis); var pathMaterial = new Material("Path", new Color(1, 0, 0, 0.75)); grid.U.DivideByFixedLength(cellSize); grid.V.DivideByFixedLength(cellSize); for (var i = 0; i < numLevels; i++) { foreach (var cell in grid.GetCells()) { foreach (var crv in cell.GetTrimmedCellGeometry()) { complex.AddCell((Polygon)crv, levelHeight, i * levelHeight, grid.U, grid.V); } } } // Draw base CellComplex foreach (var face in complex.GetFaces()) { this.Model.AddElement(new Panel(face.GetGeometry(), BuiltInMaterials.Mass)); } // Traverse CellComplex var start = new Vector3(15, 15, 15); var end = new Vector3(-15, -15, -15); // Draw lines from start and end to closest points, for reference foreach (var pt in new List <Vector3>() { start, end }) { var closest = complex.GetClosestVertex(pt).GetGeometry(); this.Model.AddElement(new ModelCurve(new Line(pt, closest), pathMaterial)); } var curCell = complex.GetClosestCell(start); var traversedCells = curCell.TraverseNeighbors(end); foreach (var cell in traversedCells) { var rep = new Representation(new[] { cell.GetGeometry() }); this.Model.AddElement(new GeometricElement(new Transform(), pathMaterial, rep, false, Guid.NewGuid(), "Path")); } // </example> }
public static void DrawGrid(Model model, Grid2d grid, List <Vector3> uPoints, List <Vector3> vPoints) { foreach (var cell in grid.GetCells()) { var polygon = (Polygon)cell.GetCellGeometry(); foreach (var vertex in polygon.Vertices) { Debug.DrawPoint(model, vertex, MagentaMaterial); } var color = RandomExtensions.NextColor(random); foreach (var cellPiece in cell.GetTrimmedCellGeometry()) { var material = new Material(color.ToString(), new Color(color.Red, color.Green, color.Blue, 0.5), unlit: true); var poly = (Polygon)cellPiece; if (poly.Vertices.Count >= 3) { model.AddElement(new Panel(poly, material: material)); } } } foreach (var pt in vPoints) { Debug.DrawPoint(model, pt, MagentaMaterial); } foreach (var pt in uPoints) { Debug.DrawPoint(model, pt, MagentaMaterial); } }
public void Grid2dSerializes() { Name = "grid2d serializes"; var polyline = new Polyline(new[] { new Vector3(0, 0, 0), new Vector3(10, 2, 0), new Vector3(30, 4, 0), }); var uGrid = new Grid1d(polyline); var p2 = new Line(Vector3.Origin, new Vector3(0, 20, 0)); var vGrid = new Grid1d(p2); var grid2d = new Grid2d(uGrid, vGrid); grid2d.U.DivideByCount(10); grid2d.V.DivideByCount(3); grid2d[2, 2].U.DivideByCount(4); var json = JsonConvert.SerializeObject(grid2d); var deserialized = JsonConvert.DeserializeObject <Grid2d>(json); Assert.Equal(grid2d.GetCells().Count, deserialized.GetCells().Count); var grid2dElem = new Grid2dElement(grid2d, Guid.NewGuid(), "Grid"); Model.AddElement(grid2dElem); }
/** * @return the so-called Moore neighborhood: the 8 neighbors of a cell at North, South, East, West, NW, NE, SW, SE */ private IList <ICell> BuildMooreNeighbors(ICell cell) { IList <ICell> neighbors = new List <ICell>(); Grid2d <ICell> .Location cellPosition = grid2d.GetPosition(cell); int X = cellPosition.GetX(); int Y = cellPosition.GetY(); ICell northNeighbor = grid2d.GetCell(X, GetNorthY(Y)); ICell southNeighbor = grid2d.GetCell(X, GetSouthY(Y)); ICell eastNeighbor = grid2d.GetCell(GetEastX(X), Y); ICell westNeighbor = grid2d.GetCell(GetWestX(X), Y); ICell northEastNeighbor = grid2d.GetCell(GetEastX(X), GetNorthY(Y)); ICell northWestNeighbor = grid2d.GetCell(GetWestX(X), GetNorthY(Y)); ICell southEastNeighbor = grid2d.GetCell(GetEastX(X), GetSouthY(Y)); ICell southWestNeighbor = grid2d.GetCell(GetWestX(X), GetSouthY(Y)); //add the neighbors to the list, if they exist(at the boundary cells have no all of the 4 neighbors) if (northNeighbor != null) { neighbors.Add(northNeighbor); } if (southNeighbor != null) { neighbors.Add(southNeighbor); } if (eastNeighbor != null) { neighbors.Add(eastNeighbor); } if (westNeighbor != null) { neighbors.Add(westNeighbor); } if (northEastNeighbor != null) { neighbors.Add(northEastNeighbor); } if (northWestNeighbor != null) { neighbors.Add(northWestNeighbor); } if (southEastNeighbor != null) { neighbors.Add(southEastNeighbor); } if (southWestNeighbor != null) { neighbors.Add(southWestNeighbor); } //add the cell-itself to the neighborhood if (includeCell) { neighbors.Add(cell); } return(neighbors); }
public void Grid2d() { this.Name = "Elements_Spatial_Grid2d"; // <example> // Create a 2d grid that's 40 x 30 in size var grid = new Grid2d(40, 30); // Access the U and V axes directly and use 1d subdivision methods on them grid.U.DivideByFixedLength(7, FixedDivisionMode.RemainderAtBothEnds); grid.V.DivideByPattern(new[] { 2.0, 5.0 }); // Get a row by index var fifthRow = grid.GetRowAtIndex(4); // Divide U axis of all cells in row into panels of approximate width 1 fifthRow.ForEach(c => c.U.DivideByApproximateLength(1)); // Get a cell by u, v indices var cell = grid[1, 1]; // Divide the cell in the V direction cell.V.DivideByCount(4); // Create a floor from the entire grid's boundary var floor = new Floor(new Profile((Polygon)grid.GetCellGeometry()), 0.5, new Transform(0, 0, -0.51)); // Create model curves from all subdivided cells of the grid var modelCurves = grid.ToModelCurves(); // </example> Model.AddElement(floor); Model.AddElements(modelCurves); }
public Grid2d <ICell> BuildCellularGrid() { //create the grid cellularGrid = CreateCellularGrid(); //add cells to the grid: PopulateGrid(); //initialize cell state: ICAConfig initialConfiguration = GetInitialConfiguration(); if (initialConfiguration != null) { foreach (ICell cell in cellularGrid.GetObjects()) { cell.SetState(initialConfiguration.GetCellState(cell)); } } //build neighborhoods: foreach (ICell cell in cellularGrid.GetObjects()) { ((ICell)cell).SetNeighbors(GetNeighborhoodStrategy().BuildNeighborhood(cell)); } //return the grid return(cellularGrid); }
/// <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 = new Polygon(newVertices); var grid2d = new Grid2d(path, definition.OrientationGuide); GridCreationRule(grid2d); var cells = grid2d.GetCells().Where(c => !c.IsTrimmed()).SelectMany(c => c.GetTrimmedCellGeometry()).OfType <Polygon>().Where(c => c.Area().ApproximatelyEquals(CellDefinition.CellLength * CellDefinition.CellWidth)); foreach (var element in CellDefinition.Elements) { foreach (var cell in cells) { var transform = new Transform(element.Transform); transform.Concatenate(definition.OrientationGuide); transform.Concatenate(new Transform(cell.Vertices[2])); element.IsElementDefinition = true; var instance = element.CreateInstance(transform, null); arrayElements.Add(instance); } } arrayElements.AddRange(cells.Select(c => new ModelCurve(c))); return(arrayElements); }
/// <summary> /// /// </summary> /// <param name="field"></param> /// <param name="selection"></param> /// <returns></returns> public static Mesh ToPolySoup(this Grid2d field, IEnumerable <int> selection) { var mesh = new Mesh(); var verts = mesh.Vertices; var faces = mesh.Faces; (var dx, var dy) = (field.Scale * 0.5); // add vertices foreach (int index in selection) { var p = field.ToWorldSpace(index); verts.Add(p.X - dx, p.Y - dy, 0.0); verts.Add(p.X + dx, p.Y - dy, 0.0); verts.Add(p.X - dx, p.Y + dy, 0.0); verts.Add(p.X + dx, p.Y + dy, 0.0); } // add faces for (int i = 0; i < verts.Count; i += 4) { faces.AddFace(i, i + 1, i + 3, i + 2); } return(mesh); }
/// <summary> /// The BigBoxParking function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A BigBoxParkingOutputs instance containing computed results and the model with any new elements.</returns> public static BigBoxParkingOutputs Execute(Dictionary <string, Model> inputModels, BigBoxParkingInputs input) { var output = new BigBoxParkingOutputs(253); var lot = new Floor(input.Boundary, 0.7, new Transform(0, 0, 0.8), new Material(Colors.Granite, 0.0, 0.0, System.Guid.NewGuid(), ""), null, false, System.Guid.NewGuid(), null); output.model.AddElement(lot); var grid = new Grid2d(input.Boundary); grid.U.SplitAtOffset(8); grid.U.SplitAtOffset(8, true); var parkingCorridor = grid.GetCellAtIndices(1, 0); parkingCorridor.V.DivideByPattern(new[] { 4, 5.6, 5.6, 4 }); var rowCount = ((int)((double)parkingCorridor.V.Domain.Length / 19.2)); var separators = parkingCorridor.GetCellSeparators(GridDirection.U); for (var i = 2; i < separators.Count - 3; i += 4) { AddLine((Line)separators[i], output.model); } for (var i = 0; i < rowCount * 4; i++) { if (i % 4 == 1 || i % 4 == 2) { AddRow(parkingCorridor.GetCellAtIndices(0, i), output.model); } } return(output); }
public void DisallowedGridEditingThrowsException() { var grid2d = new Grid2d(5, 5); grid2d.V.DivideByCount(5); grid2d.CellsFlat[2].U.DivideByCount(5); Assert.Throws <NotSupportedException>(() => grid2d.U.DivideByCount(2)); }
public Grid2dElement(Grid2d @grid, IList <GridNode> @gridNodes, IList <string> @uGridLines, IList <string> @vGridLines, Transform @transform = null, Material @material = null, Representation @representation = null, bool @isElementDefinition = false, System.Guid @id = default, string @name = null) : base(transform, material, representation, isElementDefinition, id, name) { this.Grid = @grid; this.GridNodes = @gridNodes; this.UGridLines = @uGridLines; this.VGridLines = @vGridLines; }
/// <summary> /// The DataHall function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A DataHallOutputs instance containing computed results and the model with any new elements.</returns> public static DataHallOutputs Execute(Dictionary <string, Model> inputModels, DataHallInputs input) { var spacePlanningZones = inputModels["Space Planning Zones"]; var roomBoundaries = spacePlanningZones.AllElementsOfType <SpaceBoundary>(); var model = new Model(); var dataRack = DataRack.CabinetSiemonV800V82ADataCenterV82A48U; switch (input.CabinetDepth) { case DataHallInputsCabinetDepth._1000mm: switch (input.CabinetHeight) { case DataHallInputsCabinetHeight._42U__2013mm_: dataRack = DataRack.CabinetSiemonV800V81ADataCenterV81A42U; break; case DataHallInputsCabinetHeight._45U__2146mm_: dataRack = DataRack.CabinetSiemonV800V81ADataCenterV81A45U; break; case DataHallInputsCabinetHeight._48U__2280mm_: dataRack = DataRack.CabinetSiemonV800V81ADataCenterV81A48U; break; } break; case DataHallInputsCabinetDepth._1200mm: switch (input.CabinetHeight) { case DataHallInputsCabinetHeight._42U__2013mm_: dataRack = DataRack.CabinetSiemonV800V82ADataCenterV82A42U; break; case DataHallInputsCabinetHeight._45U__2146mm_: dataRack = DataRack.CabinetSiemonV800V82ADataCenterV82A45U; break; case DataHallInputsCabinetHeight._48U__2280mm_: dataRack = DataRack.CabinetSiemonV800V82ADataCenterV82A48U; break; } break; } var width = dataRack.BoundingBox.Max.X - dataRack.BoundingBox.Min.X; var depth = dataRack.BoundingBox.Max.Y - dataRack.BoundingBox.Min.Y; var totalArea = 0.0; foreach (var room in roomBoundaries) { var profile = room.Boundary; totalArea += profile.Area(); //inset from walls var inset = profile.Perimeter.Offset(-1.2); var longestEdge = inset.SelectMany(s => s.Segments()).OrderBy(l => l.Length()).Last(); var alignment = new Transform(Vector3.Origin, longestEdge.Direction(), Vector3.ZAxis); var grid = new Grid2d(inset, alignment); grid.U.DivideByPattern(new[] { ("Forward Rack", depth), ("Hot Aisle", input.HotAisleWidth), ("Backward Rack", depth), ("Cold Aisle", input.ColdAisleWidth) });
/// <summary> /// The ReceptionLayout function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A ReceptionLayoutOutputs instance containing computed results and the model with any new elements.</returns> public static ReceptionLayoutOutputs Execute(Dictionary <string, Model> inputModels, ReceptionLayoutInputs input) { var spacePlanningZones = inputModels["Space Planning Zones"]; var levelsModel = inputModels["Levels"]; var levels = spacePlanningZones.AllElementsOfType <LevelElements>(); var levelVolumes = levelsModel.AllElementsOfType <LevelVolume>(); var output = new ReceptionLayoutOutputs(); var configJson = File.ReadAllText("./ReceptionConfigurations.json"); var configs = JsonConvert.DeserializeObject <SpaceConfiguration>(configJson); var hasCore = inputModels.TryGetValue("Core", out var coresModel); List <Line> coreSegments = new List <Line>(); if (coresModel != null) { coreSegments.AddRange(coresModel.AllElementsOfType <ServiceCore>().SelectMany(c => c.Profile.Perimeter.Segments())); } foreach (var lvl in levels) { var corridors = lvl.Elements.OfType <Floor>(); var corridorSegments = corridors.SelectMany(p => p.Profile.Segments()); var meetingRmBoundaries = lvl.Elements.OfType <SpaceBoundary>().Where(z => z.Name == "Reception"); var levelVolume = levelVolumes.First(l => l.Name == lvl.Name); foreach (var room in meetingRmBoundaries) { var spaceBoundary = room.Boundary; Line orientationGuideEdge = hasCore ? FindEdgeClosestToCore(spaceBoundary.Perimeter, coreSegments) : FindEdgeAdjacentToSegments(spaceBoundary.Perimeter.Segments(), corridorSegments, out var wallCandidates); var orientationTransform = new Transform(Vector3.Origin, orientationGuideEdge.Direction(), Vector3.ZAxis); var boundaryCurves = new List <Polygon>(); boundaryCurves.Add(spaceBoundary.Perimeter); boundaryCurves.AddRange(spaceBoundary.Voids ?? new List <Polygon>()); var grid = new Grid2d(boundaryCurves, orientationTransform); foreach (var cell in grid.GetCells()) { var rect = cell.GetCellGeometry() as Polygon; var segs = rect.Segments(); var width = segs[0].Length(); var depth = segs[1].Length(); var trimmedGeo = cell.GetTrimmedCellGeometry(); if (!cell.IsTrimmed() && trimmedGeo.Count() > 0) { output.Model.AddElement(InstantiateLayout(configs, width, depth, rect, room.Transform)); } else if (trimmedGeo.Count() > 0) { var largestTrimmedShape = trimmedGeo.OfType <Polygon>().OrderBy(s => s.Area()).Last(); var cinchedVertices = rect.Vertices.Select(v => largestTrimmedShape.Vertices.OrderBy(v2 => v2.DistanceTo(v)).First()).ToList(); var cinchedPoly = new Polygon(cinchedVertices); // output.Model.AddElement(new ModelCurve(cinchedPoly, BuiltInMaterials.ZAxis, levelVolume.Transform)); output.Model.AddElement(InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform)); Console.WriteLine("ЪциРђЇРЎѓ№ИЈ funny shape!!!"); } } } } InstancePositionOverrides(input.Overrides, output.Model); return(output); }
/// <summary> /// Get an underlying grid. /// </summary> /// <returns>An underlying grid.</returns> public Grid2d GetGrid() { if (_grid == null) { _grid = BuildGrid(); } return(_grid); }
/// <summary> /// Draws the line instance, Is in screen space as default. Can pass a Grid2D to draw in the Grid Space. /// </summary> /// <param name="grid">Optional, Grid2D to draw relative to. (Start and End are in Grid Space when you do)</param> public void Draw(Grid2d grid = null) { if (grid != null) { grid.DrawLine(this); return; } Glint.AddCommand(this); }
public static void AddRow(Grid2d row, Model model) { row.U.DivideByApproximateLength(2.7, EvenDivisionMode.RoundUp); var spaceSeparators = row.GetCellSeparators(GridDirection.V); foreach (var line in spaceSeparators) { AddLine((Line)line, model); } }
/// <summary> /// Draws the Drawing Object Instance /// </summary> /// <param name="grid">Optional, When a Grid2d is applied, object is drawn relative to the grid and location is in Grid space</param> public virtual void Draw(Grid2d grid = null) { if (Lines.Count != 0) { for (int i = 0; i < Lines.Count; i++) { Lines[i].Draw(grid); } } }
public void Setup() { grid = new Grid2d(new List <string> { "abcde", "fghij", "klmno", "pqrst", "uvwxy" }); }
public void ChildGridUpdatesParent() { var u = new Grid1d(10); var v = new Grid1d(5); var grid2d = new Grid2d(u, v); Assert.Single(grid2d.CellsFlat); grid2d.U.DivideByCount(10); grid2d.V.DivideByCount(5); Assert.Equal(50, grid2d.CellsFlat.Count); }
public void RotationOfTransform() { var rectangle = Polygon.Rectangle(10, 6); var rotation = new Transform(Vector3.Origin, 30); //30 degree rotation var rotatedRectangle = (Polygon)rectangle.Transformed(rotation); var grid = new Grid2d(rotatedRectangle, rotation); grid.U.DivideByCount(20); grid.V.DivideByCount(12); Assert.Equal(0.5, grid[5, 5].U.Domain.Length, 3); Assert.Equal(0.5, grid[5, 5].V.Domain.Length, 3); }
private Grid2d CreateGridFromPolygon(Polygon boundingPolygon) { var boundingPolygonPlane = boundingPolygon.Plane(); var primaryAxisDirection = Transform.XAxis - Transform.XAxis.Dot(boundingPolygonPlane.Normal) * boundingPolygonPlane.Normal; if (primaryAxisDirection.IsZero()) { primaryAxisDirection = Transform.ZAxis - Transform.ZAxis.Dot(boundingPolygonPlane.Normal) * boundingPolygonPlane.Normal; } var grid = new Grid2d(boundingPolygon, new Transform(boundingPolygon.Vertices.FirstOrDefault(), primaryAxisDirection, boundingPolygon.Normal())); return(grid); }
// Utility private static CellComplex MakeASimpleCellComplex( double uCellSize = 10, double vCellSize = 10, double uNumCells = 5, double vNumCells = 5, double cellHeight = 5, double numLevels = 3, Nullable <Vector3> origin = null, Nullable <Vector3> uDirection = null, Nullable <Vector3> vDirection = null, Polygon polygon = null ) { var orig = origin == null ? new Vector3() : (Vector3)origin; var uDir = uDirection == null ? new Vector3(1, 0, 0) : ((Vector3)uDirection).Unitized(); var vDir = vDirection == null ? new Vector3(0, 1, 0) : ((Vector3)vDirection).Unitized(); var uLength = orig.X + uCellSize * uNumCells; var vLength = orig.Y + vCellSize * vNumCells; // Create Grid2d var boundary = polygon == null?Polygon.Rectangle(orig, new Vector3(uLength, vLength)) : polygon; // Using constructor with origin var grid = new Grid2d(boundary, orig, uDir, vDir); for (var u = uCellSize; u < uLength; u += uCellSize) { grid.SplitAtPoint(orig + (uDir * u)); } for (var v = vCellSize; v < vLength; v += vCellSize) { grid.SplitAtPoint(orig + (vDir * v)); } var cellComplex = new CellComplex(Guid.NewGuid(), "Test"); for (var i = 0; i < numLevels; i++) { foreach (var cell in grid.GetCells()) { foreach (var crv in cell.GetTrimmedCellGeometry()) { cellComplex.AddCell((Polygon)crv, 5, cellHeight * i, grid.U, grid.V); } } } return(cellComplex); }
private static IEnumerable <int[]> GetHorizontalPaths(Grid2d grid) { for (int x = 0; x < grid.Width - PathLength + 1; x++) { for (int y = 0; y < grid.Height; y++) { yield return(new int[PathLength] { grid[x, y], grid[x + 1, y], grid[x + 2, y], grid[x + 3, y] }); } } }
private static IEnumerable <int[]> GetVerticalPaths(Grid2d grid) { for (int x = 0; x < grid.Width; x++) { for (int y = 0; y < grid.Height - PathLength + 1; y++) { yield return(new int[PathLength] { grid[x, y], grid[x, y + 1], grid[x, y + 2], grid[x, y + 3] }); } } }
private static IEnumerable <int[]> GetDiagonalNESWPaths(Grid2d grid) { for (int x = 0; x < grid.Width - PathLength + 1; x++) { for (int y = PathLength - 1; y < grid.Height; y++) { yield return(new int[PathLength] { grid[x, y], grid[x + 1, y - 1], grid[x + 2, y - 2], grid[x + 3, y - 3] }); } } }
private HashSet <Edge> AddFromGrid(Grid2d grid, IEnumerable <Edge> edgesToIntersect) { var cells = grid.GetCells(); var addedEdges = new HashSet <Edge>(); var edgeCandidates = new HashSet <(ulong, ulong)>(); Action <Vector3, Vector3> add = (Vector3 start, Vector3 end) => { var v0 = AddVertex(start); var v1 = AddVertex(end); if (v0 != v1) { var pair = v0.Id < v1.Id ? (v0.Id, v1.Id) : (v1.Id, v0.Id); edgeCandidates.Add(pair); }