Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gIaceon
Copy link

@gIaceon gIaceon commented Sep 20, 2023

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.

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))
Copy link
Owner

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.

@gIaceon
Copy link
Author

gIaceon commented Sep 24, 2023

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
Copy link
Owner

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants