softCP static method
Offset
softCP(
- OffsetPoint current, {
- OffsetPoint? previous,
- OffsetPoint? next,
- bool reverse = false,
- double smoothing = 0.65,
Calculates current
point based on previous
and next
control points.
Implementation
static Offset softCP(OffsetPoint current,
{OffsetPoint? previous,
OffsetPoint? next,
bool reverse = false,
double smoothing = 0.65}) {
assert(smoothing >= 0.0 && smoothing <= 1.0);
previous ??= current;
next ??= current;
final sharpness = 1.0 - smoothing;
final dist1 = previous.distanceTo(current);
final dist2 = current.distanceTo(next);
final dist = dist1 + dist2;
final dir1 = current.directionTo(next);
final dir2 = current.directionTo(previous);
final dir3 =
reverse ? next.directionTo(previous) : previous.directionTo(next);
final velocity =
(dist * 0.3 / (next.timestamp - previous.timestamp)).clamp(0.5, 3.0);
final ratio = (dist * velocity * smoothing)
.clamp(0.0, (reverse ? dist2 : dist1) * 0.5);
final dir =
((reverse ? dir2 : dir1) * sharpness) + (dir3 * smoothing) * ratio;
final x = current.dx + dir.dx;
final y = current.dy + dir.dy;
return Offset(x, y);
}