Skip to content

Commit bad87dc

Browse files
markuswntrstephentyrone
authored andcommitted
Change hashing behavior of Quaternion to use the canonical form
1 parent 993d23a commit bad87dc

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

Sources/QuaternionModule/Quaternion.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,13 @@ extension Quaternion: Hashable {
446446
// representation. The correct behavior for zero falls out for free from
447447
// the hash behavior of floating-point, but we need to use a
448448
// representative member for any non-finite values.
449-
// For any values not zero and infinity we use a canonical form, so
450-
// that q and -q hash to the same value. This allows people who are using
449+
// For any normal values we use the "canonical transform" representation,
450+
// where real is always non-negative. This allows people who are using
451451
// quaternions as rotations to get the expected semantics out of collections
452452
// (while unfortunately producing some collisions for people who are not,
453453
// but not in too catastrophic of a fashion).
454454
if isFinite {
455-
let absolute = SIMD4(
456-
x: abs(components[0]),
457-
y: abs(components[1]),
458-
z: abs(components[2]),
459-
w: abs(components[3]))
460-
absolute.hash(into: &hasher)
455+
transformCanonicalized.hash(into: &hasher)
461456
} else {
462457
hasher.combine(RealType.infinity)
463458
}

0 commit comments

Comments
 (0)