computeMetrics method

PathMetrics computeMetrics (
  1. {bool forceClosed: false}
)

Creates a PathMetrics object for this path, which can describe various properties about the contours of the path.

A Path is made up of zero or more contours. A contour is made up of connected curves and segments, created via methods like lineTo, cubicTo, arcTo, quadraticBezierTo, their relative counterparts, as well as the add* methods such as addRect. Creating a new Path starts a new contour once it has any drawing instructions, and another new contour is started for each moveTo instruction.

A PathMetric object describes properties of an individual contour, such as its length, whether it is closed, what the tangent vector of a particular offset along the path is. It also provides a method for creating sub-paths: PathMetric.extractPath.

Calculating PathMetric objects is not trivial. The PathMetrics object returned by this method is a lazy Iterable, meaning it only performs calculations when the iterator is moved to the next PathMetric. Callers that wish to memoize this iterable can easily do so by using Iterable.toList on the result of this method. In particular, callers looking for information about how many contours are in the path should either store the result of path.computeMetrics().length, or should use path.computeMetrics().toList() so they can repeatedly check the length, since calling Iterable.length causes traversal of the entire iterable.

In particular, callers should be aware that PathMetrics.length is the number of contours, not the length of the path. To get the length of a contour in a path, use PathMetric.length.

If forceClosed is set to true, the contours of the path will be measured as if they had been closed, even if they were not explicitly closed.

Implementation

PathMetrics computeMetrics({bool forceClosed = false}) {
  return PathMetrics._(this, forceClosed);
}