wheelSegmentCrossingCount function
Number of segment boundaries a wheel passed between two unwrapped
rotations (radians). Boundaries sit every 2π / segmentCount; the
previous rotation is exclusive and the current one inclusive, so a frame
resting exactly on a boundary neither double-counts nor misses it.
Implementation
int wheelSegmentCrossingCount({
required double previousRotation,
required double currentRotation,
required int segmentCount,
}) {
if (segmentCount < 2) {
throw ArgumentError.value(segmentCount, 'segmentCount', 'must be >= 2');
}
if (!previousRotation.isFinite || !currentRotation.isFinite) {
throw ArgumentError('rotations must be finite');
}
final step = 2 * math.pi / segmentCount;
const epsilon = 1e-9;
if (currentRotation > previousRotation) {
return (currentRotation / step + epsilon).floor() -
(previousRotation / step + epsilon).floor();
}
if (currentRotation < previousRotation) {
return (previousRotation / step - epsilon).ceil() -
(currentRotation / step - epsilon).ceil();
}
return 0;
}