addPoint method
Adds imagePoint to the stroke in flight. False when the sample is
dropped for coming too soon or too close to the last one.
Implementation
bool addPoint(Offset imagePoint) {
final now = clock.now().millisecondsSinceEpoch;
if (now - _lastInputMs < _inputThrottleMs) return false;
final scale = _activeCameraScale;
final filter =
(_filterDistance[currentBrush] ?? 8.0) /
(scale.abs() < 1e-6 ? 1.0 : scale.abs());
if (_previousPosition != null) {
final d = (imagePoint - _previousPosition!).distance;
if (d < filter) return false;
}
_lastInputMs = now;
var velocity = 0.0;
if (_previousPosition != null && now > _previousTimestampMs) {
final d = (imagePoint - _previousPosition!).distance;
final dt = (now - _previousTimestampMs).toDouble();
velocity = d / dt * 1000.0;
velocity = velocity * 0.3 + _previousVelocity * 0.7;
}
final thickness = _brushThicknessImageSpace;
var width = currentBrush == BrushType.eraser
? thickness
: _velocityWidth(thickness, velocity);
width = width * 0.3 + _previousWidth * 0.7;
_previousPosition = imagePoint;
_previousTimestampMs = now;
_previousVelocity = velocity;
_previousWidth = width;
currentPoints.add(
StrokePoint(position: imagePoint, velocity: velocity, width: width),
);
notifyListeners();
return true;
}