Provides an abstraction for mathematical angle. Because the angle is a type, errors such as:
- sum or subtract a degree angle with a radian angle
- pass degree angle to a trigonometric function from standard library
are either not possible or catched at compile time. Support convenience initializers, operators and functions for natural, fast and productive workflow.
You can import this module using:
import DLAnglelet degree = Degree(rawValue: 90.0)
let zeroDegrees = Degree()
let radian = Radian(rawValue: Double.pi / 2)
let zeroRadians = Radian()From Degree to Radian:
let degree = Degree(rawValue: 90.0)
let radian = Radian(degree: degree)From Radian to Degree:
let radian = Radian(rawValue: Double.pi)
let degree = Degree(radian: radian)Addition
let radian = Radian(degrees: 90.0)
radian += Radian(degress: 45.0)
// radian.rawValue = 3 * Double.pi / 4Subtraction
var degrees = Degree(radians: Double.pi / 2)
degrees = degrees - Degree(radians: Double.pi / 6)
// degrees.rawValue = 60.0Multiplcation
let half = Radian(rawValue: Double.pi / 2)
let pi = one * 2
// '2 * one' works as wellDivision
let pi = Radian(rawValue: Double.pi)
let sixtyDegreesRadian = one / 3
// '1 / pi' works as welllet degree = Degree(rawValue: 750.0)
degree.normalize()
// degree.rawValue = 30.0
let angle1 = Radian(rawvalue: 7 * Double.pi)
let angle2 = angle1.normalized()
// angle2.rawValue = Double.pilet angle1 = Radian(rawValue: Double.pi)
let angle2 = Radian(degrees: 180.0)
angle1 == angle2 // truelet angle1 = Radian(rawValue: Double.pi)
let angle2 = Radian(degrees: 90.0)
angle1 < angle2 // falselet angleMeasurement = Measurement<UnitAngle>(value: 45.0, unit: .degrees)
let radian = Radian(measurement: angleMeasurement)
radian.measurement // Measurement<UnitAngle>(value: Double.pi / 4, unit: .radians)
let degrees = Degrees(measurement: angleMeasurement)
degrees.measurement // Measurement<UnitAngle>(value: 45.0, unit: .degrees)Inverse functions are provided by using convenience constructors of Radian type.
do {
let angle = try Radian(acos: -1.0)
} catch {
// handle error
}let angle = Radian(degrees: 45.0)
if let sin: Double = try? angle.sin() {
// use computed sine value
}Frequently used Radian angles have constants:
let pi = Radian.pi
let half_quadrant_II = Radian.pi_2 + Radian.pi_4- macOS 10.12 and later
- iOS 10.0 and later
- watchOS 3.0 and later
- tvOS 10.0 and later
- Ubuntu - check official site to find which versions support Swift 4.0.
1. Carthage
github "davidlivadaru/DLAngle"
If you need the framework only for a single OS, then I propose to use --platform [iOS|macOS|watchOS|tvOS] specifier when your perform carthage update.
2. CocoaPods
Add the dependency in your Podfile.
pod 'DLAngle'
Add the the following dependecy in your Package.swift:
dependencies: [
.package(url: "https://github.com/davidlivadaru/DLAngle.git", .upToNextMajor(from: "1.0.0"))
]
and update your target's dependencies:
targets: [
.target(
name: "YourTargetName",
dependencies: ["DLAngle"])),
]
Module is covered by unit tests, however, bugs always slip through. If you find a bug in the module create an issue.
If you want to contribute on fixing bugs or implementing new features then create a pull request.
DLAngle is released under MIT license. See LICENSE for details.
