rect method
Rect
rect(
{ - required Rect startRect,
- required Rect currentRect,
})
Implementation
Rect rect({
required Rect startRect,
required Rect currentRect,
}) {
final width = startRect.width * scale;
final height = startRect.height * scale;
/// we want that the user will see the same scene of the image in the focalPoint
/// the difference of width (scale) is the difference of the distance from the focalPoint to the center of the rect
/// { rectWidth / desiredWidth == (rectCenter - focalPoint) / (desiredCenter - focalPoint) }
/// then { desiredCenter - focalPoint == (rectCenter - focalPoint) * desiredWidth / rectWidth }
/// then we add the focalPointDelta because the user also drag sometimes when scaling
if (currentRect.width == 0) return currentRect;
final center = (currentRect.center - focalPoint) * width / currentRect.width + focalPoint + focalPointDelta;
return Rect.fromCenter(
center: center,
width: width,
height: height,
);
}