support method

  1. @override
Vector2 support(
  1. Vector2 direction
)
override

Finds the intersection of this shape with another one, if it exists. Returns a point on the boundary that is furthest in the given direction.

In other words, this returns such a point p within in the shape for which the dot-product p·direction is maximal. If multiple such points exist, then any one of them can be returned.

The direction vector may have length not equal to 1.

This method is only used for convex shapes.

Implementation

@override
Vector2 support(Vector2 direction) {
  var bestVertex = _vertices.first;
  var bestProduct = bestVertex.dot(direction);
  for (final vertex in _vertices) {
    final dotProduct = vertex.dot(direction);
    if (dotProduct > bestProduct) {
      bestProduct = dotProduct;
      bestVertex = vertex;
    }
  }
  return bestVertex;
}