mirror of
https://github.com/joncardasis/ChromaColorPicker.git
synced 2024-09-11 06:35:41 +03:00
Updated color wheel generation for proper device scaling ratio. Updated tests.
This commit is contained in:
parent
520d4d64a7
commit
105f76bc0e
@ -25,9 +25,9 @@ public class ColorWheelView: UIView {
|
||||
layer.masksToBounds = false
|
||||
layer.cornerRadius = radius
|
||||
|
||||
let minDimensionSize = min(bounds.width, bounds.height)
|
||||
if let colorWheelImage = makeColorWheelImage(radius: minDimensionSize) {
|
||||
imageView.image = UIImage(ciImage: colorWheelImage, scale: UIScreen.main.scale, orientation: .up)
|
||||
let screenScale: CGFloat = UIScreen.main.scale
|
||||
if let colorWheelImage = makeColorWheelImage(radius: radius * screenScale) {
|
||||
imageView.image = UIImage(ciImage: colorWheelImage, scale: screenScale, orientation: .up)
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ public class ColorWheelView: UIView {
|
||||
Generates a color wheel image from a given radius.
|
||||
- Parameters:
|
||||
- radius: The radius of the wheel in points. A radius of 100 would generate an
|
||||
image of 200x200 (400x400 pixels on a device with 2x scaling.)
|
||||
image of 200x200 points (400x400 pixels on a device with 2x scaling.)
|
||||
*/
|
||||
internal func makeColorWheelImage(radius: CGFloat) -> CIImage? {
|
||||
let filter = CIFilter(name: "CIHueSaturationValueGradient", parameters: [
|
||||
|
@ -96,17 +96,16 @@ class ColorWheelViewTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testPixelColorShouldBeRedAtMaxXMidY() {
|
||||
// Given, When
|
||||
// Given
|
||||
let size = subject.frame.size
|
||||
// Note: Due to the wheel being HUE, any angle will share the same value, therefore
|
||||
// we can safely inset the width to compensate for any color smoothing at the edges.
|
||||
let testPoint = CGPoint(x: size.width - 25, y: size.height / 2.0)
|
||||
let testPoint = CGPoint(x: size.width, y: size.height / 2.0)
|
||||
let (expectedRedValue, _, _) = UIColor.red.rgbValues
|
||||
|
||||
let vc = UIViewController()
|
||||
vc.view.addSubview(subject)
|
||||
vc.beginAppearanceTransition(true, animated: false)
|
||||
vc.endAppearanceTransition()
|
||||
subject.layoutSubviews()
|
||||
|
||||
// When
|
||||
let (actualRedValue, _, _) = subject.pixelColor(at: testPoint)!.rgbValues
|
||||
@ -115,8 +114,29 @@ class ColorWheelViewTests: XCTestCase {
|
||||
XCTAssertEqual(actualRedValue, expectedRedValue, accuracy: 0.001)
|
||||
}
|
||||
|
||||
func testPixelColorShouldBeCyanAtMinXMidY() {
|
||||
// Given
|
||||
let size = subject.frame.size
|
||||
let testPoint = CGPoint(x: 0, y: size.height / 2.0)
|
||||
let expectedColorValues = UIColor.cyan.rgbValues
|
||||
|
||||
let vc = UIViewController()
|
||||
vc.view.addSubview(subject)
|
||||
vc.beginAppearanceTransition(true, animated: false)
|
||||
vc.endAppearanceTransition()
|
||||
subject.layoutSubviews()
|
||||
|
||||
// When
|
||||
let actualColorValues = subject.pixelColor(at: testPoint)!.rgbValues
|
||||
|
||||
// Then
|
||||
XCTAssertEqual(actualColorValues.red, expectedColorValues.red, accuracy: 0.005)
|
||||
XCTAssertEqual(actualColorValues.green, expectedColorValues.green, accuracy: 0.005)
|
||||
XCTAssertEqual(actualColorValues.blue, expectedColorValues.blue, accuracy: 0.005)
|
||||
}
|
||||
|
||||
func testPixelColorShouldBeWhiteAtTheCenter() {
|
||||
// Given, When
|
||||
// Given
|
||||
let size = subject.frame.size
|
||||
let testPoint = CGPoint(x: size.width / 2.0, y: size.height / 2.0)
|
||||
let expectedColorValues = UIColor.white.rgbValues
|
||||
@ -125,6 +145,7 @@ class ColorWheelViewTests: XCTestCase {
|
||||
vc.view.addSubview(subject)
|
||||
vc.beginAppearanceTransition(true, animated: false)
|
||||
vc.endAppearanceTransition()
|
||||
subject.layoutSubviews()
|
||||
|
||||
// When
|
||||
let actualColorValues = subject.pixelColor(at: testPoint)!.rgbValues
|
||||
|
Loading…
Reference in New Issue
Block a user