randomPoint method

  1. @override
Vector2 randomPoint({
  1. Random? random,
  2. bool within = true,
})
override

Returns a random point within the shape if within is true (default) and otherwise a point along the edges of the shape. Do note that within=true also includes the edges.

If isClosed is false, the within value does not make a difference.

Implementation

@override
Vector2 randomPoint({Random? random, bool within = true}) {
  final randomGenerator = random ?? randomFallback;
  final theta = randomGenerator.nextDouble() * tau;
  final radius = within ? randomGenerator.nextDouble() * _radius : _radius;
  final x = radius * cos(theta);
  final y = radius * sin(theta);

  return Vector2(_center.x + x, _center.y + y);
}