nicklockwood / Euclid

A Swift library for creating and manipulating 3D geometry
MIT License
644 stars 53 forks source link

Increase type safety for angle-related API #35

Closed jkalias closed 4 years ago

jkalias commented 4 years ago

The current API relies heavily on the use of Double for angles. Even though the argument label is explicit (eg. radians), there is no type safety enforced by the compiler.

There exists already a type safe Angle implementation, however it is defined in SwiftUI (https://developer.apple.com/documentation/swiftui/angle) and therefor not suitable for this project.

I’d love to update the angle-related API to use a type safe Angle implementation based on UnitAngle of Foundation (https://developer.apple.com/documentation/foundation/unitangle). That way, it would make it appropriate for uniform use on the supported platforms (Apple, Linux) and increase the type safety of the library.

Best regards, stay healthy and stay safe

nicklockwood commented 4 years ago

@jkalias interesting idea. UnitAngle is a class rather than a value type though, which makes it slightly unappealing for high-performance use.

Perhaps I could introduce an Angle struct similar to SwiftUI's, with some bridging to UnitAngle.

jkalias commented 4 years ago

That was exactly my guess regarding the high performance requirements. I totally agree about the custom Angle struct.

I’d love to help if you feel like it.

nicklockwood commented 4 years ago

@jkalias sure, if you'd like to make a PR that would be great.

nicklockwood commented 4 years ago

Merged in develop.