-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clamp :ScaleTo values to be greater than zero #9
base: master
Are you sure you want to change the base?
Conversation
spr.lua
Outdated
@@ -629,7 +629,7 @@ local PSEUDO_PROPERTIES: PropertyOverride = { | |||
return inst:GetScale() | |||
end, | |||
set = function(inst: Model, value: number) | |||
inst:ScaleTo(value) | |||
inst:ScaleTo(math.clamp(value, 1e-4, math.huge)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScaleTo apparently allows any input as long as it's not zero. Can we make sure this allows the smallest possible floating point value that isn't subnormal?
We should also think about clamping at some value below infinity to avoid warnings. 2^53
should work.
ScaleTo will accept values up to 10^-45 before rounding to zero. However, if we use that as our epsilon, there are cases where value gets rounded to zero anyway (ex. when the spring sleeps). 10^-35 seems to not round to zero, so we can use that as our epsilon. |
@@ -37,6 +37,7 @@ local SLEEP_ROTATION_OFFSET = math.rad(0.01) -- rad | |||
local SLEEP_ROTATION_VELOCITY = math.rad(0.1) -- rad/s | |||
local EPS = 1e-5 -- epsilon for stability checks around pathological frequency/damping values | |||
local AXIS_MATRIX_EPS = 1e-6 -- epsilon for converting from axis-angle to matrix | |||
local SCALE_TO_EPS = 1e-35 -- epsilon used for clamping ScaleTo calls above 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a table or NumberRange? e.g. SCALE_TO_RANGE = {1e-35, 2^53}
Sometimes a spring can go over its target and call :ScaleTo with values <= 0, which results in an error. Fixed by clamping the setter to be always greater than zero.