Distance3DSquared, LengthSquared

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Distance3DSquared, LengthSquared

Post by Gutawer »

On a bit of quick testing using MSTime, vec.length() takes roughly 6x more time to execute than vec dot vec, so certainly not free. I think it's also worth noting that in a quick-and-dirty test I did by changing the LENV3 opcode to not use a sqrt (i.e. how lengthSquared would be), it seems like a lengthSquared() method implemented the same as length() would take the same amount of execution time as vec dot vec anyway (at least down to the amount of precision I could get out of MSTime() with a lot of loops). Probably worth getting a dev to verify that, but it seems to me like it'd not offer any speedup over the dot-with-itself method.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: Distance3DSquared, LengthSquared

Post by Major Cooke »

Well, a squared Distance(2/3)D can still be of great use, so I made a thread with a PR. One of my projects relies upon this function a lot and I'd like to cut out the square root.

Return to “Feature Suggestions [GZDoom]”