From 681dfcbc3a50961ff5387a9def1bb5b43abdd67c Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 11 Feb 2017 22:59:05 +1300 Subject: [PATCH] Add extra protocol conformances to ConstraintPriority --- Source/ConstraintPriority.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/ConstraintPriority.swift b/Source/ConstraintPriority.swift index 1b690ff..f5ff4f4 100644 --- a/Source/ConstraintPriority.swift +++ b/Source/ConstraintPriority.swift @@ -28,12 +28,12 @@ #endif -public struct ConstraintPriority : ExpressibleByFloatLiteral { +public struct ConstraintPriority : ExpressibleByFloatLiteral, Strideable, Equatable { public typealias FloatLiteralType = Float - public let value: FloatLiteralType + public let value: Float - public init(floatLiteral value: FloatLiteralType) { + public init(floatLiteral value: Float) { self.value = value } @@ -61,4 +61,16 @@ public struct ConstraintPriority : ExpressibleByFloatLiteral { public static var low: ConstraintPriority { return 250.0 } + + public func advanced(by n: Float) -> ConstraintPriority { + return ConstraintPriority(self.value + n) + } + + public func distance(to other: ConstraintPriority) -> Float { + return other.value - self.value + } + + public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool { + return lhs.value == rhs.value + } }