/// <summary>
        /// Computes the distance from the base geometry to the given geometry.
        /// </summary>
        /// <param name="g">The geometry to compute the distance to.</param>
        /// <returns>The computed distance</returns>
        public double GetDistance(IGeometry g)
        {
            var tree2 = FacetSequenceTreeBuilder.BuildSTRtree(g);
            var obj   = _cachedTree.NearestNeighbour(tree2, new FacetSequenceDistance());

            return(FacetDistance(obj));
        }
        /// <summary>
        /// Computes the nearest locations on the base geometry
        /// and the given geometry.
        /// </summary>
        /// <param name="g">Ihe geometry to compute the nearest location to.</param>
        /// <returns>The nearest locations.</returns>
        public GeometryLocation[] NearestLocations(Geometry g)
        {
            var tree2 = FacetSequenceTreeBuilder.BuildSTRtree(g);
            var obj   = _cachedTree.NearestNeighbour(tree2, FACET_SEQ_DIST);
            var fs1   = obj[0];
            var fs2   = obj[1];

            return(fs1.NearestLocations(fs2));
        }
        /// <summary>
        /// Computes the distance from the base geometry to the given geometry.
        /// </summary>
        /// <param name="g">The geometry to compute the distance to.</param>
        /// <returns>The computed distance</returns>
        public double Distance(Geometry g)
        {
            var tree2 = FacetSequenceTreeBuilder.BuildSTRtree(g);
            var obj   = _cachedTree.NearestNeighbour(tree2, FACET_SEQ_DIST);
            var fs1   = obj[0];
            var fs2   = obj[1];

            return(fs1.Distance(fs2));
        }
        /// <summary>
        /// Tests whether the base geometry lies within
        /// a specified distance of the given geometry.
        /// </summary>
        /// <param name="g">The geometry to test</param>
        /// <param name="maxDistance">The maximum distance to test</param>
        /// <returns><c>true</c> if the geometry lies with the specified distance</returns>
        public bool IsWithinDistance(Geometry g, double maxDistance)
        {
            // short-ciruit check
            double envDist = baseGeometry.EnvelopeInternal.Distance(g.EnvelopeInternal);

            if (envDist > maxDistance)
            {
                return(false);
            }

            var tree2 = FacetSequenceTreeBuilder.BuildSTRtree(g);

            return(_cachedTree.IsWithinDistance(tree2, FACET_SEQ_DIST, maxDistance));
        }
 /// <summary>
 /// Creates a new distance-finding instance for a given target <see cref="Geometry"/>.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Distances will be computed to all facets of the input geometry.
 /// The facets of the geometry are the discrete segments and points
 /// contained in its components.  </para>
 /// <para>
 /// In the case of <see cref="ILineal"/> and <see cref="IPuntal"/> inputs,
 /// this is equivalent to computing the conventional distance.
 /// </para><para>
 /// In the case of <see cref="IPolygonal"/> inputs, this is equivalent
 /// to computing the distance to the polygon boundaries.
 /// </para>
 /// </remarks>
 /// <param name="g1">A Geometry, which may be of any type.</param>
 public IndexedFacetDistance(Geometry g1)
 {
     baseGeometry = g1;
     _cachedTree  = FacetSequenceTreeBuilder.BuildSTRtree(g1);
 }