1 #include <cmath>
2 #include <utest/utest.h>
3 #include <libnr/nr-matrix.h>
4 #include <libnr/nr-matrix-fns.h> /* identity, matrix_equalp */
5 #include <libnr/nr-matrix-ops.h>
6 #include <libnr/nr-point-fns.h>
7 #include <libnr/nr-point-matrix-ops.h>
8 #include <libnr/nr-rotate.h>
9 #include <libnr/nr-rotate-fns.h>
10 #include <libnr/nr-rotate-ops.h>
11 using NR::X;
12 using NR::Y;
14 int main(int argc, char *argv[])
15 {
16 utest_start("rotate");
18 NR::Matrix const m_id(NR::identity());
19 NR::rotate const r_id(0.0);
20 NR::rotate const rot234(.234);
21 UTEST_TEST("constructors, comparisons") {
22 UTEST_ASSERT( r_id == r_id );
23 UTEST_ASSERT( rot234 == rot234 );
24 UTEST_ASSERT( rot234 != r_id );
25 UTEST_ASSERT( r_id == NR::rotate(NR::Point(1.0, 0.0)) );
26 UTEST_ASSERT( NR::Matrix(r_id) == m_id );
27 UTEST_ASSERT( NR::Matrix(r_id).test_identity() );
29 UTEST_ASSERT(rotate_equalp(rot234, NR::rotate(NR::Point(cos(.234), sin(.234))), 1e-12));
30 }
32 UTEST_TEST("operator=") {
33 NR::rotate rot234_eq(r_id);
34 rot234_eq = rot234;
35 UTEST_ASSERT( rot234 == rot234_eq );
36 UTEST_ASSERT( rot234_eq != r_id );
37 }
39 UTEST_TEST("inverse") {
40 UTEST_ASSERT( r_id.inverse() == r_id );
41 UTEST_ASSERT( rot234.inverse() == NR::rotate(-.234) );
42 }
44 NR::Point const b(-2.0, 3.0);
45 NR::rotate const rot180(NR::Point(-1.0, 0.0));
46 UTEST_TEST("operator*(Point, rotate)") {
47 UTEST_ASSERT( b * r_id == b );
48 UTEST_ASSERT( b * rot180 == -b );
49 UTEST_ASSERT( b * rot234 == b * NR::Matrix(rot234) );
50 UTEST_ASSERT(point_equalp(b * NR::rotate(M_PI / 2),
51 NR::rot90(b),
52 1e-14));
53 UTEST_ASSERT( b * rotate_degrees(90.) == NR::rot90(b) );
54 }
56 UTEST_TEST("operator*(rotate, rotate)") {
57 UTEST_ASSERT( r_id * r_id == r_id );
58 UTEST_ASSERT( rot180 * rot180 == r_id );
59 UTEST_ASSERT( rot234 * r_id == rot234 );
60 UTEST_ASSERT( r_id * rot234 == rot234 );
61 UTEST_ASSERT(rotate_equalp(rot234 * rot234.inverse(), r_id, 1e-14));
62 UTEST_ASSERT(rotate_equalp(rot234.inverse() * rot234, r_id, 1e-14));
63 UTEST_ASSERT(rotate_equalp(( NR::rotate(0.25) * NR::rotate(.5) ),
64 NR::rotate(.75),
65 1e-10));
66 }
68 UTEST_TEST("operator/(rotate, rotate)") {
69 UTEST_ASSERT( rot234 / r_id == rot234 );
70 UTEST_ASSERT( rot234 / rot180 == rot234 * rot180 );
71 UTEST_ASSERT(rotate_equalp(rot234 / rot234, r_id, 1e-14));
72 UTEST_ASSERT(rotate_equalp(r_id / rot234, rot234.inverse(), 1e-14));
73 }
75 return ( utest_end()
76 ? EXIT_SUCCESS
77 : EXIT_FAILURE );
78 }
80 /*
81 Local Variables:
82 mode:c++
83 c-file-style:"stroustrup"
84 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
85 indent-tabs-mode:nil
86 fill-column:99
87 End:
88 */
89 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :