PathComponent constructor
PathComponent({})
With this constructor you create a PathComponent from all the contours
of the path.
The contours are sampled every sampling along their length, and the
samples that are not needed to stay within the tolerance of the contour
are left out; by default, the tolerance is half the sampling. See
PathMetricExtension.walkContour for the details of both parameters.
Contours that end up with fewer than three vertices, like open lines, do
not become polygons. When filter is true, the polygons whose vertices
all lie inside of the largest polygon are left out too, since they are
details of the shape that it already covers, like the eyes of a face.
Implementation
PathComponent({
required Path path,
this.sampling = 1.0,
this.tolerance,
this.filter = true,
super.position,
super.scale,
super.angle,
super.anchor,
super.children,
super.priority,
super.key,
super.paint,
super.paintLayers,
super.isSolid,
}) : path = path.toOrigin,
super(size: path.getBounds().size.toVector2()) {
_polygons = _polygonsOf(
this.path,
sampling: sampling,
tolerance: tolerance,
filter: filter,
);
_globalPolygons = [
for (final polygon in _polygons)
List.generate(polygon.length, (_) => Vector2.zero(), growable: false),
];
_lineSegments = [
for (final polygon in _polygons)
List.generate(
polygon.length,
(_) => LineSegment.zero(),
growable: false,
),
];
for (final polygon in _polygons) {
_polygonsPath.addPolygon(
polygon.map((vertex) => vertex.toOffset()).toList(growable: false),
true,
);
}
}