ResolvedPathGeometry constructor
ResolvedPathGeometry(
- Iterable<
DiagramPoint> source
Implementation
factory ResolvedPathGeometry(Iterable<DiagramPoint> source) {
final points = <DiagramPoint>[];
final distances = <double>[];
var length = 0.0;
for (final point in source) {
if (!point.x.isFinite || !point.y.isFinite) {
throw ArgumentError.value(
point,
'source',
'Path points must be finite',
);
}
if (points.isNotEmpty) {
final segment = (point - points.last).magnitude;
if (segment == 0) continue;
length += segment;
if (!length.isFinite) throw ArgumentError('Path length must be finite');
}
points.add(point);
distances.add(length);
}
if (points.isEmpty) throw ArgumentError('A path needs at least one point');
return ResolvedPathGeometry._(
List.unmodifiable(points),
List.unmodifiable(distances),
);
}