MCPcopy
hub / github.com/tdewolff/canvas / TestMatrix

Function TestMatrix

util_test.go:192–277  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestMatrix(t *testing.T) {
193 p := Point{3, 4}
194 test.T(t, Identity.Translate(2.0, 2.0).Dot(p), Point{5.0, 6.0})
195 test.T(t, Identity.Scale(2.0, 2.0).Dot(p), Point{6.0, 8.0})
196 test.T(t, Identity.Scale(1.0, -1.0).Dot(p), Point{3.0, -4.0})
197 test.T(t, Identity.ScaleAbout(2.0, -1.0, 2.0, 2.0).Dot(p), Point{4.0, 0.0})
198 test.T(t, Identity.Shear(1.0, 0.0).Dot(p), Point{7.0, 4.0})
199 test.T(t, Identity.ShearAbout(1.0, 0.0, 2.0, 2.0).Dot(p), Point{5.0, 4.0})
200 test.T(t, Identity.Rotate(90.0).Dot(p), p.Rot90CCW())
201 test.T(t, Identity.RotateAbout(90.0, 5.0, 5.0).Dot(p), p.Rot(90.0*math.Pi/180.0, Point{5.0, 5.0}))
202 test.T(t, Identity.ReflectX().Dot(p), Point{-3.0, 4.0})
203 test.T(t, Identity.ReflectY().Dot(p), Point{3.0, -4.0})
204 test.T(t, Identity.ReflectXAbout(1.5).Dot(p), Point{0.0, 4.0})
205 test.T(t, Identity.ReflectYAbout(2.0).Dot(p), Point{3.0, 0.0})
206 test.T(t, Identity.Rotate(90.0).T().Dot(p), p.Rot90CW())
207 test.T(t, Identity.Scale(2.0, 4.0).Inv(), Identity.Scale(0.5, 0.25))
208 test.T(t, Identity.Rotate(90.0).Inv(), Identity.Rotate(-90.0))
209 test.T(t, Identity.Rotate(90.0).Scale(2.0, 1.0), Identity.Scale(1.0, 2.0).Rotate(90.0))
210
211 lambda1, lambda2, v1, v2 := Identity.Rotate(-90.0).Scale(2.0, 1.0).Rotate(90.0).Eigen()
212 test.Float(t, lambda1, 1.0)
213 test.Float(t, lambda2, 2.0)
214 test.T(t, v1, Point{1.0, 0.0})
215 test.T(t, v2, Point{0.0, 1.0})
216
217 halfSqrt2 := 1.0 / math.Sqrt(2.0)
218 lambda1, lambda2, v1, v2 = Identity.Shear(1.0, 1.0).Eigen()
219 test.Float(t, lambda1, 0.0)
220 test.Float(t, lambda2, 2.0)
221 test.T(t, v1, Point{-halfSqrt2, halfSqrt2})
222 test.T(t, v2, Point{halfSqrt2, halfSqrt2})
223
224 lambda1, lambda2, v1, v2 = Identity.Shear(1.0, 0.0).Eigen()
225 test.Float(t, lambda1, 1.0)
226 test.Float(t, lambda2, 1.0)
227 test.T(t, v1, Point{1.0, 0.0})
228 test.T(t, v2, Point{1.0, 0.0})
229
230 lambda1, lambda2, v1, v2 = Identity.Scale(math.NaN(), math.NaN()).Eigen()
231 test.Float(t, lambda1, math.NaN())
232 test.Float(t, lambda2, math.NaN())
233 test.T(t, v1, Point{0.0, 0.0})
234 test.T(t, v2, Point{0.0, 0.0})
235
236 tx, ty, phi, sx, sy, theta := Identity.Rotate(-90.0).Scale(2.0, 1.0).Rotate(90.0).Translate(0.0, 10.0).Decompose()
237 test.Float(t, tx, 0.0)
238 test.Float(t, ty, 20.0)
239 test.Float(t, phi, -90.0)
240 test.Float(t, sx, 2.0)
241 test.Float(t, sy, 1.0)
242 test.Float(t, theta, 90.0)
243
244 test.T(t, Identity.Translate(1.0, 1.0).IsTranslation(), true)
245 test.T(t, Identity.Rotate(90.0).IsTranslation(), false)
246 test.T(t, Identity.Scale(-1.0, 1.0).IsTranslation(), false)
247 test.T(t, Identity.Scale(2.0, 2.0).IsTranslation(), false)
248 test.T(t, Identity.Scale(2.0, 1.0).IsTranslation(), false)
249 test.T(t, Identity.Shear(2.0, -1.0).IsTranslation(), false)

Callers

nothing calls this directly

Calls 15

Rot90CCWMethod · 0.95
RotMethod · 0.95
Rot90CWMethod · 0.95
TMethod · 0.80
InvMethod · 0.80
EigenMethod · 0.80
DecomposeMethod · 0.80
IsTranslationMethod · 0.80
IsRigidMethod · 0.80
IsSimilarityMethod · 0.80
DotMethod · 0.45
TranslateMethod · 0.45

Tested by

no test coverage detected