private static ICollection <object> Visit( XYWHRectangleMultiType rectangle, double x, double y, double width, double height, ICollection <object> result) { if (!BoundingBox.IntersectsBoxIncludingEnd(x, y, x + width, y + height, rectangle.X, rectangle.Y, rectangle.W, rectangle.H)) { return(result); } if (result == null) { result = new ArrayDeque <object>(4); } rectangle.CollectInto(result); return(result); }
public void AddMultiType(XYWHRectangleMultiType other) { if (other.X != X || other.Y != Y) throw new ArgumentException("Coordinate mismatch"); if (!(other.Multityped is Collection)) { AddSingleValue(other.Multityped); return; } var otherCollection = (Collection) other.Multityped; if (Multityped is Collection collection) { collection.AddAll(otherCollection); return; } var coll = new LinkedList<object>(); coll.AddLast(Multityped); coll.AddAll(otherCollection); Multityped = coll; }
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 EPException HandleUniqueViolation(string indexName, XYWHRectangleMultiType other) { return(PropertyIndexedEventTableUnique.HandleUniqueIndexViolation(indexName, "(" + other.X + "," + other.Y + "," + other.W + "," + other.H + ")")); }
public static int AddToData( MXCIFQuadTreeNode <object> node, double x, double y, double width, double height, object value, bool unique, string indexName) { var currentValue = node.Data; // value can be multitype itself since we may subdivide-add and don't want to allocate a new object if (value is XYWHRectangleMultiType rectangle) { if (!rectangle.CoordinateEquals(x, y, width, height)) { throw new IllegalStateException(); } if (currentValue == null) { node.Data = rectangle; return(rectangle.Count()); } if (currentValue is XYWHRectangleMultiType otherXYWHR) { if (otherXYWHR.CoordinateEquals(x, y, width, height)) { if (unique) { throw HandleUniqueViolation(indexName, otherXYWHR); } otherXYWHR.AddMultiType(rectangle); return(rectangle.Count()); } var collectionInner = new LinkedList <XYWHRectangleMultiType>(); collectionInner.AddLast(otherXYWHR); collectionInner.AddLast(rectangle); node.Data = collectionInner; return(rectangle.Count()); } var collectionXYWH = (ICollection <XYWHRectangleMultiType>)currentValue; foreach (var other in collectionXYWH) { if (other.CoordinateEquals(x, y, width, height)) { if (unique) { throw HandleUniqueViolation(indexName, other); } other.AddMultiType(rectangle); return(rectangle.Count()); } } collectionXYWH.Add(rectangle); return(rectangle.Count()); } if (currentValue == null) { var point = new XYWHRectangleMultiType(x, y, width, height, value); node.Data = point; return(1); } if (currentValue is XYWHRectangleMultiType otherInnerX) { if (otherInnerX.CoordinateEquals(x, y, width, height)) { if (unique) { throw HandleUniqueViolation(indexName, otherInnerX); } otherInnerX.AddSingleValue(value); return(1); } var collectionXY = new LinkedList <XYWHRectangleMultiType>(); collectionXY.AddLast(otherInnerX); collectionXY.AddLast(new XYWHRectangleMultiType(x, y, width, height, value)); node.Data = collectionXY; return(1); } var collection = (ICollection <XYWHRectangleMultiType>)currentValue; foreach (XYWHRectangleMultiType other in collection) { if (other.CoordinateEquals(x, y, width, height)) { if (unique) { throw HandleUniqueViolation(indexName, other); } other.AddSingleValue(value); return(1); } } collection.Add(new XYWHRectangleMultiType(x, y, width, height, value)); return(1); }