mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
f32: nicer Affine2D string formatting
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+22
-2
@@ -3,8 +3,8 @@
|
||||
package f32
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Affine2D represents an affine 2D transformation. The zero value of Affine2D
|
||||
@@ -148,5 +148,25 @@ func (a Affine2D) shear(radiansX, radiansY float32) Affine2D {
|
||||
|
||||
func (a Affine2D) String() string {
|
||||
sx, hx, ox, hy, sy, oy := a.Elems()
|
||||
return fmt.Sprintf("[[%f %f %f] [%f %f %f]]", sx, hx, ox, hy, sy, oy)
|
||||
|
||||
// precision 6, one period, negative sign and space per number
|
||||
const prec = 6
|
||||
const charsPerFloat = prec + 2 + 1
|
||||
s := make([]byte, 0, 6*charsPerFloat+6)
|
||||
|
||||
s = append(s, '[', '[')
|
||||
s = strconv.AppendFloat(s, float64(sx), 'g', prec, 32)
|
||||
s = append(s, ' ')
|
||||
s = strconv.AppendFloat(s, float64(hx), 'g', prec, 32)
|
||||
s = append(s, ' ')
|
||||
s = strconv.AppendFloat(s, float64(ox), 'g', prec, 32)
|
||||
s = append(s, ']', ' ', '[')
|
||||
s = strconv.AppendFloat(s, float64(hy), 'g', prec, 32)
|
||||
s = append(s, ' ')
|
||||
s = strconv.AppendFloat(s, float64(sy), 'g', prec, 32)
|
||||
s = append(s, ' ')
|
||||
s = strconv.AppendFloat(s, float64(oy), 'g', prec, 32)
|
||||
s = append(s, ']', ']')
|
||||
|
||||
return string(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user