interpolate static method
- List<
CurvePoint> points, { - int targetPoints = 50,
Interpolate points for smooth curve rendering
Implementation
static List<CurvePoint> interpolate(List<CurvePoint> points,
{int targetPoints = 50}) {
if (points.length < 2) return points;
final result = <CurvePoint>[];
for (var i = 0; i < points.length - 1; i++) {
final p1 = points[i];
final p2 = points[i + 1];
// Logarithmic interpolation
final logI1 = math.log(p1.currentMultiple);
final logI2 = math.log(p2.currentMultiple);
final logT1 = math.log(p1.timeSeconds);
final logT2 = math.log(p2.timeSeconds);
final segmentPoints = (targetPoints / (points.length - 1)).round();
for (var j = 0; j < segmentPoints; j++) {
final t = j / segmentPoints;
final logI = logI1 + (logI2 - logI1) * t;
final logT = logT1 + (logT2 - logT1) * t;
result.add(CurvePoint(math.exp(logI), math.exp(logT)));
}
}
result.add(points.last);
return result;
}