public void EnumerateFromPoint() { Vector3DLeafItem item1 = new Vector3DLeafItem(1, 0, 0); Vector3DLeafItem item2 = new Vector3DLeafItem(2, 0, 0); Vector3DLeafItem item3 = new Vector3DLeafItem(3, 0, 0); IEnumerable <Vector3DLeafItem> enumerable = new Vector3DLeafItem[] { item1, item2, item3 }.AsEnumerable <Vector3DLeafItem>(); KDTreeNode <Vector3DLeafItem> rootNode = KDTreeNode <Vector3DLeafItem> .CreateTree(enumerable); int index = 0; foreach (Vector3DLeafItem item in rootNode.GetDistanceEnumerator(new double[] { 2.1, 0, 0 })) { switch (index++) { case 0: Assert.IsTrue(item == item2); break; case 1: Assert.IsTrue(item == item3); break; case 2: Assert.IsTrue(item == item1); break; } } }
public void CreateFromKDTree() { Vector3DLeafItem item1 = new Vector3DLeafItem(5, 5, 5); Vector3DLeafItem item2 = new Vector3DLeafItem(5, 5, 5); Vector3DLeafItem item3 = new Vector3DLeafItem(5, 5, 5); IEnumerable <Vector3DLeafItem> enumerable = new Vector3DLeafItem[] { item1, item2, item3 }.AsEnumerable <Vector3DLeafItem>(); KDTreeNode <Vector3DLeafItem> rootNode = KDTreeNode <Vector3DLeafItem> .CreateTree(enumerable); RunTestOnNode3D(item1, item2, item3, rootNode); KDTreeNode <Vector3DLeafItem> fromRootNode = KDTreeNode <Vector3DLeafItem> .CreateTree(rootNode.UnorderedEnumerator()); KDTreeNode <Vector3DLeafItem> testNode = fromRootNode; Assert.IsTrue(testNode.DimensionSplitIsOn == 0); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit != null); testNode = testNode.NodeGreaterThanOrEqualToSplit; Assert.IsTrue(testNode.DimensionSplitIsOn == 1); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit != null); testNode = testNode.NodeGreaterThanOrEqualToSplit; Assert.IsTrue(testNode.DimensionSplitIsOn == 2); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit == null); }
public void SamePointTest3D() { Vector3DLeafItem item1 = new Vector3DLeafItem(5, 5, 5); Vector3DLeafItem item2 = new Vector3DLeafItem(5, 5, 5); Vector3DLeafItem item3 = new Vector3DLeafItem(5, 5, 5); IEnumerable <Vector3DLeafItem> enumerable = new Vector3DLeafItem[] { item1, item2, item3 }.AsEnumerable <Vector3DLeafItem>(); KDTreeNode <Vector3DLeafItem> rootNode = KDTreeNode <Vector3DLeafItem> .CreateTree(enumerable); RunTestOnNode3D(item1, item2, item3, rootNode); }
private static void RunTestOnNode3D(Vector3DLeafItem item1, Vector3DLeafItem item2, Vector3DLeafItem item3, KDTreeNode <Vector3DLeafItem> rootNode) { KDTreeNode <Vector3DLeafItem> testNode = rootNode; Assert.IsTrue(testNode.DimensionSplitIsOn == 0); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit != null); Assert.IsTrue(testNode.LeafItem == item1); testNode = testNode.NodeGreaterThanOrEqualToSplit; Assert.IsTrue(testNode.DimensionSplitIsOn == 1); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit != null); Assert.IsTrue(testNode.LeafItem == item2); testNode = testNode.NodeGreaterThanOrEqualToSplit; Assert.IsTrue(testNode.DimensionSplitIsOn == 2); Assert.IsTrue(testNode.NodeLessThanSplit == null); Assert.IsTrue(testNode.NodeGreaterThanOrEqualToSplit == null); Assert.IsTrue(testNode.LeafItem == item3); }