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 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 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; }
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"); } }
public void TestPoints() { tree = MXCIFQuadTreeFactory.Make(0, 0, 10, 10); Set(8.0, 4.0, 1, 1, "R0", tree); AssertCollectAll(tree, "R0"); Set(8.0, 1.0, 1, 1, "R1", tree); AssertCollectAll(tree, "R0,R1"); Set(8.0, 2.0, 1, 1, "R2", tree); AssertCollectAll(tree, "R0,R1,R2"); Set(4.0, 4.0, 1, 1, "R3", tree); AssertCollectAll(tree, "R0,R1,R2,R3"); Set(1.0, 9.0, 1, 1, "R4", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4"); Set(8.0, 3.0, 1, 1, "R5", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4,R5"); Set(0.0, 6.0, 1, 1, "R6", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4,R5,R6"); Set(5.0, 1.0, 1, 1, "R7", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4,R5,R6,R7"); Set(5.0, 8.0, 1, 1, "R8", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4,R5,R6,R7,R8"); Set(7.0, 6.0, 1, 1, "R9", tree); AssertCollectAll(tree, "R0,R1,R2,R3,R4,R5,R6,R7,R8,R9"); }
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; }
public void TestPoints() { tree = MXCIFQuadTreeFactory.Make(0, 0, 10, 10); AddNonUnique(tree, 8.0, 4.0, 1, 1, "R0"); AssertFound(tree, 0, 0, 10, 10, "R0"); AddNonUnique(tree, 8.0, 1.0, 1, 1, "R1"); AssertFound(tree, 0, 0, 10, 10, "R0,R1"); AddNonUnique(tree, 8.0, 2.0, 1, 1, "R2"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2"); AddNonUnique(tree, 4.0, 4.0, 1, 1, "R3"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3"); AddNonUnique(tree, 1.0, 9.0, 1, 1, "R4"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4"); AddNonUnique(tree, 8.0, 3.0, 1, 1, "R5"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4,R5"); AddNonUnique(tree, 0.0, 6.0, 1, 1, "R6"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4,R5,R6"); AddNonUnique(tree, 5.0, 1.0, 1, 1, "R7"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4,R5,R6,R7"); AddNonUnique(tree, 5.0, 8.0, 1, 1, "R8"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4,R5,R6,R7,R8"); AddNonUnique(tree, 7.0, 6.0, 1, 1, "R9"); AssertFound(tree, 0, 0, 10, 10, "R0,R1,R2,R3,R4,R5,R6,R7,R8,R9"); }
private static MXCIFQuadTreeNode <object> AddToNode( double x, double y, double width, double height, object value, MXCIFQuadTreeNode <object> node, MXCIFQuadTree <object> tree, bool unique, string indexName) { if (node is MXCIFQuadTreeNodeLeaf <object> ) { var leaf = (MXCIFQuadTreeNodeLeaf <object>)node; if (leaf.Count < tree.LeafCapacity || node.Level >= tree.MaxTreeHeight) { // can be multiple as value can be a collection var numAdded = AddToData(leaf, x, y, width, height, value, unique, indexName); leaf.IncCount(numAdded); if (leaf.Count <= tree.LeafCapacity || node.Level >= tree.MaxTreeHeight) { return(leaf); } } node = Subdivide(leaf, tree, unique, indexName); } var branch = (MXCIFQuadTreeNodeBranch <object>)node; AddToBranch(branch, x, y, width, height, value, tree, unique, indexName); return(node); }
public void TestAddRemoveScenario() { tree = MXCIFQuadTreeFactory.Make(0, 0, 100, 100); AddUnique(tree, 85.0, 65.0, 0.999, 0.999, "P3"); AddUnique(tree, 86.0, 50.0, 0.999, 0.999, "P6"); AddUnique(tree, 17.0, 84.0, 0.999, 0.999, "P0"); AddUnique(tree, 7.0, 34.0, 0.999, 0.999, "P4"); AddUnique(tree, 7.0, 69.0, 0.999, 0.999, "P8"); AddUnique(tree, 36.0, 47.0, 0.999, 0.999, "P9"); AddUnique(tree, 62.0, 50.0, 0.999, 0.999, "P1"); AddUnique(tree, 46.0, 17.0, 0.999, 0.999, "P2"); AddUnique(tree, 43.0, 16.0, 0.999, 0.999, "P5"); AddUnique(tree, 79.0, 92.0, 0.999, 0.999, "P7"); Remove(tree, 46.0, 17.0, 0.999, 0.999, "P2"); AddUnique(tree, 47.0, 17.0, 0.999, 0.999, "P2"); Remove(tree, 43.0, 16.0, 0.999, 0.999, "P5"); AddUnique(tree, 44.0, 16.0, 0.999, 0.999, "P5"); Remove(tree, 62.0, 50.0, 0.999, 0.999, "P1"); AddUnique(tree, 62.0, 49.0, 0.999, 0.999, "P1"); Remove(tree, 17.0, 84.0, 0.999, 0.999, "P0"); AddUnique(tree, 18.0, 84.0, 0.999, 0.999, "P0"); Remove(tree, 86.0, 50.0, 0.999, 0.999, "P6"); AddUnique(tree, 86.0, 51.0, 0.999, 0.999, "P6"); AssertFound(tree, 81.0, 46.0, 10.0, 10.0, "P6"); }
private static MXCIFQuadTreeNode <object> SetOnNode( double x, double y, double width, double height, TL value, MXCIFQuadTreeNode <object> node, MXCIFQuadTree <object> tree) { if (node is MXCIFQuadTreeNodeLeaf <object> leaf) { var count = SetOnNode(leaf, x, y, width, height, value); leaf.IncCount(count); if (leaf.Count <= tree.LeafCapacity || node.Level >= tree.MaxTreeHeight) { return(leaf); } node = Subdivide(leaf, tree); } var branch = (MXCIFQuadTreeNodeBranch <object>)node; AddToBranch(branch, x, y, width, height, value, tree); return(node); }
public void TestFewValues() { tree = MXCIFQuadTreeFactory.Make(0, 0, 100, 100); Set(73.32704983331149, 23.46990952575032, 1, 1, "R0", tree); Set(53.09747562396894, 17.100976152185034, 1, 1, "R1", tree); Set(56.75757294858788, 25.508506696809608, 1, 1, "R2", tree); Set(83.66639067675291, 76.53772974832937, 1, 1, "R3", tree); Set(51.01654641861326, 43.49009281983866, 1, 1, "R4", tree); var beginX = 50.45945198254618; var endX = 88.31594559038719; var beginY = 4.577595744501329; var endY = 22.93393078279351; AssertCollect(tree, beginX, beginY, endX - beginX, endY - beginY, "R1"); AssertCollectAll(tree, "R0,R1,R2,R3,R4"); Assert.AreEqual("R0", Get(73.32704983331149, 23.46990952575032, 1, 1, tree)); Assert.AreEqual("R1", Get(53.09747562396894, 17.100976152185034, 1, 1, tree)); Assert.AreEqual("R2", Get(56.75757294858788, 25.508506696809608, 1, 1, tree)); Assert.AreEqual("R3", Get(83.66639067675291, 76.53772974832937, 1, 1, tree)); Assert.AreEqual("R4", Get(51.01654641861326, 43.49009281983866, 1, 1, tree)); }
public static ICollection <object> QueryRange( MXCIFQuadTree <object> quadTree, double x, double y, double width, double height) { return(QueryNode(quadTree.Root, x, y, width, height, null)); }
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"); } }
/// <summary> /// Remove value. /// </summary> /// <param name="x">x</param> /// <param name="y">y</param> /// <param name="width">width</param> /// <param name="height">height</param> /// <param name="value">value to remove</param> /// <param name="tree">quadtree</param> public static void Remove(double x, double y, double width, double height, object value, MXCIFQuadTree <object> tree) { var root = tree.Root; var replacement = RemoveFromNode(x, y, width, height, value, root, tree); tree.Root = replacement; }
public EventTableQuadTreeMXCIFImpl( EventTableOrganization organization, AdvancedIndexConfigStatementMXCIFQuadtree config, MXCIFQuadTree <Object> quadTree) { _organization = organization; _config = config; _quadTree = quadTree; }
public EventTableQuadTreeMXCIFImpl( EventTableOrganization organization, AdvancedIndexConfigStatementMXCIFQuadtree config, MXCIFQuadTree quadTree) { this.organization = organization; this.config = config; this.quadTree = quadTree; }
private static object Get( double x, double y, double width, double height, MXCIFQuadTree tree) { return(MXCIFQuadTreeFilterIndexGet.Get(x, y, width, height, tree)); }
public static void CollectRange( MXCIFQuadTree <object> quadTree, double x, double y, double width, double height, EventBean eventBean, TT target, QuadTreeCollector <TL, TT> collector) { CollectRange(quadTree.Root, x, y, width, height, eventBean, target, collector); }
private static void Delete( double x, double y, double width, double height, MXCIFQuadTree tree) { MXCIFQuadTreeFilterIndexDelete.Delete(x, y, width, height, tree); }
public static object Get( double x, double y, double width, double height, MXCIFQuadTree tree) { MXCIFQuadTreeFilterIndexCheckBB.CheckBB(tree.Root.Bb, x, y, width, height); return Get(x, y, width, height, tree.Root); }
internal static void AssertCollectAll( MXCIFQuadTree tree, String expected) { BoundingBox bb = tree.Root.Bb; AssertCollect(tree, bb.MinX, bb.MinY, bb.MaxX - bb.MinX, bb.MaxY - bb.MinY, expected); Assert.AreEqual(expected.Length == 0 ? 0 : expected.SplitCsv().Length, MXCIFQuadTreeFilterIndexCount.Count(tree)); Assert.AreEqual(expected.Length == 0, MXCIFQuadTreeFilterIndexEmpty.IsEmpty(tree)); }
internal static void Remove( MXCIFQuadTree quadTree, double x, double y, double width, double height, string value) { // Comment-me-in: System.out.println("remove(tree, " + x + ", " + y + ", " + width + ", " + height + ", \"" + value + "\");"); MXCIFQuadTreeRowIndexRemove.Remove(x, y, width, height, value, quadTree); }
public static void Set( double x, double y, double width, double height, String value, MXCIFQuadTree tree) { // Comment-me-in: System.out.println("set(" + x + ", " + y + ", " + width + ", " + height + ", \"" + value + "\", tree);"); MXCIFQuadTreeFilterIndexSet.Set(x, y, width, height, value, tree); }
internal static bool AddNonUnique( MXCIFQuadTree quadTree, double x, double y, double width, double height, string value) { // Comment-me-in: System.out.println("addNonUnique(tree, " + x + ", " + y + ", " + width + ", " + height + ", \"" + value + "\");"); return(MXCIFQuadTreeRowIndexAdd.Add(x, y, width, height, value, quadTree, false, "indexNameDummy")); }
public static void AddUnique( MXCIFQuadTree tree, double x, double y, double width, double height, string value) { // Comment-me-in: System.out.println("addUnique(tree, " + x + ", " + y + ", " + width + ", " + height + ", \"" + value + "\");"); MXCIFQuadTreeRowIndexAdd.Add(x, y, width, height, value, tree, true, "indexNameHere"); }
internal static void AssertFound( MXCIFQuadTree quadTree, double x, double y, double width, double height, string p1) { object[] expected = p1.Length == 0 ? null : p1.SplitCsv(); AssertFound(quadTree, x, y, width, height, expected); }
public static void Delete( double x, double y, double width, double height, MXCIFQuadTree tree) { var root = tree.Root; MXCIFQuadTreeFilterIndexCheckBB.CheckBB(root.Bb, x, y, width, height); tree.Root = DeleteFromNode(x, y, width, height, root, tree); }
public FilterParamIndexQuadTreeMXCIF(IReaderWriterLock readWriteLock, FilterSpecLookupable lookupable) : base(FilterOperator.ADVANCED_INDEX, lookupable) { _readWriteLock = readWriteLock; _advancedIndex = (FilterSpecLookupableAdvancedIndex) lookupable; var quadTreeConfig = _advancedIndex.QuadTreeConfig; _quadTree = MXCIFQuadTreeFactory<object>.Make( quadTreeConfig.X, quadTreeConfig.Y, quadTreeConfig.Width, quadTreeConfig.Height); }
public void TestAddRemoveSimple() { tree = MXCIFQuadTreeFactory.Make(0, 0, 50, 60); AssertFound(tree, 0, 0, 10, 10, ""); AddNonUnique(tree, 5, 8, 1, 1, "R1"); AssertFound(tree, 0, 0, 10, 10, "R1"); AssertFound(tree, 0, 0, 5, 5, ""); MXCIFQuadTreeRowIndexRemove.Remove(5, 8, 1, 1, "R1", tree); AssertFound(tree, 0, 0, 10, 10, ""); }
public static void Set( double x, double y, double width, double height, object value, MXCIFQuadTree tree) { MXCIFQuadTreeNode root = tree.Root; MXCIFQuadTreeFilterIndexCheckBB.CheckBB(root.Bb, x, y, width, height); tree.Root = SetOnNode(x, y, width, height, value, root, tree); }