nearestPoint method

  1. @override
Vector2 nearestPoint(
  1. Vector2 point
)
override

Returns a point on the shape's boundary which is closest to the given point.

The point must lie outside of the shape. If there are multiple nearest points, any one can be returned.

This method will not modify point. At the same time, the caller does not get ownership of the returned object: they must treat it as an immutable short-lived object.

Implementation

@override
Vector2 nearestPoint(Vector2 point) {
  if (_radius == 0) {
    return _center;
  }
  return _tmpResult
    ..setFrom(point)
    ..sub(_center)
    ..length = _radius
    ..add(_center);
}