mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
Add 'Add' methods
This commit is contained in:
parent
7ea4e19f58
commit
cf1b1ed15e
13
affine.go
13
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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user