all: use Go 1.21's min/max builtin functions

This commit is contained in:
Hajime Hoshi 2024-09-12 00:58:15 +09:00
parent a36f6210c0
commit a4bfa6cb15
14 changed files with 2 additions and 131 deletions

View File

@ -93,10 +93,3 @@ func (r *float32BytesReader) Seek(offset int64, whence int) (int64, error) {
}
return n / 2 * 4, nil
}
func min(a, b int) int {
if a < b {
return a
}
return b
}

View File

@ -34,13 +34,6 @@ type int16BytesReader struct {
fbuf []float32
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
func (r *int16BytesReader) Read(buf []byte) (int, error) {
if r.eof {
return 0, io.EOF

View File

@ -163,19 +163,9 @@ func loadImage(data []byte) (*ebiten.Image, error) {
}
// max returns the largest of x or y.
func max(x, y int) int {
if x > y {
return x
}
return y
}
// maxSide returns the largest side of a or b images.
func maxSide(a, b *ebiten.Image) int {
return max(
max(a.Bounds().Dx(), b.Bounds().Dx()),
max(a.Bounds().Dy(), b.Bounds().Dy()),
)
return max(a.Bounds().Dx(), b.Bounds().Dx(), a.Bounds().Dy(), b.Bounds().Dy())
}
// drawCenteredText is a util function for drawing blend mode description.

View File

@ -187,13 +187,6 @@ func (f *Field) Update() {
}
}
func min(a, b float64) float64 {
if a > b {
return b
}
return a
}
func flushingColor(rate float64) colorm.ColorM {
var clr colorm.ColorM
alpha := min(1, rate*2)

View File

@ -96,20 +96,6 @@ func (w *World) Draw(pix []byte) {
}
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// neighbourCount calculates the Moore neighborhood of (x, y).
func neighbourCount(a []bool, width, height, x, y int) int {
c := 0

View File

@ -27,13 +27,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/vector"
)
func min(x, y int) int {
if x < y {
return x
}
return y
}
var (
whiteImage = ebiten.NewImage(3, 3)

View File

@ -145,20 +145,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func main() {
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Masking (Ebitengine Demo)")

View File

@ -348,26 +348,6 @@ func TestImageDeallocate(t *testing.T) {
}
}
type ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}
// TODO: Use the built-in function min from Go 1.21.
func min[T ordered](a, b T) T {
if a < b {
return a
}
return b
}
// TODO: Use the built-in function max from Go 1.21.
func max[T ordered](a, b T) T {
if a < b {
return b
}
return a
}
func TestImageBlendLighter(t *testing.T) {
img0, _, err := openEbitenImage()
if err != nil {

View File

@ -35,13 +35,6 @@ var (
maxSize = 0
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
func appendDeferred(f func()) {
deferredM.Lock()
defer deferredM.Unlock()

View File

@ -314,8 +314,5 @@ func (i *Image) syncPixelsIfNeeded() {
blend := graphicsdriver.BlendCopy
i.img.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderSrcImageCount]image.Rectangle{sr}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll, restorable.HintNone)
// TODO: Use clear if Go 1.21 is available.
for pos := range i.dotsBuffer {
delete(i.dotsBuffer, pos)
}
clear(i.dotsBuffer)
}

View File

@ -64,13 +64,6 @@ func ActualTPS() float64 {
return actualTPS
}
func max(a, b int64) int64 {
if a < b {
return b
}
return a
}
func calcCountFromTPS(tps int64, now int64) int {
if tps == 0 {
return 0

View File

@ -507,13 +507,6 @@ func roundUpPower2(x int) int {
return p2
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
func (b *uint32sBuffer) alloc(n int) []uint32 {
buf := b.buf
if len(buf)+n > cap(buf) {

View File

@ -136,18 +136,6 @@ func run() error {
fmt.Fprintln(w)
format.Node(w, fset, tree)
if f == "reader.go" {
// The min function was removed as of Go 1.22, but this is needed for old Go.
// TODO: Remove this when Go 1.21 is the minimum supported version.
fmt.Fprintln(w, `
func min(a, b int) int {
if a < b {
return a
}
return b
}`)
}
if err := w.Flush(); err != nil {
return err
}

View File

@ -1054,10 +1054,3 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
func init() {
}
func min(a, b int) int {
if a < b {
return a
}
return b
}