public void RTreeQuery_RandomPoints() { var bspQueryTime = new Stopwatch(); var checkQueryTime = new Stopwatch(); const int Seeds = 5; const int Repeats = 5; for (int seed = 0; seed < Seeds; ++seed) { int n = 100000; var points = new Point[n]; var rand = new Random(seed); double scale = 1000; for (int i = 0; i < n; ++i) { points[i] = new Point(rand.NextDouble() * scale, rand.NextDouble() * scale); } var queryTree = new RTree<Point>( from p in points select new KeyValuePair<Rectangle, Point>(new Rectangle(p), p)); Assert.AreEqual(queryTree.GetAllLeaves().Count(), n); Assert.AreEqual(queryTree.GetAllIntersecting(new Rectangle(-2, -2, -1, -1)).Count(), 0); Assert.AreEqual(queryTree.GetAllIntersecting(new Rectangle(0, 0, scale, scale)).Count(), n); for (int i = 0; i < Repeats; ++i) { double s = scale / 100; var query = new Rectangle(rand.NextDouble() * s, rand.NextDouble() * s, rand.NextDouble() * s, rand.NextDouble() * s); bspQueryTime.Start(); var result = queryTree.GetAllIntersecting(query).ToList(); bspQueryTime.Stop(); checkQueryTime.Start(); var checkList = (from p in points where query.Contains(p) select p).ToList(); checkQueryTime.Stop(); var checkSet = new HashSet<Point>(checkList); Assert.AreEqual(result.Count, checkList.Count); foreach (var r in result) { Assert.IsTrue(query.Contains(r)); Assert.IsTrue(checkSet.Contains(r)); } } Assert.IsTrue(bspQueryTime.ElapsedMilliseconds < checkQueryTime.ElapsedMilliseconds); } }
static bool CurveOverlapsBox(ICurve curve, ref Rectangle box, Polyline boxPolyline) { // if the curve bounding box doesn't intersect the invalidated region then no overlap! if (!box.Intersects(curve.BoundingBox)) { return false; } // if either end of the curve is inside the box then there is definitely overlap! if (box.Contains(curve.Start) || box.Contains(curve.End)) { return true; } // we have already determined that the curve is close but not fully contained so now we // need to check for a more expensive intersection return Curve.CurveCurveIntersectionOne(boxPolyline, curve, false) != null; }
static void DebugVerifyRectContains(Rectangle rectOuter, Rectangle rectInner, double dblPaddingX, double dblPaddingY, double dblEpsilon) { rectInner.PadWidth(dblPaddingX/2.0 - dblEpsilon); rectInner.PadHeight(dblPaddingY/2.0 - dblEpsilon); Debug.Assert(rectOuter.Contains(rectInner) , "Inner Node/Cluster rectangle is not contained within outer Cluster" ); }
private static bool FirstRectangleContainsACornerOfTheOther(Rectangle a, Rectangle b) { return a.Contains(b.LeftBottom) || a.Contains(b.LeftTop) || a.Contains(b.RightTop) || a.Contains(b.RightBottom); }