private void RemoveAbnormalBlocks() { List <int> removableIndexes = new List <int>(); foreach (Block block in ThinnedBlocks) { if (block.Nodes.Count > 10) { removableIndexes.Add(ThinnedBlocks.IndexOf(block)); continue; } var boundingRect = BoundingService.GetMinBoundingRectangle(block); if (boundingRect.GetArea() < 10f) { removableIndexes.Add(ThinnedBlocks.IndexOf(block)); } } for (int i = ThinnedBlocks.Count - 1; i > -1; i--) { if (removableIndexes.Contains(i)) { ThinnedBlocks.RemoveAt(i); } } }
private bool ValidBlock(Block block) { //Here we need to check if the newly created block is valid //Check if the size is not too small if (BoundingService.GetMinBoundingRectangle(block).GetArea() < 10f) { return(false); } //Check if the aspect ratio is valid //Check etc. // ... return(true); }
/** * BlOCK THINNING */ private Block GetTinnedBlock(Block baseBlock, float sideWalkThickness) { var blockDelegate1 = new Block(); var blockDelegate2 = new Block(); for (int i = 0; i < baseBlock.Nodes.Count; i++) { var currentNode = baseBlock.Nodes[i].GetNodeForm(); var nextNode = (i == baseBlock.Nodes.Count - 1) ? baseBlock.Nodes[0].GetNodeForm() : baseBlock.Nodes[i + 1].GetNodeForm(); var lastNode = (i == 0) ? baseBlock.Nodes[baseBlock.Nodes.Count - 1].GetNodeForm() : baseBlock.Nodes[i - 1].GetNodeForm(); var currentEdge = new Edge(currentNode, nextNode); var lastEdge = new Edge(lastNode, currentNode); currentNode.Edges.Clear(); currentNode.Edges.Add(lastEdge); currentNode.Edges.Add(currentEdge); var newBlockNodes = GetTwoEdgedThickenedNodes(currentNode, sideWalkThickness); var newBlockNode1 = newBlockNodes[0]; var newBlockNode2 = newBlockNodes[1]; if (Orientation(currentEdge, newBlockNode1) > 0) { blockDelegate1.Nodes.Add(newBlockNode1); blockDelegate2.Nodes.Add(newBlockNode2); } else { blockDelegate2.Nodes.Add(newBlockNode1); blockDelegate1.Nodes.Add(newBlockNode2); } } var boundingRect1 = BoundingService.GetMinBoundingRectangle(blockDelegate1); var boundingRect2 = BoundingService.GetMinBoundingRectangle(blockDelegate2); return(boundingRect1.GetArea() > boundingRect2.GetArea() ? blockDelegate2 : blockDelegate1); }
private List <Block> DivideBlock(Block block, int iteration) { if (iteration > 6) { return(new List <Block> { block }); } else if (block.Nodes.Count > 10) { return(new List <Block> { block }); } var minBoundingRect = BoundingService.GetMinBoundingRectangle(block); BoundingRectangles.Add(minBoundingRect); var cuttingLine = minBoundingRect.GetCutLine(rand); List <Block> newLots = SliceBlock(cuttingLine, block); //If the division is valid, try to divide even more, continue recursion if (newLots.Count > 1 && newLots.TrueForAll(ValidBlock)) { var lots = new List <Block>(); foreach (var newLot in newLots) { lots.AddRange(DivideBlock(newLot, iteration + 1)); } return(lots); } //Else don't accept the division, return only the block, ends the recursion return(new List <Block> { block }); }