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 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; } }
public void TestAddMultiType() { var vOne = new XYPointMultiType(10, 20, "X"); var vTwo = new XYPointMultiType(10, 20, "Y"); vOne.AddMultiType(vTwo); AssertValues("X,Y", vOne); AssertValues("Y", vTwo); var vThree = new XYPointMultiType(10, 20, "1"); vThree.AddSingleValue("2"); vOne.AddMultiType(vThree); AssertValues("X,Y,1,2", vOne); AssertValues("1,2", vThree); var vFour = new XYPointMultiType(10, 20, "X"); vFour.AddSingleValue("1"); vFour.AddMultiType(vTwo); AssertValues("X,1,Y", vFour); var vFive = new XYPointMultiType(10, 20, "A"); vFive.AddSingleValue("B"); vFive.AddMultiType(vThree); AssertValues("A,B,1,2", vFive); vFive.AddSingleValue("C"); AssertValues("A,B,1,2,C", vFive); }
private void AssertValues( string expected, XYPointMultiType v) { var received = v.Multityped is ICollection <object>?Join((ICollection <object>) v.Multityped) : v.Multityped.ToString(); Assert.AreEqual(expected, received); Assert.AreEqual(v.Count(), expected.SplitCsv().Length); }
internal static void Compare( double x, double y, string expected, XYPointMultiType point) { Assert.AreEqual(x, point.X); Assert.AreEqual(y, point.Y); Assert.AreEqual(expected, point.Multityped.RenderAny()); }
public void TestAddSingleValue() { var v = new XYPointMultiType(10, 20, "X"); AssertValues("X", v); v.AddSingleValue("Y"); AssertValues("X,Y", v); v.AddSingleValue("Z"); AssertValues("X,Y,Z", v); }
public void TestCollectInto() { ICollection <object> values = new List <object>(); var v = new XYPointMultiType(10, 20, "X"); v.CollectInto(values); Assert.AreEqual("X", Join(values)); values.Clear(); v.AddSingleValue("Y"); v.CollectInto(values); Assert.AreEqual("X,Y", Join(values)); }
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 ICollection<object> otherCollection)) { AddSingleValue(other.Multityped); return; } if (Multityped is ICollection<object> objectCollection) { objectCollection.AddAll(otherCollection); return; } var coll = new LinkedList<object>(); coll.AddLast(Multityped); coll.AddAll(otherCollection); Multityped = coll; }
public void TestInvalidMerge() { var vOne = new XYPointMultiType(10, 20, "X"); try { vOne.AddMultiType(new XYPointMultiType(5, 20, "Y")); Assert.Fail(); } catch (ArgumentException) { // expected } try { vOne.AddMultiType(new XYPointMultiType(10, 19, "Y")); Assert.Fail(); } catch (ArgumentException) { // expected } }
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; }