Commit Graph

35 Commits

Author SHA1 Message Date
Christopher Durham
49906a35be
Fix glm::is_null epsilon test (#1350)
The existing implementation compares each component to zero with
an epsilon; effectively `glm::all(glm::is_comp_null(v, epsilon))`.
This probably isn't the desired semantics when calling `glm::is_null`;
rather, we want to determine if the magnitude of the vector is within
`epsilon` units of zero. It's the question of circle versus square.

This behavior matches that of OpenGL Mathematics.
2024-06-23 11:09:52 +02:00
Christopher Durham
f578181351 Fix glm::is_normalized epsilon
The existing comparison bound of $\epsilon^2$ is improperly scaled for
testing an epsilon of the squared vector magnitude. Let $\epsilon$ be
our specified epsilon and $\delta$ be the permissible delta of the
squared magnitude. Thus, for a nearly-normalized vector, we have

$$\begin{align}
\sqrt{1 + \delta} &=  1 + \epsilon        \\
          \delta  &= (1 + \epsilon)^2 - 1 \\
          \delta  &=  \epsilon^2 + 2\epsilon
\text{ .}\end{align}$$

Since we only care about small epsilon, we can assume
that $\epsilon^2$ is small and just use $\delta = 2\epsilon$. And in
fact, [this is the bound used by GLM][GLM#isNormalized] (MIT license)
... except they're using `length` and not `length2` for some reason.

[GLM#isNormalized]: b06b775c1c/glm/gtx/vector_query.inl (L102)

If we stick an epsilon of `1.0e-6` into the current implementation,
this gives us a computed delta of `1.0e-12`: smaller than the `f32`
machine epsilon, and thus no different than direct float comparison
without epsilon. This also gives an effetive epsilon of `5.0e-13`;
*much* less than the intended `1.0e-6` of intended permitted slack!
By doing a bit more algebra, we can find the effective epsilon is
$\sqrt{\texttt{epsilon}^2 + 1} - 1$. This patch makes the effective
epsilon $\sqrt{2\times\texttt{epsilon} + 1} - 1$ which still isn't
*perfect*, but it's effectively linear in the domain we care about,
only really making a practical difference above an epsilon of 10%.

TL;DR: the existing `is_normalized` considers a vector normalized if
the squared magnitude is within `epsilon*epsilon` of `1`. This is wrong
and it should be testing if it's within `2*epsilon`. This PR fixes it.

For absence of doubt, a comparison epsilon of $\texttt{epsilon}^2$ is
correct when comparing squared magnitude against zero, such as when
testing if a displacement vector is nearly zero.
2024-01-13 00:02:26 -05:00
Bruce Mitchener
136a565579 docs: Use intradoc links rather than HTML.
This fixes almost all HTML links to be intradoc links that Rust
can verify during `cargo doc`. This will help prevent future
broken links.
2023-08-06 22:34:40 +07:00
Chris Ohk
fd97a82926 fix: Correct minor typos 2023-02-01 15:48:06 +09:00
Andreas Longva
f007772f4b Update slice->view in nalgebra-glm 2022-11-14 15:18:28 +01:00
Sébastien Crozet
6165ac8dbf Fix nalgebra-glm tests. 2021-08-08 13:05:13 +02:00
Sébastien Crozet
85074398d0 Fix nalgebra-glm 2021-08-08 12:59:40 +02:00
Crozet Sébastien
24d546d3b6 Rename generic parameter N -> T 2021-04-11 13:57:54 +02:00
sebcrozet
bbb3be512e Run cargo fmt. 2020-04-05 18:49:48 +02:00
sebcrozet
426b289871 nalgebra-glm: switch to simba instead of alga. 2020-04-05 17:13:34 +02:00
sebcrozet
4ef4001836 Rename Real to RealField. 2019-03-25 11:21:41 +01:00
sebcrozet
3cbe60523a 2018 edition. 2019-03-23 14:33:47 +01:00
sebcrozet
f36ff97d6a Fix deprecation warnings. 2018-12-29 13:19:09 +01:00
sebcrozet
14ad10a7e0 Add rustfmt.toml and run it. 2018-10-27 15:00:18 +02:00
sebcrozet
b9ca074740 Execute rustfmt. 2018-10-22 06:23:40 +02:00
Bruce Mitchener
e91ed3b0cd Explain l1 and l2 norms. 2018-10-09 08:31:38 +02:00
Bruce Mitchener
0dbe69ddb7 Reformat parameter listings in docs. 2018-10-08 07:54:26 +02:00
Bruce Mitchener
e7610196b6 Add more see also content. 2018-10-08 07:54:26 +02:00
Bruce Mitchener
cb96cdb794 clippy: Prefer unwrap_or_else to unwrap_or. 2018-10-05 06:00:50 +02:00
Bruce Mitchener
a01fde5699 Add more doc linking and some doc tests. 2018-10-04 21:04:50 +02:00
Bruce Mitchener
516abbfa06 'every components' -> 'every component' 2018-10-04 05:26:21 +02:00
Bruce Mitchener
ca9b4e38dd Add more see-also content to glm docs. 2018-10-04 05:26:21 +02:00
Bruce Mitchener
a8ae62ea52 Improve cross-linking and cross-referencing in docs. 2018-09-27 06:00:32 +02:00
Bruce Mitchener
96a2a56800 Use 3 space indents to avoid triggering syntax highlighting. 2018-09-25 20:17:27 +02:00
Bruce Mitchener
175c41ed3a Typo fixes. 2018-09-24 21:15:07 +02:00
sebcrozet
b8b86e72b5 Various documentation fixes. 2018-09-23 17:10:49 +02:00
sebcrozet
4140375b6e Rename the Mat and Vec aliases to TMat and TVec. 2018-09-23 17:10:49 +02:00
sebcrozet
975e0a8b6b Add the TVec* and TMat* aliases. 2018-09-23 17:10:49 +02:00
sebcrozet
d5e747bd4a Add more 2D transformation constructors. 2018-09-23 17:10:49 +02:00
sebcrozet
f2bad264ef Re-export conversion functions. 2018-09-23 17:10:49 +02:00
sebcrozet
2a6302cd54 Fix some comments. 2018-09-23 17:10:49 +02:00
sebcrozet
cff8f398ba Resolve all name conflicts. 2018-09-23 17:10:49 +02:00
sebcrozet
1b2fc74f33 Resolve some name conflicts. 2018-09-23 17:10:49 +02:00
sebcrozet
81745b5464 Add a quat_ perfix to all quaternion functions. 2018-09-23 17:10:49 +02:00
sebcrozet
3e445430a4 Move files around and complete the doc. 2018-09-23 17:10:49 +02:00