private static void Subdivide( XYWHRectangleWValue rectangle, MXCIFQuadTreeNodeBranch branch, MXCIFQuadTree tree) { var x = rectangle.X; var y = rectangle.Y; var w = rectangle.W; var h = rectangle.H; var quadrant = branch.Bb.GetQuadrantApplies(x, y, w, h); if (quadrant == QuadrantAppliesEnum.NW) { branch.Nw = SetOnNodeWithRect(x, y, w, h, rectangle, branch.Nw, tree); } else if (quadrant == QuadrantAppliesEnum.NE) { branch.Ne = SetOnNodeWithRect(x, y, w, h, rectangle, branch.Ne, tree); } else if (quadrant == QuadrantAppliesEnum.SW) { branch.Sw = SetOnNodeWithRect(x, y, w, h, rectangle, branch.Sw, tree); } else if (quadrant == QuadrantAppliesEnum.SE) { branch.Se = SetOnNodeWithRect(x, y, w, h, rectangle, branch.Se, tree); } else if (quadrant == QuadrantAppliesEnum.SOME) { var numAdded = SetOnNodeWithRect(branch, x, y, w, h, rectangle); branch.IncCount(numAdded); } else { throw new IllegalStateException("No intersection"); } }
private static void AddToBranchWithRect( MXCIFQuadTreeNodeBranch branch, double x, double y, double width, double height, XYWHRectangleWValue value, MXCIFQuadTree tree) { switch (branch.Bb.GetQuadrantApplies(x, y, width, height)) { case QuadrantAppliesEnum.NW: branch.Nw = SetOnNodeWithRect(x, y, width, height, value, branch.Nw, tree); break; case QuadrantAppliesEnum.NE: branch.Ne = SetOnNodeWithRect(x, y, width, height, value, branch.Ne, tree); break; case QuadrantAppliesEnum.SW: branch.Sw = SetOnNodeWithRect(x, y, width, height, value, branch.Sw, tree); break; case QuadrantAppliesEnum.SE: branch.Se = SetOnNodeWithRect(x, y, width, height, value, branch.Se, tree); break; case QuadrantAppliesEnum.SOME: var count = SetOnNodeWithRect(branch, x, y, width, height, value); branch.IncCount(count); break; default: throw new IllegalStateException("Quadrant not applies to any"); } }
private static MXCIFQuadTreeNode Subdivide( MXCIFQuadTreeNodeLeaf leaf, MXCIFQuadTree tree) { 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 MXCIFQuadTreeNodeLeaf(bbNW, leaf.Level + 1, null, 0); var ne = new MXCIFQuadTreeNodeLeaf(bbNE, leaf.Level + 1, null, 0); var sw = new MXCIFQuadTreeNodeLeaf(bbSW, leaf.Level + 1, null, 0); var se = new MXCIFQuadTreeNodeLeaf(bbSE, leaf.Level + 1, null, 0); var branch = new MXCIFQuadTreeNodeBranch(leaf.Bb, leaf.Level, null, 0, nw, ne, sw, se); var rectangles = leaf.Data; if (rectangles is XYWHRectangleWValue asRectangle) { Subdivide(asRectangle, branch, tree); } else { var collection = (ICollection<XYWHRectangleWValue>) rectangles; foreach (var rectangle in collection) { Subdivide(rectangle, branch, tree); } } return branch; }
private static void AddToBranch( MXCIFQuadTreeNodeBranch branch, double x, double y, double width, double height, object value, MXCIFQuadTree tree, bool unique, string indexName) { var quadrant = branch.Bb.GetQuadrantApplies(x, y, width, height); if (quadrant == QuadrantAppliesEnum.NW) { branch.Nw = AddToNode(x, y, width, height, value, branch.Nw, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.NE) { branch.Ne = AddToNode(x, y, width, height, value, branch.Ne, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SW) { branch.Sw = AddToNode(x, y, width, height, value, branch.Sw, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SE) { branch.Se = AddToNode(x, y, width, height, value, branch.Se, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SOME) { var numAdded = AddToData(branch, x, y, width, height, value, unique, indexName); branch.IncCount(numAdded); } else { throw new IllegalStateException("Applies to none"); } }
private static void Subdivide( XYWHRectangleMultiType rectangle, MXCIFQuadTreeNodeBranch branch, MXCIFQuadTree tree, bool unique, string indexName) { var x = rectangle.X; var y = rectangle.Y; var w = rectangle.W; var h = rectangle.H; var quadrant = branch.Bb.GetQuadrantApplies(x, y, w, h); if (quadrant == QuadrantAppliesEnum.NW) { branch.Nw = AddToNode(x, y, w, h, rectangle, branch.Nw, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.NE) { branch.Ne = AddToNode(x, y, w, h, rectangle, branch.Ne, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SW) { branch.Sw = AddToNode(x, y, w, h, rectangle, branch.Sw, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SE) { branch.Se = AddToNode(x, y, w, h, rectangle, branch.Se, tree, unique, indexName); } else if (quadrant == QuadrantAppliesEnum.SOME) { var numAdded = AddToData(branch, x, y, w, h, rectangle, unique, indexName); branch.IncCount(numAdded); } else { throw new IllegalStateException("No intersection"); } }
private static MXCIFQuadTreeNode Subdivide( MXCIFQuadTreeNodeLeaf leaf, MXCIFQuadTree 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); MXCIFQuadTreeNode nw = new MXCIFQuadTreeNodeLeaf(bbNW, leaf.Level + 1, null, 0); MXCIFQuadTreeNode ne = new MXCIFQuadTreeNodeLeaf(bbNE, leaf.Level + 1, null, 0); MXCIFQuadTreeNode sw = new MXCIFQuadTreeNodeLeaf(bbSW, leaf.Level + 1, null, 0); MXCIFQuadTreeNode se = new MXCIFQuadTreeNodeLeaf(bbSE, leaf.Level + 1, null, 0); var branch = new MXCIFQuadTreeNodeBranch(leaf.Bb, leaf.Level, null, 0, nw, ne, sw, se); var data = leaf.Data; if (data is XYWHRectangleMultiType) { var rectangle = (XYWHRectangleMultiType) data; Subdivide(rectangle, branch, tree, unique, indexName); } else { var collection = (ICollection<XYWHRectangleMultiType>) data; foreach (var rectangle in collection) { Subdivide(rectangle, branch, tree, unique, indexName); } } return branch; }
public static void Traverse( MXCIFQuadTreeNode node, Consumer<object> consumer) { if (node is MXCIFQuadTreeNodeLeaf) { MXCIFQuadTreeNodeLeaf leaf = (MXCIFQuadTreeNodeLeaf) node; TraverseData(leaf.Data, consumer); return; } MXCIFQuadTreeNodeBranch branch = (MXCIFQuadTreeNodeBranch) node; TraverseData(branch.Data, consumer); Traverse(branch.Nw, consumer); Traverse(branch.Ne, consumer); Traverse(branch.Sw, consumer); Traverse(branch.Se, consumer); }
private static void Subdivide( XYWHRectangleMultiType rectangle, MXCIFQuadTreeNodeBranch <object> branch, MXCIFQuadTree <object> tree, bool unique, string indexName) { var x = rectangle.X; var y = rectangle.Y; var w = rectangle.W; var h = rectangle.H; var quadrant = branch.Bb.GetQuadrantApplies(x, y, w, h); switch (quadrant) { case QuadrantAppliesEnum.NW: branch.Nw = AddToNode(x, y, w, h, rectangle, branch.Nw, tree, unique, indexName); break; case QuadrantAppliesEnum.NE: branch.Ne = AddToNode(x, y, w, h, rectangle, branch.Ne, tree, unique, indexName); break; case QuadrantAppliesEnum.SW: branch.Sw = AddToNode(x, y, w, h, rectangle, branch.Sw, tree, unique, indexName); break; case QuadrantAppliesEnum.SE: branch.Se = AddToNode(x, y, w, h, rectangle, branch.Se, tree, unique, indexName); break; case QuadrantAppliesEnum.SOME: var numAdded = AddToData(branch, x, y, w, h, rectangle, unique, indexName); branch.IncCount(numAdded); break; default: throw new IllegalStateException("No intersection"); } }
private static void CollectRange( MXCIFQuadTreeNode node, double x, double y, double width, double height, EventBean eventBean, TT target, QuadTreeCollector<TT> collector, ExprEvaluatorContext ctx) { if (node is MXCIFQuadTreeNodeLeaf leaf) { CollectNode(leaf, x, y, width, height, eventBean, target, collector, ctx); return; } MXCIFQuadTreeNodeBranch branch = (MXCIFQuadTreeNodeBranch) node; CollectNode(branch, x, y, width, height, eventBean, target, collector, ctx); CollectRange(branch.Nw, x, y, width, height, eventBean, target, collector, ctx); CollectRange(branch.Ne, x, y, width, height, eventBean, target, collector, ctx); CollectRange(branch.Sw, x, y, width, height, eventBean, target, collector, ctx); CollectRange(branch.Se, x, y, width, height, eventBean, target, collector, ctx); }