scaleForCenter function
Per-axis scaleResponse: given the rect's center on the axis, returns
the corresponding scale factor by reading the lerp between geometric
endpoints. In-display zone end = "rect's near edge touches display
edge, size = base * inDisplay.end"; past-display zone end =
"rect's far edge touches display edge, size = base * pastDisplay.end".
Implementation
double scaleForCenter({
required double center,
required double basePos,
required double baseHalfDim,
required double displayLow,
required double displayHigh,
required ScaleResponse? response,
}) {
if (response == null) return 1.0;
final isHigh = center >= basePos;
final dir = isHigh ? 1.0 : -1.0;
final dispEdge = isHigh ? displayHigh : displayLow;
final inEnd = response.inDisplay?.end ?? 1.0;
final inEndCenter = dispEdge - dir * baseHalfDim * inEnd;
final travel = (center - basePos) * dir;
final inTravel = (inEndCenter - basePos) * dir;
if (travel <= inTravel || response.pastDisplay == null) {
final p = inTravel > 0 ? (travel / inTravel).clamp(0.0, 1.0) : 0.0;
final curveP = response.inDisplay?.curve.transform(p) ?? 0.0;
return 1.0 + (inEnd - 1.0) * curveP;
}
final pastEnd = response.pastDisplay!.end;
final pastEndCenter = dispEdge + dir * baseHalfDim * pastEnd;
final pastTravel = (pastEndCenter - inEndCenter) * dir;
final p = pastTravel > 0 ? ((travel - inTravel) / pastTravel).clamp(0.0, 1.0) : 1.0;
final curveP = response.pastDisplay!.curve.transform(p);
return inEnd + (pastEnd - inEnd) * curveP;
}