git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commit73212001cc67970ea1b7bd0fe48be23af4cdabfb
parent8c4e1c85f1
authorcuishuang <imcusg@gmail.com>
date2025-04-11 18:19
vector: use built-in max/min to simplify the code

Change-Id: I8d9d86117126b224162a2b24b7fc67b20b495b59
Reviewed-on: https://go-review.googlesource.com/c/image/+/664837
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>

 vector/raster_fixed.go    | 16 +---------------
 vector/raster_floating.go | 16 +---------------
 2 files changed, 2 insertions(+), 30 deletions(-)

diff --git a/vector/raster_fixed.go b/vector/raster_fixed.go
index 12330da..74ce97b 100644
--- a/vector/raster_fixed.go
+++ b/vector/raster_fixed.go
@@ -40,20 +40,6 @@ type int1ϕ int32
 //	buf[i] += int2ϕ(etc)  // buf has type []int2ϕ.
 type int2ϕ int32
 
-func fixedMax(x, y int1ϕ) int1ϕ {
-	if x > y {
-		return x
-	}
-	return y
-}
-
-func fixedMin(x, y int1ϕ) int1ϕ {
-	if x < y {
-		return x
-	}
-	return y
-}
-
 func fixedFloor(x int1ϕ) int32 { return int32(x >> ϕ) }
 func fixedCeil(x int1ϕ) int32  { return int32((x + fxOneMinusIota) >> ϕ) }
 
@@ -85,7 +71,7 @@ func (z *Rasterizer) fixedLineTo(bx, by float32) {
 	width := int32(z.size.X)
 
 	for ; y < yMax; y++ {
-		dy := fixedMin(int1ϕ(y+1)<<ϕ, byϕ) - fixedMax(int1ϕ(y)<<ϕ, ayϕ)
+		dy := min(int1ϕ(y+1)<<ϕ, byϕ) - max(int1ϕ(y)<<ϕ, ayϕ)
 		xNext := x + int1ϕ(float32(dy)*dxdy)
 		if y < 0 {
 			x = xNext
diff --git a/vector/raster_floating.go b/vector/raster_floating.go
index fd11db1..f84d278 100644
--- a/vector/raster_floating.go
+++ b/vector/raster_floating.go
@@ -11,20 +11,6 @@ import (
 	"math"
 )
 
-func floatingMax(x, y float32) float32 {
-	if x > y {
-		return x
-	}
-	return y
-}
-
-func floatingMin(x, y float32) float32 {
-	if x < y {
-		return x
-	}
-	return y
-}
-
 func floatingFloor(x float32) int32 { return int32(math.Floor(float64(x))) }
 func floatingCeil(x float32) int32  { return int32(math.Ceil(float64(x))) }
 
@@ -53,7 +39,7 @@ func (z *Rasterizer) floatingLineTo(bx, by float32) {
 	width := int32(z.size.X)
 
 	for ; y < yMax; y++ {
-		dy := floatingMin(float32(y+1), by) - floatingMax(float32(y), ay)
+		dy := min(float32(y+1), by) - max(float32(y), ay)
 
 		// The "float32" in expressions like "float32(foo*bar)" here and below
 		// look redundant, since foo and bar already have type float32, but are