Code cleanup

This commit is contained in:
Paul-Christian Volkmer 2024-04-05 20:25:44 +02:00
parent 11cfa5a1eb
commit 16d569c457
5 changed files with 14 additions and 14 deletions

View File

@ -87,10 +87,10 @@ func hslToRgba(hue float32, sat float32, lum float32) color.RGBA {
t1 := lum*2.0 - t2 t1 := lum*2.0 - t2
return color.RGBA{ return color.RGBA{
uint8(hueToRgb(t1, t2, hue+1.0/3.0) * 255), R: uint8(hueToRgb(t1, t2, hue+1.0/3.0) * 255),
uint8(hueToRgb(t1, t2, hue) * 255), G: uint8(hueToRgb(t1, t2, hue) * 255),
uint8(hueToRgb(t1, t2, hue-1.0/3.0) * 255), B: uint8(hueToRgb(t1, t2, hue-1.0/3.0) * 255),
0xff, A: 0xff,
} }
} }

View File

@ -31,10 +31,10 @@ func HashBytes(id string) [16]byte {
func mirrorData(data []bool, blocks int) []bool { func mirrorData(data []bool, blocks int) []bool {
for x := 0; x < blocks; x++ { for x := 0; x < blocks; x++ {
min := x*blocks + 1 minBlock := x*blocks + 1
for y := 0; y < blocks; y++ { for y := 0; y < blocks; y++ {
a := ((blocks - x - 1) * blocks) + y a := ((blocks - x - 1) * blocks) + y
b := min + y - 1 b := minBlock + y - 1
if data[a] { if data[a] {
data[b] = true data[b] = true
} }
@ -46,7 +46,7 @@ func mirrorData(data []bool, blocks int) []bool {
func drawImage(data []bool, blocks int, size int, c color.Color) *image.NRGBA { func drawImage(data []bool, blocks int, size int, c color.Color) *image.NRGBA {
img := image.NewNRGBA(image.Rect(0, 0, size, size)) img := image.NewNRGBA(image.Rect(0, 0, size, size))
draw.Draw(img, img.Bounds(), &image.Uniform{color.Gray{240}}, image.Point{0, 0}, draw.Src) draw.Draw(img, img.Bounds(), &image.Uniform{C: color.Gray{Y: 240}}, image.Point{X: 0, Y: 0}, draw.Src)
blockSize := size / (blocks + 1) blockSize := size / (blocks + 1)
border := (size - (blocks * blockSize)) / 2 border := (size - (blocks * blockSize)) / 2

View File

@ -46,7 +46,7 @@ func ColorV1(hash [16]byte) color.RGBA {
} else if b > r && b > g { } else if b > r && b > g {
b += 48 b += 48
} }
return color.RGBA{r, g, b, 255} return color.RGBA{R: r, G: g, B: b, A: 255}
} }
func ColorV2(hash [16]byte) color.RGBA { func ColorV2(hash [16]byte) color.RGBA {

View File

@ -9,11 +9,11 @@ import (
func TestIgnoreCase(t *testing.T) { func TestIgnoreCase(t *testing.T) {
w1 := bytes.NewBuffer([]byte{}) w1 := bytes.NewBuffer([]byte{})
ig1 := NewIdIconGenerator().WithColorGenerator(ColorV1) ig1 := NewIdIconGenerator().WithColorGenerator(ColorV1)
png.Encode(w1, ig1.GenIcon("example", 80)) _ = png.Encode(w1, ig1.GenIcon("example", 80))
w2 := bytes.NewBuffer([]byte{}) w2 := bytes.NewBuffer([]byte{})
ig2 := NewIdIconGenerator().WithColorGenerator(ColorV1) ig2 := NewIdIconGenerator().WithColorGenerator(ColorV1)
png.Encode(w2, ig2.GenIcon("Example", 80)) _ = png.Encode(w2, ig2.GenIcon("Example", 80))
if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 { if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 {
t.Errorf("resulting images do not match") t.Errorf("resulting images do not match")
@ -24,11 +24,11 @@ func TestStringMatchesHash(t *testing.T) {
w1 := bytes.NewBuffer([]byte{}) w1 := bytes.NewBuffer([]byte{})
ig1 := NewIdIconGenerator().WithColorGenerator(ColorV2) ig1 := NewIdIconGenerator().WithColorGenerator(ColorV2)
// MD5 of lowercase 'example' // MD5 of lowercase 'example'
png.Encode(w1, ig1.GenIcon("1a79a4d60de6718e8e5b326e338ae533", 80)) _ = png.Encode(w1, ig1.GenIcon("1a79a4d60de6718e8e5b326e338ae533", 80))
w2 := bytes.NewBuffer([]byte{}) w2 := bytes.NewBuffer([]byte{})
ig2 := NewIdIconGenerator().WithColorGenerator(ColorV2) ig2 := NewIdIconGenerator().WithColorGenerator(ColorV2)
png.Encode(w2, ig2.GenIcon("Example", 80)) _ = png.Encode(w2, ig2.GenIcon("Example", 80))
if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 { if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 {
t.Errorf("resulting images do not match") t.Errorf("resulting images do not match")

View File

@ -112,8 +112,8 @@ func TestUsesConfig(t *testing.T) {
} }
func TestUsesConfigWithEnvVar(t *testing.T) { func TestUsesConfigWithEnvVar(t *testing.T) {
os.Setenv("COLORSCHEME", "v1") _ = os.Setenv("COLORSCHEME", "v1")
os.Setenv("PATTERN", "default") _ = os.Setenv("PATTERN", "default")
configure("./testdata/testconfig.toml") configure("./testdata/testconfig.toml")