def discrete(self, points, fraction=None): '''Compute the C{forward, discrete Fréchet} distance. @param points: Second set of points (C{LatLon}[], C{Numpy2LatLon}[], C{Tuple2LatLon}[] or C{other}[]). @keyword fraction: Index fraction (C{float} in L{EPS}..L{EPS1}) to interpolate intermediate B{C{points}} or C{None} or C{1} for no intermediate B{C{points}} and no I{fractional} indices. @return: A L{Frechet6Tuple}C{(fd, fi1, fi2, r, n, units)}. @raise FrechetError: Insufficient number of B{C{points}} or invalid B{C{fraction}}. @raise RecursionError: Recursion depth exceeded, see U{sys.getrecursionlimit() <https://docs.Python.org/3/library/sys.html#sys.getrecursionlimit>}. ''' n2, ps2 = _points2(points, closed=False, Error=FrechetError) f2 = _fraction(fraction, n2) p2 = self.points_fraction if f2 < EPS1 else self.points_ # PYCHOK expected f1 = self.fraction p1 = self.points_fraction if f1 < EPS1 else self.points_ # PYCHOK expected def dF(fi1, fi2): return self.distance(p1(self._ps1, fi1), p2(ps2, fi2)) return _frechet_(self._n1, f1, n2, f2, dF, self.units)
def __init__(self, points, fraction=None, name='', units='', **wrap_adjust): '''New C{Frechet...} calculator/interpolator. @arg points: First set of points (C{LatLon}[], L{Numpy2LatLon}[], L{Tuple2LatLon}[] or C{other}[]). @kwarg fraction: Index fraction (C{float} in L{EPS}..L{EPS1}) to interpolate intermediate B{C{points}} or use C{None}, C{0} or C{1} for no intermediate B{C{points}} and no I{fractional} indices. @kwarg name: Optional calculator/interpolator name (C{str}). @kwarg units: Optional distance units (C{str}). @kwarg wrap_adjust: Optionally, C{wrap} and unroll longitudes, iff applicable (C{bool}) and C{adjust} wrapped, unrolled longitudinal delta by the cosine of the mean latitude, iff applicable. @raise FrechetError: Insufficient number of B{C{points}} or invalid B{C{fraction}} or B{{wrap}} or B{C{ajust}} not applicable. ''' self._n1, self._ps1 = _points2(points, closed=False, Error=FrechetError) if fraction: self.fraction = fraction if name: self.name = name if units and not self.units: self.units = units if wrap_adjust: _bkwds(self, Error=FrechetError, **wrap_adjust)
def frechet_(points1, points2, distance=None, units=''): '''Compute the I{discrete} U{Fréchet<https://WikiPedia.org/wiki/Frechet_distance>} distance between two paths given as sets of points. @param points1: First set of points (C{LatLon}[], C{Numpy2LatLon}[], C{Tuple2LatLon}[] or C{other}[]). @param points2: Second set of points (C{LatLon}[], C{Numpy2LatLon}[], C{Tuple2LatLon}[] or C{other}[]). @keyword distance: Callable returning the distance between a B{C{points1}} and a B{C{points2}} point (signature C{(point1, point2)}). @keyword units: Optional, name of the distance units (C{str}). @return: A L{Frechet6Tuple}C{(fd, fi1, fi2, r, n, units)} where C{fi1} and C{fi2} are type C{int} indices into B{C{points1}} respectively B{C{points2}}. @raise FrechetError: Insufficient number of B{C{points1}} or B{C{points2}}. @raise RecursionError: Recursion depth exceeded, see U{sys.getrecursionlimit() <https://docs.Python.org/3/library/sys.html#sys.getrecursionlimit>}. @raise TypeError: If B{C{distance}} is not a callable. @note: Keyword C{fraction}, intermediate B{C{points1}} and B{C{points2}} and I{fractional} indices are I{not} supported in this L{frechet_} function. ''' if not callable(distance): raise _IsNotError(callable.__name__, distance=distance) n1, ps1 = _points2(points1, closed=False, Error=FrechetError) n2, ps2 = _points2(points2, closed=False, Error=FrechetError) def dF(i1, i2): return distance(ps1[i1], ps2[i2]) return _frechet_(n1, 1, n2, 1, dF, units)
def __init__(self, points, fraction=None, name='', units=''): '''New L{Frechet} calculator/interpolator. @param points: First set of points (C{LatLon}[], C{Numpy2LatLon}[], C{Tuple2LatLon}[] or C{other}[]). @keyword fraction: Index fraction (C{float} in L{EPS}..L{EPS1}) to interpolate intermediate B{C{points}} or C{None} or C{1} for no intermediate B{C{points}} and no I{fractional} indices. @keyword name: Optional calculator/interpolator name (C{str}). @keyword units: Optional, distance units (C{str}). @raise FrechetError: Insufficient number of B{C{points}} or invalid B{C{fraction}}. ''' self._n1, self._ps1 = _points2(points, closed=False, Error=FrechetError) if fraction: self.fraction = fraction if name: self.name = name if units: self.units = units
def _points2(self, points): '''(INTERNAL) Check a set of points. ''' return _points2(points, closed=False, Error=FrechetError)