scale property
double
get
scale
Calculates the scale factor for transformations.
This getter computes the appropriate scale factor based on the current body and image sizes, taking into account rotation and cropping configurations.
Returns:
- A double representing the scale factor used to transform the image within the editor body.
Implementation
double get scale {
if (mainBodySize.isEmpty) return 1;
Size imageSize = transformConfigs?.is90DegRotated == true
? mainImageSize.flipped
: mainImageSize;
double? cropRectRatio =
transformConfigs != null && transformConfigs!.isNotEmpty
? transformConfigs?.cropRect.size.aspectRatio
: null;
if (transformConfigs?.is90DegRotated == true) {
cropRectRatio = 1 / cropRectRatio!;
}
double scaleW = editorBodySize.width / mainBodySize.width;
double scaleH = editorBodySize.height / mainBodySize.height;
double scaleOldDifferenceW = mainBodySize.width / imageSize.width;
double scaleOldDifferenceH = mainBodySize.height / imageSize.height;
bool stickOnHeightOld =
mainBodySize.aspectRatio > (cropRectRatio ?? imageSize.aspectRatio);
bool stickOnHeightNew =
editorBodySize.aspectRatio > (cropRectRatio ?? imageSize.aspectRatio);
double scaleStickSize = stickOnHeightNew != stickOnHeightOld
? (stickOnHeightOld ? scaleOldDifferenceW : scaleOldDifferenceH)
: 1;
double scaleImgSize = stickOnHeightNew ? scaleH : scaleW;
return scaleImgSize * scaleStickSize;
}