From dad427920d87837025e5b613e498a75de7a3164d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 25 May 2017 22:50:47 +0900 Subject: [PATCH] affine: Add Reset function --- colorm.go | 5 +++++ examples/sprites/main.go | 2 +- geom.go | 5 +++++ internal/affine/colorm.go | 4 ++++ internal/affine/geom.go | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/colorm.go b/colorm.go index 57be2f31e..332413f81 100644 --- a/colorm.go +++ b/colorm.go @@ -33,6 +33,11 @@ type ColorM struct { impl affine.ColorM } +// Reset resets the ColorM as identity. +func (c *ColorM) Reset() { + c.impl.Reset() +} + // Concat multiplies a color matrix with the other color matrix. // This is same as muptiplying the matrix other and the matrix c in this order. func (c *ColorM) Concat(other ColorM) { diff --git a/examples/sprites/main.go b/examples/sprites/main.go index 281606ca7..2350937a6 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -110,7 +110,7 @@ func update(screen *ebiten.Image) error { } for i := 0; i < sprites.num; i++ { s := sprites.sprites[i] - op.GeoM = ebiten.GeoM{} + op.GeoM.Reset() op.GeoM.Translate(float64(s.x), float64(s.y)) screen.DrawImage(ebitenImage, op) } diff --git a/geom.go b/geom.go index fb54a16ee..433218d2e 100644 --- a/geom.go +++ b/geom.go @@ -28,6 +28,11 @@ type GeoM struct { impl affine.GeoM } +// Reset resets the GeoM as identity. +func (g *GeoM) Reset() { + g.impl.Reset() +} + // Element returns a value of a matrix at (i, j). func (g *GeoM) Element(i, j int) float64 { a, b, c, d, tx, ty := g.impl.Elements() diff --git a/internal/affine/colorm.go b/internal/affine/colorm.go index c14632091..bd13c5ab9 100644 --- a/internal/affine/colorm.go +++ b/internal/affine/colorm.go @@ -44,6 +44,10 @@ type ColorM struct { elements []float64 } +func (c *ColorM) Reset() { + c.elements = nil +} + func (c *ColorM) UnsafeElements() []float64 { if c.elements == nil { c.elements = colorMIdentityElements diff --git a/internal/affine/geom.go b/internal/affine/geom.go index 3cfa30a04..68ea30b15 100644 --- a/internal/affine/geom.go +++ b/internal/affine/geom.go @@ -34,6 +34,10 @@ type GeoM struct { inited bool } +func (g *GeoM) Reset() { + g.inited = false +} + func (g *GeoM) Elements() (a, b, c, d, tx, ty float64) { if !g.inited { return 1, 0, 0, 1, 0, 0