Add 'Add' methods

This commit is contained in:
Hajime Hoshi 2014-12-26 04:22:06 +09:00
parent 7ea4e19f58
commit cf1b1ed15e
3 changed files with 27 additions and 0 deletions

View File

@ -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() {

View File

@ -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
}

View File

@ -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
}