示例#1
0
        /// <summary>
        /// Remove item from kd-tree.
        /// </summary>
        /// <remarks>
        /// Removes the first item with equal coordinates.
        /// </remarks>
        public bool Remove(T item)
        {
            // Determine leaf
            KdNode <T> leaf = _cls.FindClosestLeaf(item);
            // Find first index in collection with equal coordinates
            int index = leaf.Vectors.FindIndex(delegate(T obj) { return(VectorComparison.Equal(item, obj)); });

            if (index < 0) // Item not found
            {
                return(false);
            }
            leaf.Vectors.RemoveAt(index);
            if (leaf.Vectors.Count > 0)
            {
                // Still items to process, test if removal of item changed internal bounds
                AABB aabb = new AABB(leaf.InternalBounds.Dimensions);
                aabb.Enlarge <T>(leaf.Vectors);
                if (!aabb.Equals(leaf.InternalBounds))
                {
                    // It did change internal bounds; broadcast change up to root
                    leaf.InternalBounds = aabb;
                    this.ShrinkAncestorBounds(leaf);
                }
            }
            else
            {
                // No more items contained
                leaf.InternalBounds.Reset();
                this.ShrinkAncestorBounds(leaf); // Need to shrink here: else space encapsulated by
                // empty leaf is not freed up to root
                this.TryCollapse(leaf);
            }
            _count -= 1;
            return(true);
        }
示例#2
0
 /// <summary>
 /// Component-wise equality with zero tolerance.
 /// </summary>
 public bool Equals(IVector other)
 {
     return(VectorComparison.Equal(this, other));
 }