private static Boolean HasEnoughArea(PartitionParam paramOutput, double targetArea) { double outputArea = PolylineTools.GetArea(paramOutput.Outline); if (outputArea > targetArea) { return(true); } return(false); }
// private int AreaFitnessComparer(PartitionParam outputA, PartitionParam outputB, double targetArea) { //setting double aArea = PolylineTools.GetArea(outputA.Outline); double bArea = PolylineTools.GetArea(outputB.Outline); double aLength = outputA.PartitionPost.GetLength(); double bLength = outputB.PartitionPost.GetLength(); double aCost = ComputeCost(aArea, targetArea); double bCost = ComputeCost(bArea, targetArea); //decider bool isACostLarger = aCost > bCost; //compare if (isACostLarger) { if (bCost / aCost > areaInitiative) { if (aLength < bLength) { return(-1); } } return(1); } else { if (aCost / bCost > areaInitiative) { if (bLength < aLength) { return(1); } } return(-1); } }
private static List <LabeledOutline> DistributeLabel(List <Polyline> difference, List <Polyline> outlinePure, List <List <RoomLine> > coreLabeled, Polyline coreUnion) { List <LabeledOutline> distributedLabels = new List <LabeledOutline>(); if (outlinePure.Count == 1 && outlinePure.First().IsClosed) { LabeledOutline nonSeperatedLabel = new LabeledOutline(difference.First(), outlinePure.First(), coreLabeled.First()); nonSeperatedLabel.DifferenceArea = PolylineTools.GetArea(difference.First()) - PolylineTools.GetArea(coreUnion); distributedLabels.Add(nonSeperatedLabel); return(distributedLabels); } int seperatedCount = difference.Count; for (int i = 0; i < seperatedCount; i++) { LabeledOutline seperatedLabel = new LabeledOutline(difference[i], outlinePure[i], coreLabeled[i]); seperatedLabel.DifferenceArea = PolylineTools.GetArea(difference[i]); distributedLabels.Add(seperatedLabel); } return(distributedLabels); }
//comparer method private List <PartitionParam> SieveByFillingRate(List <PartitionParam> unseived, Plane cornerBasis) { List <PartitionParam> fillingSeived = new List <PartitionParam>(); foreach (PartitionParam i in unseived) { List <double> tempBoundingLength = GetBoundingLength(i.Outline, cornerBasis); double tempPolyArea = PolylineTools.GetArea(i.Outline); double tempFillingRatio = tempPolyArea / (tempBoundingLength[0] * tempBoundingLength[1]); if (tempFillingRatio > fillingTolerance) { fillingSeived.Add(i); } } if (fillingSeived.Count == 0) { return(unseived); } return(fillingSeived); }
//중복코드 나중에 지워보자.. private static PartitionParam DrawAtNoFoldOutline(PartitionParam param, double targetArea, List <Point3d> outlineVertex) { Line mainLine = GetMainLine(param, outlineVertex); Vector3d mainAlign = mainLine.UnitTangent; Vector3d mainPerp = VectorTools.RotateVectorXY(mainAlign, Math.PI / 2); Point3d origin = param.OriginPost.Point; double dotProduct = Vector3d.Multiply(mainAlign, param.OriginPost.BaseLine.UnitNormal); double dotTolerance = 0.005; bool isMainDirecPreDiv = false; if (Math.Abs(dotProduct) < dotTolerance) { int originIndex = param.OutlineLabel.Core.FindIndex (i => i.PureLine == param.OriginPost.BasePureLine); param.OriginPost = new PartitionOrigin(origin, param.OutlineLabel.Core[originIndex - 1]); mainPerp = VectorTools.RotateVectorXY(mainAlign, -Math.PI / 2); isMainDirecPreDiv = true; } int iterNum = 10; int breaker = 0; double lowerBound = 0; double upperBound = mainLine.Length; Polyline polyOutput = new Polyline(); while (lowerBound < upperBound) { if (breaker > iterNum) { break; } double tempStatus = (upperBound - lowerBound) / 2 + lowerBound; Point3d tempAnchor = origin + mainAlign * tempStatus; if (isMainDirecPreDiv) { tempAnchor = origin + mainAlign * (mainLine.Length - tempStatus); } List <RoomLine> cornerPartitions = new List <RoomLine>(); cornerPartitions.Add(new RoomLine(new Line(origin, tempAnchor), LineType.Inner)); Line anchorToOutline = PCXTools.PCXByEquation(tempAnchor, param.OutlineLabel.Pure, mainPerp); cornerPartitions.Add(new RoomLine(anchorToOutline, LineType.Inner)); Partition tempPartition = new Partition(cornerPartitions, param.OriginPost); param.PartitionPost = tempPartition; double tempArea = PolylineTools.GetArea(param.Outline); if (targetArea > tempArea) { lowerBound = tempStatus; } else if (targetArea < tempArea) { upperBound = tempStatus; } else { lowerBound = tempArea; upperBound = tempArea; } breaker++; } return(param); }