Skip to content

Commit efc7fc8

Browse files
authored
all: use built-in min and max functions
We can use the built-in `min` and `max` functions since Go 1.21. Signed-off-by: Eng Zer Jun <[email protected]>
1 parent 6cdb326 commit efc7fc8

File tree

4 files changed

+4
-31
lines changed

4 files changed

+4
-31
lines changed

axis.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,11 @@ func (DefaultTicks) Ticks(min, max float64) []Tick {
566566
}
567567

568568
func minInt(a, b int) int {
569-
if a < b {
570-
return a
571-
}
572-
return b
569+
return min(a, b)
573570
}
574571

575572
func maxInt(a, b int) int {
576-
if a > b {
577-
return a
578-
}
579-
return b
573+
return max(a, b)
580574
}
581575

582576
// LogTicks is suitable for the Tick.Marker field of an Axis,

plotter/image.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ func (img *Image) transformFor(p *plot.Plot) image.Image {
9191
cTrans := int(p.X.Norm(img.x(c)) * float64(img.cols))
9292
// Find the equivalent column of the previous image column after applying
9393
// axis transforms.
94-
cPrevTrans := int(p.X.Norm(img.x(maxInt(c-1, 0))) * float64(img.cols))
94+
cPrevTrans := int(p.X.Norm(img.x(max(c-1, 0))) * float64(img.cols))
9595
for r := range img.rows {
9696
// Find the equivalent image row after applying axis transforms.
9797
rTrans := int(p.Y.Norm(img.y(r)) * float64(img.rows))
9898
// Find the equivalent row of the previous image row after applying
9999
// axis transforms.
100-
rPrevTrans := int(p.Y.Norm(img.y(maxInt(r-1, 0))) * float64(img.rows))
100+
rPrevTrans := int(p.Y.Norm(img.y(max(r-1, 0))) * float64(img.rows))
101101
crColor := img.img.At(c, img.rows-r-1)
102102
// Set all the pixels in the new image between (cPrevTrans, rPrevTrans)
103103
// and (cTrans, rTrans) to the color at (c,r) in the original image.
@@ -112,13 +112,6 @@ func (img *Image) transformFor(p *plot.Plot) image.Image {
112112
return o
113113
}
114114

115-
func maxInt(a, b int) int {
116-
if a > b {
117-
return a
118-
}
119-
return b
120-
}
121-
122115
func (img *Image) x(c int) float64 {
123116
if c >= img.cols || c < 0 {
124117
panic("plotter/image: illegal range")

plotter/johnson.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ func (j *johnson) unblock(u int) {
114114
}
115115
}
116116

117-
func min(a, b int) int {
118-
if a < b {
119-
return a
120-
}
121-
return b
122-
}
123-
124117
// tarjan implements Tarjan's strongly connected component finding
125118
// algorithm. The implementation is from the pseudocode at
126119
//

vg/vgimg/vgimg_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ func TestIssue540(t *testing.T) {
150150
}
151151

152152
func TestIssue687(t *testing.T) {
153-
min := func(a, b int) int {
154-
if a < b {
155-
return a
156-
}
157-
return b
158-
}
159-
160153
const (
161154
fname = "testdata/issue687.png"
162155
size = 500

0 commit comments

Comments
 (0)