Skip to content

Commit f8ea5c1

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 b3ad290 commit f8ea5c1

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
@@ -217,8 +217,8 @@ func (p PixMap) Pointer(x, y, w, h int) (ptr Pointer, ok bool) {
217217
DeltaX: dx,
218218
DeltaY: dy,
219219
Pix: pix,
220-
RemainingPixels: MinInt(w, clip.X+clip.W-x),
221-
RemainingLines: MinInt(h, clip.Y+clip.H-y),
220+
RemainingPixels: min(w, clip.X+clip.W-x),
221+
RemainingLines: min(h, clip.Y+clip.H-y),
222222
}, true
223223
}
224224

@@ -235,13 +235,13 @@ type Pointer struct {
235235
func (p PixMap) Copy(x, y, w, h int, dst PixMap, dstX, dstY int) {
236236
dstPtr, srcPtr := p.pointersForCopy(x, y, w, h, dst, dstX, dstY)
237237

238-
remainingLines := MinInt(dstPtr.RemainingLines, srcPtr.RemainingLines)
238+
remainingLines := min(dstPtr.RemainingLines, srcPtr.RemainingLines)
239239

240240
if remainingLines == 0 {
241241
return
242242
}
243243

244-
remainingPixels := MinInt(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
244+
remainingPixels := min(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
245245

246246
copy(dstPtr.Pix[:remainingPixels], srcPtr.Pix)
247247
for i := 1; i < remainingLines; i++ {
@@ -255,13 +255,13 @@ func (p PixMap) Copy(x, y, w, h int, dst PixMap, dstX, dstY int) {
255255
func (p PixMap) Merge(x, y, w, h int, dst PixMap, dstX, dstY int, merge func(dst, src []byte)) {
256256
dstPtr, srcPtr := p.pointersForCopy(x, y, w, h, dst, dstX, dstY)
257257

258-
remainingLines := MinInt(dstPtr.RemainingLines, srcPtr.RemainingLines)
258+
remainingLines := min(dstPtr.RemainingLines, srcPtr.RemainingLines)
259259

260260
if remainingLines == 0 {
261261
return
262262
}
263263

264-
remainingPixels := MinInt(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
264+
remainingPixels := min(dstPtr.RemainingPixels, srcPtr.RemainingPixels)
265265

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

0 commit comments

Comments
 (0)