1include <../std.scad>
2
3
4module test_hsl() {
5 for (h = [0:30:360]) {
6 for (s = [0:0.2:1]) {
7 for (l = [0:0.2:1]) {
8 c = (1 - abs(2*l-1)) * s;
9 x = c * (1 - abs(((h/60)%2)-1));
10 m = l - c/2;
11 rgb = [m,m,m] + (
12 h<= 60? [c,x,0] :
13 h<=120? [x,c,0] :
14 h<=180? [0,c,x] :
15 h<=240? [0,x,c] :
16 h<=300? [x,0,c] :
17 [c,0,x]
18 );
19 assert_approx(hsl(h,s,l), rgb, format("h={}, s={}, l={}", [h,s,l]));
20 }
21 }
22 }
23}
24test_hsl();
25
26
27module test_hsv() {
28 for (h = [0:30:360]) {
29 for (s = [0:0.2:1]) {
30 for (v = [0:0.2:1]) {
31 c = v * s;
32 x = c * (1 - abs(((h/60)%2)-1));
33 m = v - c;
34 rgb = [m,m,m] + (
35 h<= 60? [c,x,0] :
36 h<=120? [x,c,0] :
37 h<=180? [0,c,x] :
38 h<=240? [0,x,c] :
39 h<=300? [x,0,c] :
40 [c,0,x]
41 );
42 assert_approx(hsv(h,s,v), rgb, format("h={}, s={}, v={}", [h,s,v]));
43 }
44 }
45 }
46}
47test_hsv();
48
49
50// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap