setSegmentKind method
Implementation
EditResult setSegmentKind(
String id,
String nodeId,
DiagramPathSegmentKind kind,
) => _edit(id, (p) {
final index = _index(p, nodeId);
if (!p.closed && index == p.nodes.length - 1) {
throw ArgumentError('The last open node has no outgoing segment');
}
final next = (index + 1) % p.nodes.length;
final nodes = [...p.nodes];
final a = nodes[index];
final b = nodes[next];
final tangent = (b.position - a.position) * (1 / 3);
nodes[index] = a.copyWith(
segment: kind,
outgoing:
kind == DiagramPathSegmentKind.cubic && a.outgoing.magnitude == 0
? tangent
: a.outgoing,
mode: DiagramPathHandleMode.corner,
);
nodes[next] = b.copyWith(
incoming:
kind == DiagramPathSegmentKind.cubic && b.incoming.magnitude == 0
? tangent * -1
: b.incoming,
mode: DiagramPathHandleMode.corner,
);
return p.copyWith(nodes: nodes);
});