/// <summary> /// Picks the next best box to add to one of the given nodes. /// </summary> /// <param name="nodeBoxes"></param> /// <param name="boxes"></param> /// <param name="nodeBoxIndex"></param> /// <returns></returns> protected static int PickNext(BoxF2D[] nodeBoxes, IList <BoxF2D> boxes, out int nodeBoxIndex) { double difference = double.MinValue; nodeBoxIndex = 0; int pickedIdx = -1; for (int idx = 0; idx < boxes.Count; idx++) { BoxF2D item = boxes[idx]; double d1 = item.Union(nodeBoxes[0]).Surface - item.Surface; double d2 = item.Union(nodeBoxes[1]).Surface - item.Surface; double localDifference = System.Math.Abs(d1 - d2); if (difference < localDifference) { difference = localDifference; if (d1 == d2) { nodeBoxIndex = (nodeBoxes[0].Surface < nodeBoxes[1].Surface) ? 0 : 1; } else { nodeBoxIndex = (d1 < d2) ? 0 : 1; } pickedIdx = idx; } } return(pickedIdx); }
public void BoxF2DUnionTest() { var testDataList = new List <BoxF2D>(); for (int idx = 0; idx < 10000; idx++) { double x1 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0); double x2 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0); double y1 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0); double y2 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0); testDataList.Add(new BoxF2D(x1, y1, x2, y2)); } BoxF2D box = testDataList[0]; foreach (BoxF2D rectangleF2D in testDataList) { box = box.Union(rectangleF2D); } foreach (BoxF2D rectangleF2D in testDataList) { box.IsInside(rectangleF2D); } }
/// <summary> /// Returns the bounding box for this node. /// </summary> /// <returns></returns> public BoxF2D GetBox() { BoxF2D box = this.Boxes[0]; for (int idx = 1; idx < this.Boxes.Count; idx++) { box = box.Union(this.Boxes[idx]); } return(box); }
public BoxF2D GetBox() { BoxF2D boxF2D = this.Boxes[0]; for (int index = 1; index < this.Boxes.Count; ++index) { boxF2D = boxF2D.Union(this.Boxes[index]); } return(boxF2D); }
protected static int PickNext(BoxF2D[] nodeBoxes, IList <BoxF2D> boxes, out int nodeBoxIndex) { double num1 = double.MinValue; nodeBoxIndex = 0; int num2 = -1; for (int index = 0; index < boxes.Count; ++index) { BoxF2D box = boxes[index]; double num3 = box.Union(nodeBoxes[0]).Surface - box.Surface; double num4 = box.Union(nodeBoxes[1]).Surface - box.Surface; double num5 = System.Math.Abs(num3 - num4); if (num1 < num5) { num1 = num5; nodeBoxIndex = num3 != num4 ? (num3 < num4 ? 0 : 1) : (nodeBoxes[0].Surface < nodeBoxes[1].Surface ? 0 : 1); num2 = index; } } return(num2); }