private static void SubdividePoint( XYPointMultiType point, PointRegionQuadTreeNodeBranch branch, PointRegionQuadTree<object> tree, bool unique, string indexName) { var x = point.X; var y = point.Y; var quadrant = branch.Bb.GetQuadrant(x, y); switch (quadrant) { case QuadrantEnum.NW: branch.Nw = AddToNode(x, y, point, branch.Nw, tree, unique, indexName); break; case QuadrantEnum.NE: branch.Ne = AddToNode(x, y, point, branch.Ne, tree, unique, indexName); break; case QuadrantEnum.SW: branch.Sw = AddToNode(x, y, point, branch.Sw, tree, unique, indexName); break; default: branch.Se = AddToNode(x, y, point, branch.Se, tree, unique, indexName); break; } }
private static void AddToBranch( PointRegionQuadTreeNodeBranch branch, double x, double y, TL value, PointRegionQuadTree<object> tree) { switch (branch.Bb.GetQuadrant(x, y)) { case QuadrantEnum.NW: branch.Nw = SetOnNode(x, y, value, branch.Nw, tree); break; case QuadrantEnum.NE: branch.Ne = SetOnNode(x, y, value, branch.Ne, tree); break; case QuadrantEnum.SW: branch.Sw = SetOnNode(x, y, value, branch.Sw, tree); break; default: branch.Se = SetOnNode(x, y, value, branch.Se, tree); break; } }
private static PointRegionQuadTreeNode Subdivide( PointRegionQuadTreeNodeLeaf<object> leaf, PointRegionQuadTree<object> tree, bool unique, string indexName) { var w = (leaf.Bb.MaxX - leaf.Bb.MinX) / 2d; var h = (leaf.Bb.MaxY - leaf.Bb.MinY) / 2d; var minx = leaf.Bb.MinX; var miny = leaf.Bb.MinY; var bbNW = new BoundingBox(minx, miny, minx + w, miny + h); var bbNE = new BoundingBox(minx + w, miny, leaf.Bb.MaxX, miny + h); var bbSW = new BoundingBox(minx, miny + h, minx + w, leaf.Bb.MaxY); var bbSE = new BoundingBox(minx + w, miny + h, leaf.Bb.MaxX, leaf.Bb.MaxY); var nw = new PointRegionQuadTreeNodeLeaf<object>(bbNW, leaf.Level + 1, null, 0); var ne = new PointRegionQuadTreeNodeLeaf<object>(bbNE, leaf.Level + 1, null, 0); var sw = new PointRegionQuadTreeNodeLeaf<object>(bbSW, leaf.Level + 1, null, 0); var se = new PointRegionQuadTreeNodeLeaf<object>(bbSE, leaf.Level + 1, null, 0); var branch = new PointRegionQuadTreeNodeBranch(leaf.Bb, leaf.Level, nw, ne, sw, se); var points = leaf.Points; if (points is XYPointMultiType) { var point = (XYPointMultiType) points; SubdividePoint(point, branch, tree, unique, indexName); } else { foreach (var point in (ICollection<XYPointMultiType>) points) { SubdividePoint(point, branch, tree, unique, indexName); } } return branch; }
private static void AddToBranch( PointRegionQuadTreeNodeBranch branch, double x, double y, object value, PointRegionQuadTree <object> tree, bool unique, string indexName) { var quadrant = branch.Bb.GetQuadrant(x, y); if (quadrant == QuadrantEnum.NW) { branch.Nw = AddToNode(x, y, value, branch.Nw, tree, unique, indexName); } else if (quadrant == QuadrantEnum.NE) { branch.Ne = AddToNode(x, y, value, branch.Ne, tree, unique, indexName); } else if (quadrant == QuadrantEnum.SW) { branch.Sw = AddToNode(x, y, value, branch.Sw, tree, unique, indexName); } else { branch.Se = AddToNode(x, y, value, branch.Se, tree, unique, indexName); } }
private static void SubdividePoint( XYPointWValue <TL> point, PointRegionQuadTreeNodeBranch branch, PointRegionQuadTree <object> tree) { var x = point.X; var y = point.Y; switch (branch.Bb.GetQuadrant(x, y)) { case QuadrantEnum.NW: branch.Nw = SetOnNode(x, y, point, branch.Nw, tree); break; case QuadrantEnum.NE: branch.Ne = SetOnNode(x, y, point, branch.Ne, tree); break; case QuadrantEnum.SW: branch.Sw = SetOnNode(x, y, point, branch.Sw, tree); break; default: branch.Se = SetOnNode(x, y, point, branch.Se, tree); break; } }
public void TestSubdivideMultiChild() { PointRegionQuadTree <object> tree = PointRegionQuadTreeFactory <object> .Make(0, 0, 100, 100, 4, 3); Set(tree, 60, 11, "P1"); Set(tree, 60, 40, "P2"); Set(tree, 70, 30, "P3"); Set(tree, 60, 10, "P4"); Set(tree, 90, 45, "P5"); NavigateLeaf(tree, "nw"); NavigateLeaf(tree, "se"); NavigateLeaf(tree, "sw"); PointRegionQuadTreeNodeBranch ne = NavigateBranch(tree, "ne"); Assert.AreEqual(2, ne.Level); PointRegionQuadTreeNodeLeaf <object> nw = NavigateLeaf(ne, "nw"); IList <XYPointWValue <object> > collection = (IList <XYPointWValue <object> >)nw.Points; Compare(60, 11, "P1", collection[0]); Compare(60, 10, "P4", collection[1]); Assert.AreEqual(2, nw.Count); PointRegionQuadTreeNodeLeaf <object> se = NavigateLeaf(ne, "se"); Compare(90, 45, "P5", (XYPointWValue <object>)se.Points); Assert.AreEqual(1, se.Count); PointRegionQuadTreeNodeLeaf <object> sw = NavigateLeaf(ne, "sw"); collection = (IList <XYPointWValue <object> >)sw.Points; Compare(60, 40, "P2", collection[0]); Compare(70, 30, "P3", collection[1]); Assert.AreEqual(2, sw.Count); Delete(tree, 60, 11); Delete(tree, 60, 40); PointRegionQuadTreeNodeLeaf <object> root = NavigateLeaf(tree, ""); collection = (IList <XYPointWValue <object> >)root.Points; Assert.AreEqual(3, root.Count); Assert.AreEqual(3, collection.Count); Compare(60, 10, "P4", collection[0]); Compare(70, 30, "P3", collection[1]); Compare(90, 45, "P5", collection[2]); }
public void TestSubdivideMultiChild() { PointRegionQuadTree <object> tree = PointRegionQuadTreeFactory <object> .Make(0, 0, 100, 100, 4, 3); AddNonUnique(tree, 60, 10, "P1"); AddNonUnique(tree, 60, 40, "P2"); AddNonUnique(tree, 70, 30, "P3"); AddNonUnique(tree, 60, 10, "P4"); AddNonUnique(tree, 90, 45, "P5"); NavigateLeaf(tree, "nw"); NavigateLeaf(tree, "se"); NavigateLeaf(tree, "sw"); PointRegionQuadTreeNodeBranch ne = NavigateBranch(tree, "ne"); Assert.AreEqual(2, ne.Level); PointRegionQuadTreeNodeLeaf <object> nw = NavigateLeaf(ne, "nw"); Compare(60, 10, "[\"P1\", \"P4\"]", (XYPointMultiType)nw.Points); Assert.AreEqual(2, nw.Count); PointRegionQuadTreeNodeLeaf <object> se = NavigateLeaf(ne, "se"); Compare(90, 45, "\"P5\"", (XYPointMultiType)se.Points); Assert.AreEqual(1, se.Count); PointRegionQuadTreeNodeLeaf <object> sw = NavigateLeaf(ne, "sw"); var collection = AssertPointCollection(sw); Compare(60, 40, "\"P2\"", collection[0]); Compare(70, 30, "\"P3\"", collection[1]); Assert.AreEqual(2, sw.Count); Remove(tree, 60, 10, "P1"); Remove(tree, 60, 40, "P2"); PointRegionQuadTreeNodeLeaf <object> root = NavigateLeaf(tree, ""); collection = AssertPointCollection(root); Assert.AreEqual(3, root.Count); Assert.AreEqual(3, collection.Length); Compare(60, 10, "[\"P4\"]", collection[0]); Compare(70, 30, "\"P3\"", collection[1]); Compare(90, 45, "\"P5\"", collection[2]); }
private static void AddToBranch( PointRegionQuadTreeNodeBranch branch, double x, double y, XYPointWValue<TL> value, PointRegionQuadTree<object> tree) { var quadrant = branch.Bb.GetQuadrant(x, y); if (quadrant == QuadrantEnum.NW) { branch.Nw = SetOnNode(x, y, value, branch.Nw, tree); } else if (quadrant == QuadrantEnum.NE) { branch.Ne = SetOnNode(x, y, value, branch.Ne, tree); } else if (quadrant == QuadrantEnum.SW) { branch.Sw = SetOnNode(x, y, value, branch.Sw, tree); } else { branch.Se = SetOnNode(x, y, value, branch.Se, tree); } }
private static void SubdividePoint( XYPointWValue<TL> point, PointRegionQuadTreeNodeBranch branch, PointRegionQuadTree<object> tree) { var x = point.X; var y = point.Y; var quadrant = branch.Bb.GetQuadrant(x, y); if (quadrant == QuadrantEnum.NW) { branch.Nw = SetOnNode(x, y, point, branch.Nw, tree); } else if (quadrant == QuadrantEnum.NE) { branch.Ne = SetOnNode(x, y, point, branch.Ne, tree); } else if (quadrant == QuadrantEnum.SW) { branch.Sw = SetOnNode(x, y, point, branch.Sw, tree); } else { branch.Se = SetOnNode(x, y, point, branch.Se, tree); } }
private static void CollectRange( PointRegionQuadTreeNode node, double x, double y, double width, double height, EventBean eventBean, TT target, QuadTreeCollector<TL, TT> collector) { if (!node.Bb.IntersectsBoxIncludingEnd(x, y, width, height)) return; if (node is PointRegionQuadTreeNodeLeaf<object> leaf) { CollectLeaf(leaf, x, y, width, height, eventBean, target, collector); return; } PointRegionQuadTreeNodeBranch branch = (PointRegionQuadTreeNodeBranch) node; CollectRange(branch.Nw, x, y, width, height, eventBean, target, collector); CollectRange(branch.Ne, x, y, width, height, eventBean, target, collector); CollectRange(branch.Sw, x, y, width, height, eventBean, target, collector); CollectRange(branch.Se, x, y, width, height, eventBean, target, collector); }