//private double _maxDistance = -1.0; /// <summary> /// Creates an instance of this class with the given <see cref="IBoundable{Envelope, TItem}"/>s and the <see cref="IItemDistance{Envelope, TItem}"/> function. /// </summary> /// <param name="boundable1">The first boundable</param> /// <param name="boundable2">The second boundable</param> /// <param name="itemDistance">The item distance function</param> public BoundablePair(IBoundable <Envelope, TItem> boundable1, IBoundable <Envelope, TItem> boundable2, IItemDistance <Envelope, TItem> itemDistance) { _boundable1 = boundable1; _boundable2 = boundable2; _itemDistance = itemDistance; _distance = GetDistance(); }
/// <summary> /// Finds the item in this tree which is nearest to the given <paramref name="item"/>, /// using <see cref="IItemDistance{Envelope,TItem}"/> as the distance metric. /// A Branch-and-Bound tree traversal algorithm is used /// to provide an efficient search. /// <para/> /// The query <paramref name="item"/> does <b>not</b> have to be /// contained in the tree, but it does /// have to be compatible with the <paramref name="itemDist"/> /// distance metric. /// </summary> /// <param name="env">The envelope of the query item</param> /// <param name="item">The item to find the nearest neighbour of</param> /// <param name="itemDist">A distance metric applicable to the items in this tree and the query item</param> /// <returns>The nearest item in this tree</returns> public TItem NearestNeighbour(Envelope env, TItem item, IItemDistance <Envelope, TItem> itemDist) { var bnd = new ItemBoundable <Envelope, TItem>(env, item); var bp = new BoundablePair <TItem>(Root, bnd, itemDist); return(NearestNeighbour(bp)[0]); }
/// <summary> /// Finds the two nearest items from this tree /// and another tree, /// using <see cref="IItemDistance{Envelope, TItem}"/> as the distance metric. /// A Branch-and-Bound tree traversal algorithm is used /// to provide an efficient search. /// The result value is a pair of items, /// the first from this tree and the second /// from the argument tree. /// </summary> /// <param name="tree">Another tree</param> /// <param name="itemDist">A distance metric applicable to the items in the trees</param> /// <returns>The pair of the nearest items, one from each tree or <c>null</c> if no pair of distinct items can be found.</returns> public TItem[] NearestNeighbour(STRtree <TItem> tree, IItemDistance <Envelope, TItem> itemDist) { if (IsEmpty || tree.IsEmpty) { return(null); } var bp = new BoundablePair <TItem>(Root, tree.Root, itemDist); return(NearestNeighbour(bp)); }
/// <summary> /// Finds the two nearest items in the tree, /// using <see cref="IItemDistance{Envelope, TItem}"/> as the distance metric. /// A Branch-and-Bound tree traversal algorithm is used /// to provide an efficient search. /// <para/> /// If the tree is empty, the return value is <c>null</c>. /// If the tree contains only one item, the return value is a pair containing that item. /// If it is required to find only pairs of distinct items, /// the <see cref="IItemDistance{T,TItem}"/> function must be <b>anti-reflexive</b>. /// </summary> /// <param name="itemDist">A distance metric applicable to the items in this tree</param> /// <returns>The pair of the nearest items or <c>null</c> if the tree is empty</returns> public TItem[] NearestNeighbour(IItemDistance <Envelope, TItem> itemDist) { if (IsEmpty) { return(null); } // if tree has only one item this will return null var bp = new BoundablePair <TItem>(Root, Root, itemDist); return(NearestNeighbour(bp)); }
/// <summary> /// Finds the two nearest items in the tree, /// using <see cref="IItemDistance{Envelope, TItem}"/> as the distance metric. /// A Branch-and-Bound tree traversal algorithm is used /// to provide an efficient search. /// </summary> /// <param name="itemDist">A distance metric applicable to the items in this tree</param> /// <returns>The pair of the nearest items</returns> public TItem[] NearestNeighbour(IItemDistance <Envelope, TItem> itemDist) { var bp = new BoundablePair <TItem>(Root, Root, itemDist); return(NearestNeighbour(bp)); }
/** * Tests whether some two items from this tree and another tree * lie within a given distance. * {@link ItemDistance} is used as the distance metric. * A Branch-and-Bound tree traversal algorithm is used * to provide an efficient search. * * @param tree another tree * @param itemDist a distance metric applicable to the items in the trees * @param maxDistance the distance limit for the search * @return true if there are items within the distance */ public bool IsWithinDistance(STRtree <TItem> tree, IItemDistance <Envelope, TItem> itemDist, double maxDistance) { var bp = new BoundablePair <TItem>(Root, tree.Root, itemDist); return(IsWithinDistance(bp, maxDistance)); }