johankasperi/SwiftHSVColorPicker

Strange results in Xcode 9.2

Opened this issue · 1 comments

I have loaded the example into Xcode 9.2.
Tried both swift 3.2 and swift 4.
It compiles and runs with only three minor warning, the warning involve the pi constant and the program runs the same either way.
// hue = acos(dx/d) / CGFloat(M_PI) / 2.0
hue = acos(dx/d) / CGFloat.pi / 2.0
There were no other changes to the example.

Problem:
If the wheel is placed where you would expect only Blue "Select color" returns:
UIExtendedSRGBColorSpace 0.214549 0.269541 1 1

If placed the wheel on the complement (amber) the results are:
UIExtendedSRGBColorSpace 1 0.844251 -0.206295 1
NOTE: unexpected Minus Value.

I think I've found the problem: in ColorWheel.swift / func touchHandler the point supplied to hueSaturationAtPoint must be corrected by the margin (20) of the color wheel:

color = hueSaturationAtPoint(CGPoint(x: (point.x - 20) * scale, y: (point.y - 20) * scale))

Btw: better set the margin somewhere in the class

private let margin: CGFloat = 20

and get rid of the magic numbers 20 in the code.