distanceTo2D method

  1. @override
double distanceTo2D(
  1. Position destination
)
override

Returns a distance from this to destination calculated in a cartesian 2D plane.

The distance is computed according to dimensionality of a geometry:

  • areal geometries: a shortest distance to the outline of a polygon
  • linear geometries: a distance to the nearest line segment
  • punctual geometries: a distance to the nearest position

Returns double.infinity if a distance could not be calculated.

Implementation

@override
double distanceTo2D(Position destination) {
  var minDistance = double.infinity;
  for (final pol in polygons) {
    final dist = pol.distanceTo2D(destination);
    if (dist < minDistance) {
      minDistance = dist;
    }
  }
  return minDistance;
}