affine: Implement (*GeoM).String() and (*ColorM).String()

Fixes #586
This commit is contained in:
Hajime Hoshi 2018-05-08 01:53:59 +09:00
parent fbeed96bb5
commit c22857ca89
2 changed files with 20 additions and 0 deletions

View File

@ -15,6 +15,8 @@
package ebiten
import (
"fmt"
"image/color"
"github.com/hajimehoshi/ebiten/internal/affine"
@ -35,6 +37,16 @@ type ColorM struct {
impl *affine.ColorM
}
// 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])
}
// Reset resets the ColorM as identity.
func (c *ColorM) Reset() {
c.impl = nil

View File

@ -15,6 +15,8 @@
package ebiten
import (
"fmt"
"github.com/hajimehoshi/ebiten/internal/affine"
)
@ -28,6 +30,12 @@ type GeoM struct {
impl *affine.GeoM
}
// String returns a string representation of GeoM.
func (g *GeoM) String() string {
a, b, c, d, tx, ty := g.impl.Elements()
return fmt.Sprintf("[[%f, %f, %f], [%f, %f, %f]]", a, b, tx, c, d, ty)
}
// Reset resets the GeoM as identity.
func (g *GeoM) Reset() {
g.impl = nil