Simplify natural aspect ratio math
This commit is contained in:
parent
21bdb6afc1
commit
a6e6a7d741
|
@ -372,22 +372,14 @@ function Media({
|
||||||
) {
|
) {
|
||||||
$media.dataset.hasSmallDimension = true;
|
$media.dataset.hasSmallDimension = true;
|
||||||
} else {
|
} else {
|
||||||
const naturalAspectRatio = (
|
const displayNaturalHeight =
|
||||||
naturalWidth / naturalHeight
|
(naturalHeight * clientWidth) / naturalWidth;
|
||||||
).toFixed(2);
|
const almostSimilarHeight =
|
||||||
const displayAspectRatio = (
|
Math.abs(displayNaturalHeight - clientHeight) < 2;
|
||||||
clientWidth / clientHeight
|
|
||||||
).toFixed(2);
|
if (almostSimilarHeight) {
|
||||||
const similarThreshold = 0.05;
|
|
||||||
if (
|
|
||||||
naturalAspectRatio === displayAspectRatio ||
|
|
||||||
Math.abs(naturalAspectRatio - displayAspectRatio) <
|
|
||||||
similarThreshold
|
|
||||||
) {
|
|
||||||
// $media.dataset.hasNaturalAspectRatio = true;
|
|
||||||
setHasNaturalAspectRatio(true);
|
setHasNaturalAspectRatio(true);
|
||||||
}
|
}
|
||||||
// $media.dataset.aspectRatios = `${naturalAspectRatio} ${displayAspectRatio}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue