projectCircle static method

({double max, double min}) projectCircle(
  1. Vector2 center,
  2. double radius,
  3. Vector2 axis
)

Implementation

static ({double min, double max}) projectCircle(
    Vector2 center, double radius, Vector2 axis) {
  Vector2 direction = axis.normalized();
  Vector2 directionAndRadius = direction * radius;

  Vector2 p1 = center + directionAndRadius;
  Vector2 p2 = center - directionAndRadius;

  double min = p1.dot(axis);
  double max = p2.dot(axis);

  if (min > max) {
    // swap the min and max values.
    double t = min;
    min = max;
    max = t;
  }
  return (min: min, max: max);
}