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 ICollection <object> Visit( PointRegionQuadTreeNodeLeaf <object> node, double x, double y, double width, double height, ICollection <object> result) { object points = node.Points; if (points == null) { return(result); } if (points is XYPointMultiType) { XYPointMultiType point = (XYPointMultiType)points; return(Visit(point, x, y, width, height, result)); } ICollection <XYPointMultiType> collection = (ICollection <XYPointMultiType>)points; foreach (XYPointMultiType point in collection) { result = Visit(point, x, y, width, height, result); } return(result); }
private static ICollection <object> Visit( XYPointMultiType point, double x, double y, double width, double height, ICollection <object> result) { if (!BoundingBox.ContainsPoint(x, y, width, height, point.X, point.Y)) { return(result); } if (result == null) { result = new ArrayDeque <object>(4); } point.CollectInto(result); return(result); }
public void AddMultiType(XYPointMultiType 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) Multityped).AddAll(otherCollection); return; } var coll = new LinkedList<object>(); coll.AddLast(Multityped); coll.AddAll(otherCollection); Multityped = coll; }
public static int AddToLeaf( PointRegionQuadTreeNodeLeaf <object> leaf, double x, double y, object value, bool unique, string indexName) { var currentValue = leaf.Points; // value can be multitype itself since we may subdivide-add and don't want to allocate a new object if (value is XYPointMultiType) { var point = (XYPointMultiType)value; if (point.X != x && point.Y != y) { throw new IllegalStateException(); } if (currentValue == null) { leaf.Points = point; return(point.Count()); } if (currentValue is XYPointMultiType) { var other = (XYPointMultiType)currentValue; if (other.X == x && other.Y == y) { if (unique) { throw HandleUniqueViolation(indexName, other.X, other.Y); } other.AddMultiType(point); return(point.Count()); } var collectionX = new LinkedList <XYPointMultiType>(); collectionX.AddLast(other); collectionX.AddLast(point); leaf.Points = collectionX; return(point.Count()); } var xyPointMultiTypes = (ICollection <XYPointMultiType>)currentValue; foreach (var other in xyPointMultiTypes) { if (other.X == x && other.Y == y) { if (unique) { throw HandleUniqueViolation(indexName, other.X, other.Y); } other.AddMultiType(point); return(point.Count()); } } xyPointMultiTypes.Add(point); return(point.Count()); } if (currentValue == null) { var point = new XYPointMultiType(x, y, value); leaf.Points = point; return(1); } if (currentValue is XYPointMultiType) { var other = (XYPointMultiType)currentValue; if (other.X == x && other.Y == y) { if (unique) { throw HandleUniqueViolation(indexName, other.X, other.Y); } other.AddSingleValue(value); return(1); } var xyPointMultiTypes = new LinkedList <XYPointMultiType>(); xyPointMultiTypes.AddLast(other); xyPointMultiTypes.AddLast(new XYPointMultiType(x, y, value)); leaf.Points = xyPointMultiTypes; return(1); } var collection = (ICollection <XYPointMultiType>)currentValue; foreach (var other in collection) { if (other.X == x && other.Y == y) { if (unique) { throw HandleUniqueViolation(indexName, other.X, other.Y); } other.AddSingleValue(value); return(1); } } collection.Add(new XYPointMultiType(x, y, value)); return(1); }