computeScaledDimensions static method

List<double> computeScaledDimensions(
  1. Texture texture,
  2. Camera camera,
  3. double textureScale,
  4. bool cover,
)

Implementation

static List<double> computeScaledDimensions(Texture texture, Camera camera, double textureScale, bool cover) {
  // return some default values if the image hasn't loaded yet
  if (texture.image == null) {
    return [1, 1];
  }

  // return if it's a video and if the video hasn't loaded yet
  if (Texture is VideoTexture && texture.image.width == 0 && texture.image.height == 0) {//if (texture.image.videoWidth == 0 && texture.image.videoHeight == 0) {
    return [1, 1];
  }

  final sourceWidth = texture.image.width;// ?? texture.image.videoWidth ?? texture.image.clientWidth;
  final sourceHeight = texture.image.height;// ?? texture.image.videoHeight ?? texture.image.clientHeight;

  final double ratio = sourceWidth / sourceHeight;
  final ratioCamera = getCameraRatio(camera);
  final widthCamera = 1;
  final heightCamera = widthCamera * (1 / ratioCamera);
  double widthScaled;
  double heightScaled;
  if (cover ? ratio > ratioCamera : ratio < ratioCamera) {
    final width = heightCamera * ratio;
    widthScaled = 1 / ((width / widthCamera) * textureScale);
    heightScaled = 1 / textureScale;
  } else {
    final height = widthCamera * (1 / ratio);
    heightScaled = 1 / ((height / heightCamera) * textureScale);
    widthScaled = 1 / textureScale;
  }

  return [widthScaled, heightScaled];
}