#159 Add test case when matrix determinant is not 1
This commit is contained in:
parent
a0713598da
commit
1e19db5b25
|
@ -405,7 +405,7 @@ func (m Matrix) Project(u Vec) Vec {
|
|||
func (m Matrix) Unproject(u Vec) Vec {
|
||||
det := m[0]*m[3] - m[2]*m[1]
|
||||
return Vec{
|
||||
m[3]/det*u.X - m[2]/det*u.Y + m[2]*m[5] - m[3]*m[4],
|
||||
-m[1]/det*u.X + m[0]/det*u.Y + m[1]*m[4] - m[0]*m[5],
|
||||
m[3]/det*u.X - m[2]/det*u.Y + (m[2]*m[5]-m[3]*m[4])/det,
|
||||
-m[1]/det*u.X + m[0]/det*u.Y + (m[1]*m[4]-m[0]*m[5])/det,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,12 @@ func TestMatrix_Unproject(t *testing.T) {
|
|||
assert.InDelta(t, unprojected.X, 2, delta)
|
||||
assert.InDelta(t, unprojected.Y, 2, delta)
|
||||
})
|
||||
t.Run("for scaled, rotated and moved matrix", func(t *testing.T) {
|
||||
matrix := pixel.IM.Scaled(pixel.ZV, 2).Rotated(pixel.ZV, math.Pi/2).Moved(pixel.V(2, 2))
|
||||
unprojected := matrix.Unproject(pixel.V(-2, 6))
|
||||
assert.InDelta(t, unprojected.X, 2, delta)
|
||||
assert.InDelta(t, unprojected.Y, 2, delta)
|
||||
})
|
||||
t.Run("for rotated and moved matrix", func(t *testing.T) {
|
||||
matrix := pixel.IM.Rotated(pixel.ZV, math.Pi/2).Moved(pixel.V(1, 1))
|
||||
unprojected := matrix.Unproject(pixel.V(1, 2))
|
||||
|
|
Loading…
Reference in New Issue