public static void GetBuildingLayout(List <BuildingUnit> unitList, BuildingUnitMix desiredUnitMix, Line2D mainCorridor, Line2D leftLeg, Line2D middleLeg, Line2D rightLeg, double unitDepth, double hallWidth, out List <Polygon2D> polyUnits, out List <string> unitNames, out List <Line2D> shearWallLines, out List <Line2D> lineList, out MainCorridor mainCorridorOutput) { var corridors = new List <Corridor>(); var mainCorridorObject = new MainCorridor(); var location = CorridorLocation.Main; var corridorLineList = new List <UnitsLine>(); var leftLegObject = new Corridor(); if (leftLeg.Length > unitDepth + hallWidth / 2) { var leftLine2D = CreateLine2D(leftLeg); location = CorridorLocation.LeftLeg; leftLegObject = new Corridor(leftLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(leftLegObject.GetLines()); } var midLegObject = new Corridor(); if (middleLeg.Length > unitDepth + hallWidth / 2) { var midLine2D = CreateLine2D(middleLeg); location = CorridorLocation.MiddleLeg; midLegObject = new Corridor(midLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(midLegObject.GetLines()); } var rightLegObject = new Corridor(); if (rightLeg.Length > unitDepth + hallWidth / 2) { var rightLine2D = CreateLine2D(rightLeg); location = CorridorLocation.RightLeg; rightLegObject = new Corridor(rightLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(rightLegObject.GetLines()); } var mainLine2D = CreateLine2D(mainCorridor); location = CorridorLocation.Main; mainCorridorObject.CenterLine = mainLine2D; mainCorridorObject.UnitDepth = unitDepth; mainCorridorObject.HallWidth = hallWidth; mainCorridorObject.CorridorLocation = location; mainCorridorObject.LeftLeg = leftLegObject; mainCorridorObject.MiddleLeg = midLegObject; mainCorridorObject.RightLeg = rightLegObject; mainCorridorObject.CalculateMainLines(); var currentPercentage = new BuildingUnitMix(); foreach (var kvp in desiredUnitMix) { currentPercentage.Add(kvp.Key, 0); } corridorLineList.AddRange(mainCorridorObject.GetLines()); corridorLineList.OrderBy(x => x.Line.Length); double usedLength = 0; var unitPriority = new List <string>() { "C", "B", "A", "S" }; var totalUnitList = new List <Tuple <string, double> >(); polyUnits = new List <Polygon2D>(); unitNames = new List <string>(); shearWallLines = new List <Line2D>(); foreach (var corridorLine in corridorLineList) { var corridorLength = corridorLine.Line.Length; var units = FittingAlgorithm.CreateUnitLine(unitList, desiredUnitMix, corridorLength, ref currentPercentage, unitPriority, ref totalUnitList, ref usedLength); var buildingUnits = new List <BuildingUnit>(); double startLength = 0; var lineVector = corridorLine.Line.Direction; var angle = new Vector2D(1, 0).SignedAngleTo(lineVector); foreach (var unit in units) { var matchingUnit = unitList.Single(x => (x.Type == unit.Item1 && x.Width == unit.Item2)); matchingUnit.Rotation = angle; matchingUnit.Location = corridorLine.Line.StartPoint + startLength * lineVector; var unitPolygon = matchingUnit.GetPolygon(); var unitWallLines = matchingUnit.GetShearWallLines(); foreach (var unitLine in unitWallLines) { shearWallLines.Add(new Line2D(new Point2D(unitLine.StartPoint.X, unitLine.StartPoint.Y), new Point2D(unitLine.EndPoint.X, unitLine.EndPoint.Y))); } var unitPoints = unitPolygon.ToPolyLine2D().Vertices; var unitPolyline = new Polygon2D(unitPoints); polyUnits.Add(unitPolyline); unitNames.Add(matchingUnit.Type); buildingUnits.Add(matchingUnit); startLength += matchingUnit.Width; } corridorLine.BuildingUnits = buildingUnits; } lineList = new List <Line2D>(); foreach (var corridorLine in corridorLineList) { lineList.Add(new Line2D(new Point2D(corridorLine.Line.StartPoint.X, corridorLine.Line.StartPoint.Y), new Point2D(corridorLine.Line.EndPoint.X, corridorLine.Line.EndPoint.Y))); } mainCorridorOutput = mainCorridorObject; }
public static List <Point2D> GetOutlinePoints(double unitDepth, double hallWidth, MainCorridor mainCorridorObject) { var finalPoints = new List <Point2D>() { }; var corridorWidth = unitDepth * 2 + hallWidth; var moveVectorY = corridorWidth / 2 * new Vector2D(0, 1); var moveVectorX = corridorWidth / 2 * new Vector2D(1, 0); var main1 = mainCorridorObject.CenterLine - moveVectorY; var main2 = mainCorridorObject.CenterLine + moveVectorY; finalPoints.Add(main1.EndPoint); finalPoints.Add(main1.StartPoint); if (mainCorridorObject.LeftLeg.CenterLine.Length > 0.001) { var left1 = mainCorridorObject.LeftLeg.CenterLine - moveVectorX; var left2 = mainCorridorObject.LeftLeg.CenterLine + moveVectorX; finalPoints.Add(left1.EndPoint); finalPoints.Add(left2.EndPoint); finalPoints.Add(left2.StartPoint + moveVectorY); } else { finalPoints.Add(main2.StartPoint); } if (mainCorridorObject.MiddleLeg.CenterLine.Length > 0.001) { var mid1 = mainCorridorObject.MiddleLeg.CenterLine - moveVectorX; var mid2 = mainCorridorObject.MiddleLeg.CenterLine + moveVectorX; finalPoints.Add(mid1.StartPoint + moveVectorY); finalPoints.Add(mid1.EndPoint); finalPoints.Add(mid2.EndPoint); finalPoints.Add(mid2.StartPoint + moveVectorY); } else { } if (mainCorridorObject.RightLeg.CenterLine.Length > 0.001) { var right1 = mainCorridorObject.RightLeg.CenterLine - moveVectorX; var right2 = mainCorridorObject.RightLeg.CenterLine + moveVectorX; finalPoints.Add(right1.StartPoint + moveVectorY); finalPoints.Add(right1.EndPoint); finalPoints.Add(right2.EndPoint); } else { finalPoints.Add(main2.EndPoint); } finalPoints.Add(main1.EndPoint); return(finalPoints); }