DLAngle

1.0.1

Provides an abstraction for mathematical angle written in Swift 4.

DLAngle v1.0.1

2018-03-25T10:17:13Z

Update deployment target to 10.12 for macOS.

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.

Usage

Importing the module

You can import this module using:

import DLAngle

Creation

let degree = Degree(rawValue: 90.0)
let zeroDegrees = Degree()

let degree = Degree(rawValue: 90.0)

Basic Operations

// radian.rawValue = 3 * Double.pi / 4

Subtraction

var degrees = Degree(radians: Double.pi / 2)
degrees = degrees - Degree(radians: Double.pi / 6)
// degrees.rawValue = 60.0

Multiplcation

let half = Radian(rawValue: Double.pi / 2)
let pi = one * 2
// '2 * one' works as well

Division

let sixtyDegreesRadian = one / 3
// '1 / pi' works as well

Normalization

let 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.pi

Equality

angle1 == angle2 // true

Comparison

angle1 < angle2 // false

Foundation.Measurement conversion

let angleMeasurement = Measurement<UnitAngle>(value: 45.0, unit: .degrees)
let degrees = Degrees(measurement: angleMeasurement)
degrees.measurement // Measurement<UnitAngle>(value: 45.0, unit: .degrees)

Inverse trigonometric functions

Inverse functions are provided by using convenience constructors of Radian type.

do {
let angle = try Radian(acos: -1.0)
} catch {
// handle error
}

Trigonometric functions

if let sin: Double = try? angle.sin() {
// use computed sine value
}

Constants

Frequently used Radian angles have constants:

Installation

Supported Operating Systems

• 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

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.

pod 'DLAngle'

3. Swift Package Manager

dependencies: [
]

targets: [
.target(
name: "YourTargetName",
dependencies: ["DLAngle"])),
]

Contribution

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.