normalizeToLocalCenter method
Normalizes interactive line geometry into local coordinates.
Preconditions (validated at runtime):
Throws StateError when preconditions are violated.
This method is intended for interactive drawing: while the user draws,
the engine may temporarily store start/end in world/scene coordinates
with transform == identity. Call this when the gesture finishes to
convert geometry to local space and store the world center in transform.
Implementation
void normalizeToLocalCenter() {
final t = transform;
if (!_isExactIdentityTransform(t)) {
throw StateError(
'LineNode.normalizeToLocalCenter requires transform == identity. '
'Use LineNode.fromWorldSegment for non-interactive creation.',
);
}
if (!start.dx.isFinite ||
!start.dy.isFinite ||
!end.dx.isFinite ||
!end.dy.isFinite) {
throw StateError(
'LineNode.normalizeToLocalCenter requires finite start/end coordinates.',
);
}
final bounds = Rect.fromPoints(start, end);
final centerWorld = bounds.center;
start = start - centerWorld;
end = end - centerWorld;
transform = Transform2D.trs(translation: centerWorld);
}