From cf1b1ed15ea9a60dcf6685c759b1ff84c56a746a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Dec 2014 04:22:06 +0900 Subject: [PATCH] Add 'Add' methods --- affine.go | 13 +++++++++++++ colormatrix.go | 7 +++++++ geometrymatrix.go | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/affine.go b/affine.go index 334bec230..114e2ea1f 100644 --- a/affine.go +++ b/affine.go @@ -35,6 +35,19 @@ func isIdentity(ebiten affine) bool { return true } +func add(lhs, rhs, result affine) { + dim := lhs.dim() + if dim != rhs.dim() { + panic("diffrent-sized matrices can't be multiplied") + } + + for i := 0; i < dim-1; i++ { + for j := 0; j < dim; j++ { + result.setElement(i, j, lhs.Element(i, j)+rhs.Element(i, j)) + } + } +} + func mul(lhs, rhs, result affine) { dim := lhs.dim() if dim != rhs.dim() { diff --git a/colormatrix.go b/colormatrix.go index edbfd33e2..6c2405771 100644 --- a/colormatrix.go +++ b/colormatrix.go @@ -60,6 +60,13 @@ func (c *ColorMatrix) Concat(other ColorMatrix) { *c = result } +// Add adds a color matrix with the other color matrix. +func (c *ColorMatrix) Add(other ColorMatrix) { + result := ColorMatrix{} + add(&other, c, &result) + *c = result +} + func (c *ColorMatrix) setElement(i, j int, element float64) { c.es[i][j] = element } diff --git a/geometrymatrix.go b/geometrymatrix.go index 7c30059db..19bca6be7 100644 --- a/geometrymatrix.go +++ b/geometrymatrix.go @@ -53,6 +53,13 @@ func (g *GeometryMatrix) Concat(other GeometryMatrix) { *g = result } +// Add adds a geometry matrix with the other geometry matrix. +func (g *GeometryMatrix) Add(other GeometryMatrix) { + result := GeometryMatrix{} + add(&other, g, &result) + *g = result +} + func (g *GeometryMatrix) setElement(i, j int, element float64) { g.es[i][j] = element }