Skip to content

Commit 195ce02

Browse files
committed
Fix HueOffset for hues greater *and* equal to 360 degrees
Fixes #8.
1 parent 886e4aa commit 195ce02

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

colors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func HueOffset(c color.Color, degrees int) color.Color {
3030
h += float64(degrees)
3131
if h < 0 {
3232
h += 360
33-
} else if h > 360 {
33+
} else if h >= 360 {
3434
h -= 360
3535
}
3636

colors_test.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ func TestLightness(t *testing.T) {
5252
}
5353

5454
func TestComplementary(t *testing.T) {
55-
c, _ := colorful.Hex("#2f1b82")
56-
cc, _ := colorful.MakeColor(Complementary(c))
57-
exp, _ := colorful.Hex("#6e821b")
55+
cols := []struct {
56+
hex string
57+
complementary string
58+
}{
59+
{"#2f1b82", "#6e821b"},
60+
{"#00ffff", "#ff0000"},
61+
}
62+
63+
for _, col := range cols {
64+
c, _ := colorful.Hex(col.hex)
65+
cc, _ := colorful.MakeColor(Complementary(c))
66+
exp, _ := colorful.Hex(col.complementary)
5867

59-
if cc.Hex() != exp.Hex() {
60-
t.Errorf("Expected complementary color %v, got %v", exp.Hex(), cc.Hex())
68+
if cc.Hex() != exp.Hex() {
69+
t.Errorf("Expected complementary color %v, got %v", exp.Hex(), cc.Hex())
70+
}
6171
}
6272
}
6373

0 commit comments

Comments
 (0)