internal/affine: Add String

This commit is contained in:
Hajime Hoshi 2021-07-26 14:26:59 +09:00
parent 18757cff16
commit e84506dfc3
2 changed files with 11 additions and 8 deletions

View File

@ -15,8 +15,6 @@
package ebiten
import (
"fmt"
"image/color"
"github.com/hajimehoshi/ebiten/v2/internal/affine"
@ -41,12 +39,7 @@ type ColorM struct {
// String returns a string representation of ColorM.
func (c *ColorM) String() string {
b, t := c.impl.UnsafeElements()
return fmt.Sprintf("[[%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f]]",
b[0], b[4], b[8], b[12], t[0],
b[1], b[5], b[9], b[13], t[1],
b[2], b[6], b[10], b[14], t[2],
b[3], b[7], b[11], b[15], t[3])
return c.impl.String()
}
// Reset resets the ColorM as identity.

View File

@ -15,6 +15,7 @@
package affine
import (
"fmt"
"image/color"
"math"
"sync"
@ -50,6 +51,15 @@ type ColorM struct {
translate []float32
}
func (c *ColorM) String() string {
b, t := c.UnsafeElements()
return fmt.Sprintf("[[%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f], [%f, %f, %f, %f, %f]]",
b[0], b[4], b[8], b[12], t[0],
b[1], b[5], b[9], b[13], t[1],
b[2], b[6], b[10], b[14], t[2],
b[3], b[7], b[11], b[15], t[3])
}
func clamp(x float32) float32 {
if x > 1 {
return 1