tarcieri / micromath

Embedded Rust arithmetic, 2D/3D vector, and statistics library
Apache License 2.0
402 stars 21 forks source link

Add magnitude_sq function to support non-f32 #118

Closed sunsided closed 2 months ago

sunsided commented 4 months ago

Extracted from #114, this provides the magnitude_sq function that calculates the squared magnitude of a vector (e.g. as the squared Euclidean distance between two points). This function is useful in general to speed up relative comparisons where taking the square root isn't strictly necessary, e.g. sorting by distance, as the square root function is monotonic and therefore doesn't change the outcome.

This also allows for C: Component types that re not Into<f32> to partially calculate the vector norm, as the current magnitude function is strictly limited to f32 results.