Skip to content

Commit 8244763

Browse files
committed
Simplify implementation of halfAngle
1 parent 15a7c2c commit 8244763

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Sources/QuaternionModule/Polar.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,14 @@ extension Quaternion {
9191
@inlinable
9292
public var argument: RealType {
9393
guard isFinite else { return .nan }
94-
guard imaginary != .zero else {
95-
// A zero quaternion does not encode transformation properties.
96-
// If imaginary is zero, real must be non-zero or nan is returned.
97-
return real.isZero ? .nan : .zero
98-
}
99-
94+
// A zero quaternion does not encode transformation properties.
95+
// If imaginary is zero, real must be non-zero or nan is returned.
96+
guard !isReal else { return isPure ? .nan : .zero }
10097
// If lengthSquared computes without over/underflow, everything is fine
10198
// and the result is correct. If not, we have to do the computation
10299
// carefully and unscale the quaternion first.
103100
let lenSq = imaginary.lengthSquared
104-
guard lenSq.isNormal else { return divided(by: magnitude).argument }
101+
guard lenSq.isNormal else { return divided(by: magnitude).halfAngle }
105102
return .atan2(y: .sqrt(lenSq), x: real)
106103
}
107104

0 commit comments

Comments
 (0)