VectorPathOutline.local constructor
VectorPathOutline.local(
- DiagramRect frame,
- DiagramVectorPath localPath, {
- double cornerRadius = 0,
Resolves localPath, in shape-local units measured from the frame
origin (not unit coordinates), at frame.
Implementation
factory VectorPathOutline.local(
DiagramRect frame,
DiagramVectorPath localPath, {
double cornerRadius = 0,
}) {
final path = localPath..validate();
final nodes = [
for (final n in path.nodes)
n.copyWith(
position: DiagramPoint(
frame.left + n.position.x,
frame.top + n.position.y,
),
),
];
for (final node in nodes) {
for (final point in [
node.position,
node.position + node.incoming,
node.position + node.outgoing,
]) {
if (!point.x.isFinite || !point.y.isFinite) {
throw StateError('Resolved path coordinates must remain finite');
}
}
}
final segments = <List<DiagramPoint>>[];
for (var i = 0; i < nodes.length - (path.closed ? 0 : 1); i++) {
final a = nodes[i];
final b = nodes[(i + 1) % nodes.length];
final points = <DiagramPoint>[a.position];
if (a.segment == DiagramPathSegmentKind.line) {
points.add(b.position);
} else {
flattenCubic(
a.position,
a.position + a.outgoing,
b.position + b.incoming,
b.position,
tolerance: curveTolerance,
output: points,
);
}
segments.add(points);
}
final points = _roundPathCorners(
segments,
closed: path.closed,
radius: cornerRadius,
corners: [
for (final node in nodes) node.mode == DiagramPathHandleMode.corner,
],
);
// Control hull is conservative even for curves with extrema between anchors.
final hull = [
for (final n in nodes) ...[
n.position,
n.position + n.incoming,
n.position + n.outgoing,
],
];
final bounds = DiagramRect.fromPoints([...frame.corners, ...hull]);
return VectorPathOutline._(
bounds,
List.unmodifiable(nodes),
List.unmodifiable(points),
path.closed,
);
}