2017-11-21 14:01:31 +03:00
|
|
|
(load "Test.carp")
|
|
|
|
(load "Vector.carp")
|
|
|
|
(load "Geometry.carp")
|
|
|
|
|
2017-12-12 17:08:33 +03:00
|
|
|
(use-all Test Vector2 Geometry Double)
|
2017-10-24 14:52:32 +03:00
|
|
|
|
2018-11-07 18:11:38 +03:00
|
|
|
(deftest test
|
|
|
|
(assert-equal test
|
2019-09-08 14:02:04 +03:00
|
|
|
&(init 0.0 0.0) &(Vector2.zero)
|
2018-11-07 18:11:38 +03:00
|
|
|
"zero works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 1.0 2.0) &(init 1.0 2.0)
|
|
|
|
"= operator works")
|
|
|
|
(assert-op test
|
|
|
|
&(init 1.0 2.0) &(init 1.0 1.0)
|
|
|
|
"/= operator works"
|
|
|
|
Vector2./=)
|
|
|
|
(assert-equal test
|
|
|
|
&(init 3.0 3.0)
|
|
|
|
&(add &(init 2.0 1.0) &(init 1.0 2.0))
|
|
|
|
"add operator works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 1.0 -1.0)
|
|
|
|
&(sub &(init 2.0 1.0) &(init 1.0 2.0))
|
|
|
|
"sub operator works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 4.0 2.0)
|
|
|
|
&(mul &(init 2.0 1.0) 2.0)
|
|
|
|
"mul operator works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 1.0 0.5)
|
|
|
|
&(div &(init 2.0 1.0) 2.0)
|
|
|
|
"div operator works")
|
|
|
|
(assert-equal test
|
|
|
|
5.0
|
|
|
|
(mag &(init 3.0 4.0))
|
|
|
|
"mag works")
|
|
|
|
(assert-equal test
|
|
|
|
101.0
|
|
|
|
(mag-sq &(init 10.0 1.0))
|
|
|
|
"mag-sq works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 0.6 0.8)
|
|
|
|
&(normalize &(init 3.0 4.0))
|
|
|
|
"normalize works")
|
|
|
|
(assert-equal test
|
|
|
|
5.0
|
|
|
|
(dist &(init 10.0 10.0) &(init 7.0 6.0))
|
|
|
|
"dist works")
|
|
|
|
(assert-equal test
|
|
|
|
0.0
|
|
|
|
(heading &(init 1.0 0.0))
|
|
|
|
"heading works")
|
|
|
|
(assert-op test
|
|
|
|
&(init -2.0 1.0)
|
|
|
|
&(rotate &(init 1.0 2.0) (degree-to-radians 90.0))
|
|
|
|
"rotate works"
|
2019-09-08 14:02:04 +03:00
|
|
|
vapprox)
|
2018-11-07 18:11:38 +03:00
|
|
|
(assert-equal test
|
|
|
|
90.0
|
|
|
|
(radians-to-degree (Vector2.angle-between &(init 1.0 0.0) &(init 0.0 1.0)))
|
|
|
|
"angle-between works")
|
|
|
|
(assert-true test
|
|
|
|
(anti-parallel? &(init 1.0 0.0) &(init -1.0 0.0))
|
|
|
|
"anti-parallel? works")
|
|
|
|
(assert-true test
|
|
|
|
(parallel? &(init 1.0 0.0) &(init 1.0 0.0))
|
|
|
|
"parallel? works")
|
|
|
|
(assert-true test
|
|
|
|
(perpendicular? &(init 1.0 0.0) &(init 0.0 1.0))
|
|
|
|
"perpendicular? works")
|
|
|
|
(assert-equal test
|
|
|
|
44.0
|
|
|
|
(dot &(init 10.0 2.0) &(init 2.0 12.0))
|
|
|
|
"dot works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 2.5 5.0)
|
2019-09-08 14:02:04 +03:00
|
|
|
&(vlerp &(Vector2.zero) &(init 5.0 10.0) 0.5)
|
|
|
|
"vlerp works")
|
2018-11-07 18:11:38 +03:00
|
|
|
)
|