interpolate method
InterpolatedResult
interpolate(
- dynamic controllerValue,
- dynamic animValue,
- dynamic interpolateBetweenPoints
Implementation
InterpolatedResult interpolate( controllerValue, animValue, interpolateBetweenPoints ) {
var thisPoint;
for( var c=lastPointIndex; c < points.length ; c++ ) {
if( animValue >= pointDistanceSteps[c].distance ) {
/// Our animation is past the next point, so add it in
/// but remove any interpolated point that we were using
if( interpolatedPoint != null ) {
builtPoints.removeLast(); // dont nec need the interpolated point any more
interpolatedPoint = null;
}
thisPoint = LatLng(points[c].latitude, points[c].longitude);
builtPoints.add(thisPoint);
lastPointIndex = c+1;
} else {
/// only need this if we want to draw inbetween points...
/// use our point steps and interpolate
if( interpolateBetweenPoints ) {
var lastPerc = pointDistanceSteps[c - 1].percent;
var nextPerc = pointDistanceSteps[c].percent;
if (nextPerc == null) break;
var perc = (controllerValue - lastPerc) / /// swap this around with not 0-1 and get rid of tweener ?
(nextPerc - lastPerc);
var intermediateLat = (points[c].latitude -
points[c - 1].latitude) * perc + points[c - 1].latitude;
var intermediateLon = (points[c].longitude -
points[c - 1].longitude) * perc + points[c - 1].longitude;
interpolatedPoint = LatLng(
intermediateLat, intermediateLon); // last tail point
if (builtPoints.length > c) {
builtPoints[c] = interpolatedPoint!;
} else {
builtPoints.add(interpolatedPoint!);
}
}
thisPoint = interpolatedPoint;
break;
}
}
if( thisPoint == null ) {
thisPoint = LatLng(points[lastPointIndex - 1].latitude,
points[lastPointIndex - 1].longitude);
}
double angle = 0.0;
if(_previousPoint != null)
if(thisPoint != null) {
angle = -atan2(thisPoint.latitude - _previousPoint?.latitude,
thisPoint.longitude - _previousPoint?.longitude ) - 4.7128 ;
}
// We do this in case we're not interpolating visually otherwise
// point and prev point are the same most of the time
if(_lastAngle == null) _lastAngle = angle;
if(thisPoint != _previousPoint) _lastAngle = angle;
//if((_lastAngle == null) || (thisPoint != _previousPoint)) _lastAngle = angle;
_previousPoint = thisPoint;
return InterpolatedResult(point: thisPoint, angle: _lastAngle, animValue: animValue,
controllerValue: controllerValue, builtPoints: builtPoints);
}