limitTransAndScale method
limits the maximum scale and X translation of the given matrix
@param matrix
Implementation
void limitTransAndScale(Matrix4 matrix, Rect content) {
for (int i = 0; i < 16; i++) {
matrixBuffer[i] = matrix.storage[i];
}
double curTransX = matrixBuffer[12]!;
double curScaleX = matrixBuffer[0]!;
double curTransY = matrixBuffer[13]!;
double curScaleY = matrixBuffer[5]!;
// min scale-x is 1f
_scaleX = min(max(_minScaleX, curScaleX), _maxScaleX);
// min scale-y is 1f
_scaleY = min(max(_minScaleY, curScaleY), _maxScaleY);
double width = 0;
double height = 0;
width = content.width;
height = content.height;
double maxTransX = -width * (_scaleX - 1);
_transX = min(max(curTransX, maxTransX - _transOffsetX!), _transOffsetX!);
double maxTransY = height * (_scaleY - 1);
_transY = max(min(curTransY, maxTransY + _transOffsetY!), -_transOffsetY!);
matrixBuffer[12] = _transX;
matrixBuffer[0] = _scaleX;
matrixBuffer[13] = _transY;
matrixBuffer[5] = _scaleY;
for (int i = 0; i < 16; i++) {
matrix.storage[i] = matrixBuffer[i]!;
}
}