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 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"); } }
internal static void Compare( double x, double y, double width, double height, object expected, XYWHRectangleWValue rectangle) { Assert.AreEqual(x, rectangle.X); Assert.AreEqual(y, rectangle.Y); Assert.AreEqual(width, rectangle.W); Assert.AreEqual(height, rectangle.H); Assert.AreEqual(expected, rectangle.Value); }
private static int SetOnNodeWithRect( MXCIFQuadTreeNode node, double x, double y, double width, double height, XYWHRectangleWValue value) { if (!value.CoordinateEquals(x, y, width, height)) { throw new IllegalStateException(); } return SetOnNode(node, x, y, width, height, value.Value); }
private static MXCIFQuadTreeNode SetOnNodeWithRect( double x, double y, double width, double height, XYWHRectangleWValue value, MXCIFQuadTreeNode node, MXCIFQuadTree tree) { if (node is MXCIFQuadTreeNodeLeaf leaf) { var count = SetOnNodeWithRect(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) node; AddToBranchWithRect(branch, x, y, width, height, value, tree); return node; }