Issue #607
Implement Equatable
and Comparable
and use round
struct RGBA: Equatable, Comparable {
let red: CGFloat
let green: CGFloat
let blue: CGFloat
let alpha: CGFloat
init(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
}
static func round(_ value: CGFloat) -> CGFloat {
(value * 100).rounded() / 100
}
static func == (left: RGBA, right: RGBA) -> Bool {
let r = Self.round
return r(left.red) == r(right.red)
&& r(left.green) == r(right.green)
&& r(left.blue) == r(right.blue)
&& r(left.alpha) == r(right.alpha)
}
static func < (left: RGBA, right: RGBA) -> Bool {
let r = Self.round
return r(left.red) < r(right.red)
&& r(left.green) < r(right.green)
&& r(left.blue) < r(right.blue)
&& r(left.alpha) <= r(right.alpha)
}
}
XCTAssertGreaterThan(backgroundRgba, RGBA(0.57, 0.12, 0.88, 1.0)
XCTAssertLessThanThan(backgroundRgba, RGBA(0.57, 0.12, 0.88, 1.0)