-
Notifications
You must be signed in to change notification settings - Fork 142
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
Refine Hashable and Equatable on Quaternion #124
Refine Hashable and Equatable on Quaternion #124
Conversation
return self.multiplied(by: 1) | ||
} | ||
|
||
/// A "canonical transformation" representation of the value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to make this more precise. If I wasn't concerned about jargon, I would say "the canonical representative of the equivalence class of quaternions representing the same 3d transformation."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The canonical representative of quaternions with non-negative real components representing the same 3D transformation."
Does that make sense? :)
I guess that's another task to think about over the weekend.
/// - Parameter other: The value to compare. | ||
/// - Returns: True if the transformation of this quaternion equals `other`. | ||
@_transparent | ||
public func transformEquals(_ other: Quaternion) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about how this reads at a use site?
if q.transformEquals(p) { /* ... */ }
I don't love that "transform" may read as a verb if you don't know what you're looking at. What if we used something like this instead:
if q.equals(as3DTransform: p) { /* ... */ }
I'm not totally set on this either way, but let's give it some thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about how this reads at a use site?
if q.transformEquals(p) { /* ... */ }
Yeah, you are right. This can easily be misread. We could maybe use transformationEquals
to make it more explicit.
if q.equals(as3DTransform: p) { /* ... */ }
I think, I do prefer this spelling over transformEquals
/transformationEquals
. If we want to (somewhat) reuse existing naming patterns, we could utilize append(contentsOf:)
and insert(contentsOf:at:)
on Array
and use:
if q.equals(transformationOf: p) { /* ... */ }
Though, I think it is a little less obvious and does not mention 3D explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's think about this over the weekend and see if we can make a provisional decision on Monday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any further thoughts on this? If not, let's go with equals(as3DTransform:)
for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps q.isSame3DTransform(as: p)
or some such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to equals(as3DTransform:)
for now. I think, it reads a little nicer at the call site.
@markuswntr is this ready to merge from your perspective, or do you want to iterate on it more first? |
Hi @stephentyrone, as you mentioned previously, the |
Canonical Representations
Add
canonicalized
andcanonicalizedTransform
propertiesEquatable
Update type and header documentation and mention the alternative for transformations in R³
Hashable
This PR changes the hashing behavior of
Quaternion
, so that any finite quaternionq
clears the sign bit of its real component before hashing.Transform Equality
Added a new
transformEquals()
method onQuaternion
to test for 3D transformation equality.