Skip to content

Commit 66f8aa7

Browse files
committed
Remove pi.MaxInt and pi.MinInt
Because Go 1.21 supports generic max and min functions which work for integers.
1 parent a0abcd4 commit 66f8aa7

File tree

8 files changed

+8
-86
lines changed

8 files changed

+8
-86
lines changed

devtools/internal/lib/github_com-elgopher-pi.go

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ROADMAP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* [ ] map API
2222
* [ ] math API
2323
* [x] Cos, Sin, Atan2
24-
* [x] Min, Max, Mid for integers
24+
* [x] Mid for integers
2525
* [x] Mid for float64
2626
* [x] Game controller support: gamepad and keyboard
2727
* [x] Mouse support

examples/shapes/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func drawMousePointer() {
101101
func radius(x0, y0, x1, y1 int) int {
102102
dx := math.Abs(float64(x0 - x1))
103103
dy := math.Abs(float64(y0 - y1))
104-
return int(math.Max(dx, dy))
104+
return int(max(dx, dy))
105105
}
106106

107107
func printCmd(command string) {

internal/bench/math_bench_test.go

-28
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,6 @@ import (
99
"github.com/elgopher/pi"
1010
)
1111

12-
func BenchmarkMinInt(b *testing.B) {
13-
b.ReportAllocs()
14-
b.ResetTimer()
15-
16-
for i := 0; i < b.N; i++ {
17-
for j := 0; j < 60; j++ {
18-
pi.MinInt(j, j+1)
19-
}
20-
for j := 0; j < 60; j++ {
21-
pi.MinInt(j+1, j)
22-
}
23-
}
24-
}
25-
26-
func BenchmarkMaxInt(b *testing.B) {
27-
b.ReportAllocs()
28-
b.ResetTimer()
29-
30-
for i := 0; i < b.N; i++ {
31-
for j := 0; j < 60; j++ {
32-
pi.MaxInt(j, j+1)
33-
}
34-
for j := 0; j < 60; j++ {
35-
pi.MaxInt(j+1, j)
36-
}
37-
}
38-
}
39-
4012
func BenchmarkMidInt(b *testing.B) {
4113
b.ReportAllocs()
4214
b.ResetTimer()

internal/fuzz/math_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ import (
1111
"github.com/elgopher/pi"
1212
)
1313

14-
func FuzzMinInt(f *testing.F) {
15-
f.Fuzz(func(t *testing.T, x, y int) {
16-
pi.MinInt(x, y)
17-
})
18-
}
19-
20-
func FuzzMaxInt(f *testing.F) {
21-
f.Fuzz(func(t *testing.T, x, y int) {
22-
pi.MaxInt(x, y)
23-
})
24-
}
25-
2614
func FuzzMidInt(f *testing.F) {
2715
f.Fuzz(func(t *testing.T, x, y, z int) {
2816
pi.MidInt(x, y, z)

math.go

-18
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,6 @@ type Int interface {
4141
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
4242
}
4343

44-
// MinInt returns minimum of two integer numbers.
45-
func MinInt[T Int](x, y T) T {
46-
if x < y {
47-
return x
48-
}
49-
50-
return y
51-
}
52-
53-
// MaxInt returns maximum of two integer numbers.
54-
func MaxInt[T Int](x, y T) T {
55-
if x > y {
56-
return x
57-
}
58-
59-
return y
60-
}
61-
6244
// MidInt returns the middle of three integer numbers. Very useful for clamping.
6345
func MidInt[T Int](x, y, z T) T {
6446
if x > y {

math_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,6 @@ func TestAtan2(t *testing.T) {
114114
}
115115
}
116116

117-
func TestMinInt(t *testing.T) {
118-
assert.Equal(t, 0, pi.MinInt(0, 0))
119-
assert.Equal(t, 1, pi.MinInt(1, 2))
120-
assert.Equal(t, 1, pi.MinInt(1, 1))
121-
assert.Equal(t, 1, pi.MinInt(2, 1))
122-
assert.Equal(t, -2, pi.MinInt(-1, -2))
123-
assert.Equal(t, -2, pi.MinInt(-2, 2))
124-
}
125-
126-
func TestMaxInt(t *testing.T) {
127-
assert.Equal(t, 0, pi.MaxInt(0, 0))
128-
assert.Equal(t, 2, pi.MaxInt(2, 1))
129-
assert.Equal(t, 1, pi.MaxInt(1, 1))
130-
assert.Equal(t, 2, pi.MaxInt(1, 2))
131-
assert.Equal(t, -1, pi.MaxInt(-1, -2))
132-
assert.Equal(t, 2, pi.MaxInt(-2, 2))
133-
}
134-
135117
func TestMidInt(t *testing.T) {
136118
assert.Equal(t, 0, pi.MidInt(0, 0, 0))
137119
assert.Equal(t, 1, pi.MidInt(0, 1, 2))

pixmap.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ func (p PixMap) Pointer(x, y, w, h int) (ptr Pointer, ok bool) {
212212
DeltaX: dx,
213213
DeltaY: dy,
214214
Pix: pix,
215-
RemainingPixels: MinInt(w, clip.X+clip.W-x),
216-
RemainingLines: MinInt(h, clip.Y+clip.H-y),
215+
RemainingPixels: min(w, clip.X+clip.W-x),
216+
RemainingLines: min(h, clip.Y+clip.H-y),
217217
}, true
218218
}
219219

@@ -230,13 +230,13 @@ type Pointer struct {
230230
func (p PixMap) Copy(x, y, w, h int, dst PixMap, dstX, dstY int) {
231231
dstPtr, srcPtr := p.pointersForCopy(x, y, w, h, dst, dstX, dstY)
232232

233-
remainingLines := MinInt(dstPtr.RemainingLines, srcPtr.RemainingLines)
233+
remainingLines := min(dstPtr.RemainingLines, srcPtr.RemainingLines)
234234

235235
if remainingLines == 0 {
236236
return
237237
}
238238

239-
remainingPixels := MinInt(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
239+
remainingPixels := min(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
240240

241241
copy(dstPtr.Pix[:remainingPixels], srcPtr.Pix)
242242
for i := 1; i < remainingLines; i++ {
@@ -250,13 +250,13 @@ func (p PixMap) Copy(x, y, w, h int, dst PixMap, dstX, dstY int) {
250250
func (p PixMap) Merge(x, y, w, h int, dst PixMap, dstX, dstY int, merge func(dst, src []byte)) {
251251
dstPtr, srcPtr := p.pointersForCopy(x, y, w, h, dst, dstX, dstY)
252252

253-
remainingLines := MinInt(dstPtr.RemainingLines, srcPtr.RemainingLines)
253+
remainingLines := min(dstPtr.RemainingLines, srcPtr.RemainingLines)
254254

255255
if remainingLines == 0 {
256256
return
257257
}
258258

259-
remainingPixels := MinInt(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
259+
remainingPixels := min(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
260260

261261
merge(dstPtr.Pix[:remainingPixels], srcPtr.Pix)
262262
for i := 1; i < remainingLines; i++ {

0 commit comments

Comments
 (0)