Skip to content

Commit

Permalink
Merge pull request #56 from dn-m/double-init
Browse files Browse the repository at this point in the history
Add init(_ value: Double) to NoteNumberRepresentable types
  • Loading branch information
jsbean authored Aug 21, 2018
2 parents 45fad9a + 0527eaa commit b13ad7f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
19 changes: 19 additions & 0 deletions Sources/Pitch/Documentation/.jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
theme: fullwidth
custom_categories:
- name: "Basic Types"
children:
- "NoteNumber"
- "Frequency"
- "Pitch"
- name: "Collections"
children:
- "Dyad"
- "Collection"
- "intervals"
- "dyads"
- name: "Intervals"
children:
- "OrderedInterval"
- "UnorderedInterval"
- name: "Tuning Systems"
children:
- "TuningSystem"
2 changes: 1 addition & 1 deletion Sources/Pitch/Frequency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Math
/// **Example Usage**
///
/// let nice = Frequency(440.0) // => "a 440"
/// let mean: Frequency = 440.0
/// let mean: Frequency = 440.0 // => "a 440"
///
public struct Frequency: NewType, SignedNumeric {

Expand Down
16 changes: 11 additions & 5 deletions Sources/Pitch/NoteNumberRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ public protocol NoteNumberRepresentable:

// MARK: - Initializers

/// Create a `NoteNumberRepresentable` value with `NoteNumber`.
/// Create a `NoteNumberRepresentable` value with given `NoteNumber`.
init(_ noteNumber: NoteNumber)
}

extension NoteNumberRepresentable {

// MARK: - NewType
// MARK: - Initializers

/// Create a `NoteNumberRepresentable` value with given `NoteNumber`.
public init(value: NoteNumber) {
self.init(value)
}

/// Creates a `NoteNumberRepresentable`-conforming type value with the given `Double` value.
public init(_ value: Double) {
self.init(NoteNumber(value))
}

/// Creates a `NoteNumberRepresentable`-conforming type value with another.
public init <N> (_ value: N) where N: NoteNumberRepresentable {
self.init(value.value)
Expand All @@ -45,7 +51,7 @@ extension NoteNumberRepresentable {

extension NoteNumberRepresentable {

// MARK: - `Hashable`
// MARK: - Hashable

/// - Returns: The hash value of a `NoteNumberRepresentable` type.
public var hashValue: Int {
Expand All @@ -55,7 +61,7 @@ extension NoteNumberRepresentable {

extension NoteNumberRepresentable {

// MARK: - `Equatable`
// MARK: - Equatable

/// - Returns: `true` if both values are representable by the same `NoteNumber`.
/// Otherwise, `false`.
Expand All @@ -66,7 +72,7 @@ extension NoteNumberRepresentable {

extension NoteNumberRepresentable {

// MARK: - `Comparable`
// MARK: - Comparable

/// - Returns: `true` if the first value is less than the second value. Otherwise, `false`.
public static func < (lhs: Self, rhs: Self) -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Pitch/OrderedInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
/// The ordered interval between two `NoteNumberRepresentable`-conforming type values.
public struct OrderedInterval <Element: NoteNumberRepresentable>: NoteNumberRepresentable {

/// MARK: - Instance Properties
// MARK: - Instance Properties

/// The underlying `NoteNumber` value for this `OrderedInterval`.
public let value: NoteNumber

/// MARK: - Initializers
// MARK: - Initializers

/// Creates an `OrderedInterval` with the given `noteNumber` value.
public init(_ noteNumber: NoteNumber) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Pitch/UnorderedInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Algorithms
/// The unordered interval between two `NoteNumberRepresentable`-conforming type values.
public struct UnorderedInterval <Element: NoteNumberRepresentable>: NoteNumberRepresentable {

/// MARK: - Instance Properties
// MARK: - Instance Properties

/// The underlying `NoteNumber` value for this `UnorderedInterval`.
public let value: NoteNumber

/// MARK: - Initializers
// MARK: - Initializers

/// Creates an `UnorderedInterval` with the given `noteNumber` value.
public init(_ noteNumber: NoteNumber) {
Expand Down

0 comments on commit b13ad7f

Please sign in to comment.