Skip to content

Commit b151274

Browse files
alecthomasclaude
andcommitted
refactor: replace math.Min/Max with builtin min/max
ClampBrightness's min/max parameters are renamed low/high as they would shadow the builtins. In serialise.go the builtins operate on float32 directly, removing the float64 round-trips and the math import. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 76cf6db commit b151274

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

colour.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ func (c Colour) BrightenOrDarken(factor float64) Colour {
101101
}
102102

103103
// ClampBrightness returns a copy of this colour with its brightness adjusted such that
104-
// it falls within the range [min, max] (or very close to it due to rounding errors).
104+
// it falls within the range [low, high] (or very close to it due to rounding errors).
105105
// The supplied values use the same [0.0, 1.0] range as Brightness.
106-
func (c Colour) ClampBrightness(min, max float64) Colour {
106+
func (c Colour) ClampBrightness(low, high float64) Colour {
107107
if !c.IsSet() {
108108
return c
109109
}
110110

111-
min = math.Max(min, 0)
112-
max = math.Min(max, 1)
111+
low = max(low, 0)
112+
high = min(high, 1)
113113
current := c.Brightness()
114-
target := math.Min(math.Max(current, min), max)
114+
target := min(max(current, low), high)
115115
if current == target {
116116
return c
117117
}

colour_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package chroma
22

33
import (
4-
"math"
54
"testing"
65

76
assert "github.com/alecthomas/assert/v2"
@@ -48,16 +47,16 @@ func hue(c Colour) float64 {
4847
g := float64(c.Green()) / 255
4948
b := float64(c.Blue()) / 255
5049

51-
min := math.Min(math.Min(r, g), b)
52-
max := math.Max(math.Max(r, g), b)
50+
lo := min(r, g, b)
51+
hi := max(r, g, b)
5352

5453
switch {
55-
case r == min:
56-
return (g - b) / (max - min)
57-
case g == min:
58-
return 2 + (b-r)/(max-min)
54+
case r == lo:
55+
return (g - b) / (hi - lo)
56+
case g == lo:
57+
return 2 + (b-r)/(hi-lo)
5958
default:
60-
return 4 + (r-g)/(max-min)
59+
return 4 + (r-g)/(hi-lo)
6160
}
6261
}
6362

serialise.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"io/fs"
10-
"math"
1110
"path/filepath"
1211
"reflect"
1312
"regexp"
@@ -173,15 +172,15 @@ func NewXMLLexer(from fs.FS, path string) (*RegexLexer, error) {
173172
}
174173

175174
if ok && config.Analyse.First {
176-
return float32(math.Min(float64(ra.score), 1.0))
175+
return min(ra.score, 1.0)
177176
}
178177

179178
if ok {
180179
score += ra.score
181180
}
182181
}
183182

184-
return float32(math.Min(float64(score), 1.0))
183+
return min(score, 1.0)
185184
}
186185
}
187186

0 commit comments

Comments
 (0)