rotateSymbolCommand function
The Rotate step for instance (D7), or null when nothing changes.
Implementation
CompoundCommand? rotateSymbolCommand(
DraftDocument doc, Handle instance, double degrees) {
final node = doc.tree[instance];
if (node is! InstanceNode || !degrees.isFinite) return null;
final def = doc.tree.definition(node.definition);
if (def == null) return null;
// Already there, within the field's display step: the shown value
// committed again is nothing.
var diff = (degrees - rotationDegreesOf(node.transform)) % 360;
if (diff < 0) diff += 360;
final steps = diff * kRotationStepsPerDegree;
if (steps < 1 || steps > 360 * kRotationStepsPerDegree - 1) return null;
final next = rotatedTo(node.transform, def.basePoint, degrees);
if (_same(next, node.transform)) return null;
return CompoundCommand([TransformNodeCommand(instance, next)],
label: 'Rotate');
}