-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cassowary: improve some documentation coverage
This cleans up some of the markers and adds a trivial amount of documentation coverage.
- Loading branch information
Showing
9 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,71 @@ | ||
// Copyright © 2019 Saleem Abdulrasool <[email protected]>. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
/// The constraint cannot be satisfied. | ||
public struct UnsatisfiableConstraint: Error { | ||
private let constraint: Constraint | ||
public init(_ constraint: Constraint) { | ||
self.constraint = constraint | ||
} | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension UnsatisfiableConstraint: CustomStringConvertible { | ||
public var description: String { | ||
return "unable to satisfy constraint: \(constraint)" | ||
} | ||
} | ||
|
||
/// The constraint is not currently in the system. | ||
public struct UnknownConstraint: Error { | ||
private let constraint: Constraint | ||
public init(_ constraint: Constraint) { | ||
self.constraint = constraint | ||
} | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension UnknownConstraint: CustomStringConvertible { | ||
public var description: String { | ||
return "unknown constraint: \(constraint)" | ||
} | ||
} | ||
|
||
/// The constraint is already in the system. | ||
public struct DuplicateConstraint: Error { | ||
private let constraint: Constraint | ||
public init(_ constraint: Constraint) { | ||
self.constraint = constraint | ||
} | ||
} | ||
|
||
// MARK: - CustomStringConvertible | ||
|
||
extension DuplicateConstraint: CustomStringConvertible { | ||
public var description: String { | ||
return "duplicate constraint: \(constraint)" | ||
} | ||
} | ||
|
||
/// The edit variable is not in the system. | ||
public struct UnknownEditVariable: Error { | ||
public init(_ variable: Variable) { | ||
} | ||
} | ||
|
||
/// The edit variable is already in the system. | ||
public struct DuplicateEditVariable: Error { | ||
public init(_ variable: Variable) { | ||
} | ||
} | ||
|
||
/// The required strength is invalid. | ||
public struct BadRequiredStrength: Error { | ||
} | ||
|
||
/// An internal solver error occurred. | ||
internal struct InternalSolverError: Error { | ||
public init(_ message: String) { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
// Copyright © 2019 Saleem Abdulrasool <[email protected]>. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
// MARK - epsilon check | ||
// MARK: - epsilon check | ||
|
||
infix operator ~= | ||
|
||
public func ~= (_ lhs: Double, _ rhs: Double) -> Bool { | ||
let epsilon: Double = 1.0e-8 | ||
return abs(lhs - rhs) <= epsilon | ||
} | ||
|
||
// MARK - expression operations | ||
// MARK: - expression operations | ||
|
||
public prefix func - (_ expression: Expression) -> Expression { | ||
return expression * -1.0 | ||
|
@@ -56,7 +57,7 @@ public func / (_ expression: Expression, _ denominator: Double) -> Expression { | |
return expression * (1.0 / denominator) | ||
} | ||
|
||
// MARK - term operations | ||
// MARK: - term operations | ||
|
||
public prefix func - (_ term: Term) -> Term { | ||
return term * -1.0 | ||
|
@@ -102,7 +103,7 @@ public func / (_ term: Term, _ denominator: Double) -> Term { | |
return term * (1.0 / denominator) | ||
} | ||
|
||
// MARK - variable operations | ||
// MARK: - variable operations | ||
|
||
public prefix func - (_ variable: Variable) -> Term { | ||
return variable * -1.0 | ||
|
@@ -148,7 +149,7 @@ public func / (_ variable: Variable, _ denominator: Double) -> Term { | |
return variable * (1.0 / denominator) | ||
} | ||
|
||
// MARK - double operations | ||
// MARK: - double operations | ||
|
||
public func + (_ lhs: Double, _ rhs: Expression) -> Expression { | ||
return rhs + lhs | ||
|
@@ -186,7 +187,7 @@ public func * (_ coefficient: Double, _ variable: Variable) -> Term { | |
return variable * coefficient | ||
} | ||
|
||
// MARK - expression constraints | ||
// MARK: - expression constraints | ||
|
||
public func == (_ lhs: Expression, _ rhs: Expression) -> Constraint { | ||
return Constraint(lhs - rhs, .eq) | ||
|
@@ -236,7 +237,7 @@ public func >= (_ lhs: Expression, _ rhs: Double) -> Constraint { | |
return lhs >= Expression(rhs) | ||
} | ||
|
||
// MARK - term constraints | ||
// MARK: - term constraints | ||
|
||
public func == (_ lhs: Term, _ rhs: Expression) -> Constraint { | ||
return rhs == lhs | ||
|
@@ -286,7 +287,7 @@ public func >= (_ lhs: Term, _ rhs: Double) -> Constraint { | |
return Expression(lhs) >= rhs | ||
} | ||
|
||
// MARK - Variable constraints | ||
// MARK: - Variable constraints | ||
|
||
public func == (_ lhs: Variable, _ rhs: Expression) -> Constraint { | ||
return rhs == lhs | ||
|
@@ -336,7 +337,7 @@ public func >= (_ lhs: Variable, _ rhs: Double) -> Constraint { | |
return Term(lhs) >= rhs | ||
} | ||
|
||
// MARK - double constraints | ||
// MARK: - double constraints | ||
|
||
public func == (_ lhs: Double, _ rhs: Expression) -> Constraint { | ||
return rhs == lhs | ||
|
@@ -374,7 +375,7 @@ public func >= (_ lhs: Double, _ rhs: Variable) -> Constraint { | |
return rhs <= lhs | ||
} | ||
|
||
// MARK - constraint strength modifiers | ||
// MARK: - constraint strength modifiers | ||
|
||
@available(*, deprecated, message: "explicitly pass strength when adding the constraint") | ||
public func | (_ lhs: Constraint, _ rhs: Strength) -> Constraint { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters