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

Quaternion Documentation: Describe edge cases #87422

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

Conversation

0awful
Copy link

@0awful 0awful commented Jan 20, 2024

Working on the Rust GDExt library I became aware of how the edge cases for quaternions are handled. I believe exposing this may help future library authors/maintainers work with the engine.

@0awful 0awful requested a review from a team as a code owner January 20, 2024 20:36
@AThousandShips AThousandShips added this to the 4.x milestone Jan 20, 2024
@AThousandShips
Copy link
Member

See also:

Co-authored-by: A Thousand Ships <[email protected]>
@0awful
Copy link
Author

0awful commented Jan 20, 2024

Having become aware of #87181. I'm not seeing any specific discrepancies between the two. However one is a significantly larger changeset. I believe this PR, being the smaller one, should bear the responsibility of handling merge conflicts.

@@ -39,7 +39,8 @@
<param index="0" name="axis" type="Vector3" />
<param index="1" name="angle" type="float" />
<description>
Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
Constructs a quaternion that will rotate around the given axis by the specified angle.
[b]Note:[/b] The axis must be a normalized vector. Returns [code](0, 0, 0, 1)[/code] if your vector is not normalized in Debug mode. Returns the quaternion that would have been generated by normalizing the axis in release mode. If the axis has length [code]0[/code] and therefore cannot be normalized returns [code](0, 0, 0, 0)[/code]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do trust that this is all correct, as it is way out of my expertise. I heavily appreciate the extra detail.

However, the way this entire note and others are structured in this PR is extremely inconsistent and kind of "not good" for several reasons:

  • (0, 0, 0, 1) is the IDENTITY Quaternion and should be referred to as such (Returns [constant IDENTITY]) to point users in the right direction, as it is not an arbitrary, magic value.
  • "Debug" in "debug mode" is never capitalized across the entire class reference. Saying "debug builds" is also more common in this context.
  • The whole note is extremely verbose. "Debug build" and "release build" are mutually exclusive, so there's almost no need to define both.
    • It also feels like the behavior in debug builds is the exception and not the norm, as the following sentence implies nothing wrong really happens when the axis is not normalized:
      "Returns the quaternion that would have been generated by normalizing the axis in release mode."
      This means that it's only worth noting the more "unusual" behavior in debug builds.
    • There's also little point in saying "and therefore cannot be normalized" because users interacting with a Quaternion should already have a decent understanding of vector math.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the feedback. I'll make those modifications. Great work on your documentation improvements by the way.

@@ -164,7 +166,7 @@
<param index="1" name="weight" type="float" />
<description>
Returns the result of the spherical linear interpolation between this quaternion and [param to] by amount [param weight].
[b]Note:[/b] Both quaternions must be normalized.
[b]Note:[/b] Both quaternions must be normalized. Returns [code](0, 0, 0, 1)[/code] if any quaternion is not normalized in debug mode. Returns [code]self[/code] if any quaternion is not normalized in release mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is a GDScript-exclusive context and it only applies to Object, because all other Variant types cannot be extended.

In this situation the class reference likes to say, for example "Returns this quaternion unchanged" or "Returns the quaternion without changes" or similar.

@Mickeon
Copy link
Contributor

Mickeon commented Mar 6, 2024

#87181 has been merged a while ago. Is this PR still necessary? Could it be rebased?

@@ -39,7 +39,8 @@
<param index="0" name="axis" type="Vector3" />
<param index="1" name="angle" type="float" />
<description>
Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
Constructs a quaternion that will rotate around the given axis by the specified angle.
[b]Note:[/b] The axis must be a normalized vector. Returns [code](0, 0, 0, 1)[/code] if your vector is not normalized in Debug mode. Returns the quaternion that would have been generated by normalizing the axis in release mode. If the axis has length [code]0[/code] and therefore cannot be normalized returns [code](0, 0, 0, 0)[/code]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[b]Note:[/b] The axis must be a normalized vector. Returns [code](0, 0, 0, 1)[/code] if your vector is not normalized in Debug mode. Returns the quaternion that would have been generated by normalizing the axis in release mode. If the axis has length [code]0[/code] and therefore cannot be normalized returns [code](0, 0, 0, 0)[/code]
[b]Note:[/b] The axis must be a normalized vector. Returns [code](0, 0, 0, 1)[/code] if your vector is not normalized in Debug mode. Returns the quaternion that would have been generated by normalizing the axis in release mode. If the axis has length [code]0[/code] and therefore cannot be normalized returns [code](0, 0, 0, 0)[/code].

@mhilbrunner
Copy link
Member

mhilbrunner commented Apr 7, 2024

@0awful Any chance of a rebase and adding the missing "."? 🙏If this is still needed after #87181. Otherwise this looks good to me.

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

Successfully merging this pull request may close these issues.

4 participants