mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Remove rounding operations
This commit is contained in:
@@ -3052,20 +3052,8 @@ module.exports = {
|
||||
/**
|
||||
* Applies ratio to value without intermediary value to avoid precision issues.
|
||||
*/
|
||||
applyRatio({
|
||||
oldReferenceValue,
|
||||
newReferenceValue,
|
||||
valueToApplyTo,
|
||||
precision = 0,
|
||||
}) {
|
||||
const newValue =
|
||||
(newReferenceValue / oldReferenceValue) *
|
||||
valueToApplyTo *
|
||||
10 ** precision;
|
||||
const roundedNewValue = Math.round(newValue);
|
||||
if (Math.abs(roundedNewValue - newValue) < 0.001)
|
||||
return roundedNewValue / 10 ** precision;
|
||||
return newValue / 10 ** precision;
|
||||
applyRatio({ oldReferenceValue, newReferenceValue, valueToApplyTo }) {
|
||||
return (newReferenceValue / oldReferenceValue) * valueToApplyTo;
|
||||
}
|
||||
|
||||
_updateDefaultTransformation(
|
||||
@@ -3153,42 +3141,50 @@ module.exports = {
|
||||
modelDepth < epsilon
|
||||
? Number.POSITIVE_INFINITY
|
||||
: originalDepth / modelDepth;
|
||||
let minScaleRatio = Math.min(widthRatio, heightRatio, depthRatio);
|
||||
const minScaleRatio = Math.min(widthRatio, heightRatio, depthRatio);
|
||||
if (!Number.isFinite(minScaleRatio)) {
|
||||
this._defaultWidth = modelWidth;
|
||||
this._defaultHeight = modelHeight;
|
||||
this._defaultDepth = modelDepth;
|
||||
} else {
|
||||
let oldReferenceValue, newReferenceValue;
|
||||
if (widthRatio === minScaleRatio) {
|
||||
oldReferenceValue = modelWidth;
|
||||
newReferenceValue = originalWidth;
|
||||
this._defaultWidth = originalWidth;
|
||||
this._defaultHeight = this.applyRatio({
|
||||
oldReferenceValue: modelWidth,
|
||||
newReferenceValue: originalWidth,
|
||||
valueToApplyTo: modelHeight,
|
||||
});
|
||||
this._defaultDepth = this.applyRatio({
|
||||
oldReferenceValue: modelWidth,
|
||||
newReferenceValue: originalWidth,
|
||||
valueToApplyTo: modelDepth,
|
||||
});
|
||||
} else if (heightRatio === minScaleRatio) {
|
||||
oldReferenceValue = modelHeight;
|
||||
newReferenceValue = originalHeight;
|
||||
} else {
|
||||
oldReferenceValue = modelDepth;
|
||||
newReferenceValue = originalDepth;
|
||||
}
|
||||
this._defaultWidth = this.applyRatio({
|
||||
oldReferenceValue: modelHeight,
|
||||
newReferenceValue: originalHeight,
|
||||
valueToApplyTo: modelWidth,
|
||||
});
|
||||
|
||||
this._defaultWidth = this.applyRatio({
|
||||
oldReferenceValue,
|
||||
newReferenceValue,
|
||||
valueToApplyTo: modelWidth,
|
||||
precision: 1,
|
||||
});
|
||||
this._defaultHeight = this.applyRatio({
|
||||
oldReferenceValue,
|
||||
newReferenceValue,
|
||||
valueToApplyTo: modelHeight,
|
||||
precision: 1,
|
||||
});
|
||||
this._defaultDepth = this.applyRatio({
|
||||
oldReferenceValue,
|
||||
newReferenceValue,
|
||||
valueToApplyTo: modelDepth,
|
||||
precision: 1,
|
||||
});
|
||||
this._defaultHeight = originalHeight;
|
||||
this._defaultDepth = this.applyRatio({
|
||||
oldReferenceValue: modelHeight,
|
||||
newReferenceValue: originalHeight,
|
||||
valueToApplyTo: modelDepth,
|
||||
});
|
||||
} else {
|
||||
this._defaultWidth = this.applyRatio({
|
||||
oldReferenceValue: modelDepth,
|
||||
newReferenceValue: originalDepth,
|
||||
valueToApplyTo: modelWidth,
|
||||
});
|
||||
this._defaultHeight = this.applyRatio({
|
||||
oldReferenceValue: modelDepth,
|
||||
newReferenceValue: originalDepth,
|
||||
valueToApplyTo: modelHeight,
|
||||
});
|
||||
this._defaultDepth = originalDepth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,19 +33,12 @@ const applyRatio = ({
|
||||
oldReferenceValue,
|
||||
newReferenceValue,
|
||||
valueToApplyTo,
|
||||
precision = 0,
|
||||
}: {|
|
||||
oldReferenceValue: number,
|
||||
newReferenceValue: number,
|
||||
valueToApplyTo: number,
|
||||
precision?: number,
|
||||
|}) => {
|
||||
const newValue =
|
||||
(newReferenceValue / oldReferenceValue) * valueToApplyTo * 10 ** precision;
|
||||
const roundedNewValue = Math.round(newValue);
|
||||
if (Math.abs(roundedNewValue - newValue) < 0.001)
|
||||
return roundedNewValue / 10 ** precision;
|
||||
return newValue / 10 ** precision;
|
||||
return (newReferenceValue / oldReferenceValue) * valueToApplyTo;
|
||||
};
|
||||
|
||||
const getEditObjectButton = ({
|
||||
@@ -239,7 +232,6 @@ const getWidthField = ({
|
||||
instance.setCustomWidth(newWidth);
|
||||
instance.setCustomHeight(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialWidth,
|
||||
newReferenceValue: newWidth,
|
||||
valueToApplyTo: getInstanceHeight(instance),
|
||||
@@ -247,7 +239,6 @@ const getWidthField = ({
|
||||
);
|
||||
instance.setCustomDepth(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialWidth,
|
||||
newReferenceValue: newWidth,
|
||||
valueToApplyTo: getInstanceDepth(instance),
|
||||
@@ -296,7 +287,6 @@ const getHeightField = ({
|
||||
const initialHeight = getInstanceHeight(instance) || 1;
|
||||
instance.setCustomWidth(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialHeight,
|
||||
newReferenceValue: newHeight,
|
||||
valueToApplyTo: getInstanceWidth(instance),
|
||||
@@ -305,7 +295,6 @@ const getHeightField = ({
|
||||
instance.setCustomHeight(newHeight);
|
||||
instance.setCustomDepth(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialHeight,
|
||||
newReferenceValue: newHeight,
|
||||
valueToApplyTo: getInstanceDepth(instance),
|
||||
@@ -354,7 +343,6 @@ const getDepthField = ({
|
||||
const initialDepth = getInstanceDepth(instance) || 1;
|
||||
instance.setCustomWidth(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialDepth,
|
||||
newReferenceValue: newDepth,
|
||||
valueToApplyTo: getInstanceWidth(instance),
|
||||
@@ -362,7 +350,6 @@ const getDepthField = ({
|
||||
);
|
||||
instance.setCustomHeight(
|
||||
applyRatio({
|
||||
precision: 2,
|
||||
oldReferenceValue: initialDepth,
|
||||
newReferenceValue: newDepth,
|
||||
valueToApplyTo: getInstanceHeight(instance),
|
||||
|
Reference in New Issue
Block a user