However is_zero_approx still evaluates to false with values of 0.00001525878906. If I want to change this I have to do something like this:
const EPSILON: float = 0.001
# then in my code
if some_value < EPSILON:
# some code here
However, is_zero_approx as a built in function feels so much cleaner.
So can I change the internal epsilon value at which it considers a small float value as 0? Perhaps in the project settings somewhere? I have looked but cannot find anything in the editor nor in the docs.
I just noticed that the docs mention is_equal_approx too:
I just tried this and it seems too insensitive for my particular use case:
if is_equal_approx(max_speed, velocity.length()):
# some code here
At my magnitudes it seems to return false at around 0.03, which is a bit too insensitive for my requirements.
I suppose the internal epsilon is probably used all over the place internally so you cannot change it or set it. So I will have to set my own EPSILON constant and just test against that. The inbuilt function is so much easier to read though I would really prefer to use either of the two is_zero_approx or is_equal_approx.
Is there a better way to do this or to set an epsilon for the internal functions?
You would need to customize the engine or write your own function within your project. It is compiled with a specific EPSILON in the engine that has too much precision for your example:
It might even be worth a PR to add another function to the engine that allows a provided EPSILON.
Now I get the 2, 3 and 12, but why would you want the square root of 13?
I don’t think I will change the engine though and I think not many people would want to fiddle with the EPSILON setting just change the sensitivity of two functions. So I have decided that ‘is_equal_approx’ is good enough. I tried all three, my own EPSILON, and the two inbuilt methods and is_equal_approx will do the job near enough.
Thank you for showing it to me in the actual engine files, much appreciated!
PS I will probably loose an hour or two now rummaging around in those files. It is jaw dropping how much work has gone into this engine. So much code, written beautifully, and so much of it still unfathomable to me! Makes me feel like such an amateur!
Of course. It is used for a test to check limit length for a vector3 (and clamp). I actually thought the SQRT13 was the square root of 13. But it is the square root of 1/3. So the length of a vector3 with all values set to SQRT13 should be 1. (Which is compared to a vector(10, 10, 10) with its length limited to 1, to test if limit length is working as expected)
Ok, thankyou, you were right again and now that makes perfect sense.
PS Although it took me a lot longer to work out than it probably should have done! Especially since the sqrt of 13 is 3.6… I could not for the life of me think why you would want the root of 13! Now I know, you don’t. Now I am left pondering why I thought the square root of 12 would be useful… Pfff who knows.
I saw SQRT12 and initially thought it was the 12th root of 2, which is useful if you’re doing music playback; that would be what you multiply a frequency by to increase the pitch by one semitone (assuming you’re using even tempering, IIRC, there’s a whole rabbit hole here…), but then I saw it was half of root 2.
IIRC SQRT3 is kind of important for regularly tiled hexagons.