[squeak-dev] The Inbox: Graphics-ct.410.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Aug 14 21:52:37 UTC 2019
A new version of Graphics was added to project The Inbox:
http://source.squeak.org/inbox/Graphics-ct.410.mcz
==================== Summary ====================
Name: Graphics-ct.410
Author: ct
Time: 14 August 2019, 11:52:24.4754 pm
UUID: 008f8bb1-9963-1e46-8b29-1f1e2aa3235b
Ancestors: Graphics-nice.409
Little refactoring to HSV conversion
Afaik #caseOf: is compiler optimized, so this is not only more beautiful but also at least at efficient as the old conditional chain, isn't it?
=============== Diff against Graphics-nice.409 ===============
Item was changed:
----- Method: Color>>setHue:saturation:brightness: (in category 'private') -----
setHue: hue saturation: saturation brightness: brightness
"Initialize this color to the given hue, saturation, and brightness. See the comment in the instance creation method for details."
| s v hf i f p q t |
s := (saturation asFloat max: 0.0) min: 1.0.
v := (brightness asFloat max: 0.0) min: 1.0.
"zero saturation yields gray with the given brightness"
s = 0.0 ifTrue: [ ^ self setRed: v green: v blue: v ].
hf := hue asFloat.
(hf < 0.0 or: [hf >= 360.0])
ifTrue: [hf := hf \\ 360].
hf := hf / 60.0.
i := hf asInteger. "integer part of hue"
f := hf fractionPart. "fractional part of hue"
p := (1.0 - s) * v.
q := (1.0 - (s * f)) * v.
t := (1.0 - (s * (1.0 - f))) * v.
+ ^ i caseOf: {
+ [0] -> [ self setRed: v green: t blue: p ].
+ [1] -> [ self setRed: q green: v blue: p ].
+ [2] -> [ self setRed: p green: v blue: t ].
+ [3] -> [ self setRed: p green: q blue: v ].
+ [4] -> [ self setRed: t green: p blue: v ].
+ [5] -> [ self setRed: v green: p blue: q ]. }!
- 0 = i ifTrue: [ ^ self setRed: v green: t blue: p ].
- 1 = i ifTrue: [ ^ self setRed: q green: v blue: p ].
- 2 = i ifTrue: [ ^ self setRed: p green: v blue: t ].
- 3 = i ifTrue: [ ^ self setRed: p green: q blue: v ].
- 4 = i ifTrue: [ ^ self setRed: t green: p blue: v ].
- 5 = i ifTrue: [ ^ self setRed: v green: p blue: q ].
-
- self error: 'implementation error'.
- !
More information about the Squeak-dev
mailing list
|