ebiten: Bug fix: Colorm.Concat crashed when the argument is an initial value

Closes #1765
This commit is contained in:
Hajime Hoshi 2021-08-18 01:09:04 +09:00
parent 12350e2fee
commit 415ceded79
2 changed files with 15 additions and 1 deletions

View File

@ -64,7 +64,11 @@ func (c *ColorM) Apply(clr color.Color) color.Color {
// 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) {
c.impl = c.affineColorM().Concat(other.impl)
o := other.impl
if o == nil {
o = affine.ColorMIdentity{}
}
c.impl = c.affineColorM().Concat(o)
}
// Scale scales the matrix by (r, g, b, a).

View File

@ -2426,3 +2426,13 @@ func BenchmarkColorMScale(b *testing.B) {
dst.DrawImage(src, op)
}
}
// #1765
func TestColorMConcat(t *testing.T) {
var a, b ColorM
a.SetElement(1, 2, -1)
a.Concat(b)
if got, want := a.Element(1, 2), -1.0; got != want {
t.Errorf("got: %f, want: %f", got, want)
}
}