### Question:
CircleMath { public static IVector2 nearestPointOutsideCircle(final ICircular circle, final IVector2 point) { final Vector2 direction = point.subtractNew(circle.center()); final double factor = circle.radius() / direction.getLength2(); if (Double.isFinite(factor)) { if (factor <= 1) { return point; } direction.multiply(factor); direction.add(circle.center()); return direction; } return point.addNew(Vector2f.fromXY(circle.radius(), 0)); } @SuppressWarnings("unused") private  CircleMath(); static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint); static List<IVector2> lineIntersections(final ICircular circle, final ILineBase line); static List<IVector2> circleIntersections(final ICircle firstCircle, final ICircle secondCircle); static IVector2 nearestPointOutsideCircle(final ICircular circle, final IVector2 point); static boolean isPointInCircle(ICircular circle, IVector2 point, double margin); static boolean isPointInArc(final IArc arc, final IVector2 point, double margin); static IVector2 nearestPointOutsideArc(final IArc arc, final IVector2 point); static Vector2 stepAlongCircle(final IVector2 current, final IVector2 center, final double angle);  }### Answer:
@Test public void nearestPointOutsideCircle() { double radius = 300; double posX = 1000; double posY = 500; IVector2 origin = Vector2.fromXY(posX, posY); ICircle circle = Circle.createCircle(origin, radius); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(300, 300)))) .isEqualTo(origin.addNew(Vector2.fromXY(300, 300))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(-400, 500)))) .isEqualTo(origin.addNew(Vector2.fromXY(-400, 500))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(250, -300)))) .isEqualTo(origin.addNew(Vector2.fromXY(250, -300))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(-240, -220)))) .isEqualTo(origin.addNew(Vector2.fromXY(-240, -220))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(100, 0)))) .isEqualTo(origin.addNew(Vector2.fromXY(radius, 0))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(0, -50)))) .isEqualTo(origin.addNew(Vector2.fromXY(0, -radius))); assertThat(CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(0, 0)))) .isEqualTo(origin.addNew(Vector2.fromXY(radius, 0))); assertThat( (CircleMath.nearestPointOutsideCircle(circle, origin.addNew(Vector2.fromXY(100, 100))) .subtractNew(origin.addNew(Vector2.fromAngle(Math.PI / 4).multiply(radius)))).getLength() < 1e-3) .isTrue(); }