Code

Use subdirectories with icon sizes.
[inkscape.git] / src / libnr / nr-rotate-test.h
1 #include <cxxtest/TestSuite.h>
3 #include <cmath>
4 #include <libnr/nr-matrix.h>
5 #include <libnr/nr-matrix-ops.h>
6 #include <libnr/nr-matrix-fns.h>        /* identity, matrix_equalp */
7 #include <libnr/nr-point-fns.h>
8 #include <libnr/nr-rotate.h>
9 #include <libnr/nr-rotate-fns.h>
10 #include <libnr/nr-rotate-ops.h>
13 class NrRotateTest : public CxxTest::TestSuite
14 {
15 public:
17     NrRotateTest() :
18         m_id( NR::identity() ),
19         r_id( 0.0 ),
20         rot234( .234 ),
21         b( -2.0, 3.0 ),
22         rot180( NR::Point(-1.0, 0.0) )
23     {
24     }
25     virtual ~NrRotateTest() {}
27 // createSuite and destroySuite get us per-suite setup and teardown
28 // without us having to worry about static initialization order, etc.
29     static NrRotateTest *createSuite() { return new NrRotateTest(); }
30     static void destroySuite( NrRotateTest *suite ) { delete suite; }
32     NR::Matrix const m_id;
33     NR::rotate const r_id;
34     NR::rotate const rot234;
35     NR::Point const b;
36     NR::rotate const rot180;
41     void testCtorsCompares(void)
42     {
43         TS_ASSERT_EQUALS( r_id, r_id );
44         TS_ASSERT_EQUALS( rot234, rot234 );
45         TS_ASSERT_DIFFERS( rot234, r_id );
46         TS_ASSERT_EQUALS( r_id, NR::rotate(NR::Point(1.0, 0.0)) );
47         TS_ASSERT_EQUALS( NR::Matrix(r_id), m_id );
48         TS_ASSERT( NR::Matrix(r_id).test_identity() );
50         TS_ASSERT(rotate_equalp(rot234, NR::rotate(NR::Point(cos(.234), sin(.234))), 1e-12));
51     }
53     void testAssignmentOp(void)
54     {
55         NR::rotate rot234_eq(r_id);
56         rot234_eq = rot234;
57         TS_ASSERT_EQUALS( rot234, rot234_eq );
58         TS_ASSERT_DIFFERS( rot234_eq, r_id );
59     }
61     void testInverse(void)
62     {
63         TS_ASSERT_EQUALS( r_id.inverse(), r_id );
64         TS_ASSERT_EQUALS( rot234.inverse(), NR::rotate(-.234) );
65     }
67     void testOpStarPointRotate(void)
68     {
69         TS_ASSERT_EQUALS( b * r_id, b );
70         TS_ASSERT_EQUALS( b * rot180, -b );
71         TS_ASSERT_EQUALS( b * rot234, b * NR::Matrix(rot234) );
72         TS_ASSERT(point_equalp(b * NR::rotate(M_PI / 2),
73                                NR::rot90(b),
74                                1e-14));
75         TS_ASSERT_EQUALS( b * rotate_degrees(90.), NR::rot90(b) );
76     }
78     void testOpStarRotateRotate(void)
79     {
80         TS_ASSERT_EQUALS( r_id * r_id, r_id );
81         TS_ASSERT_EQUALS( rot180 * rot180, r_id );
82         TS_ASSERT_EQUALS( rot234 * r_id, rot234 );
83         TS_ASSERT_EQUALS( r_id * rot234, rot234 );
84         TS_ASSERT( rotate_equalp(rot234 * rot234.inverse(), r_id, 1e-14) );
85         TS_ASSERT( rotate_equalp(rot234.inverse() * rot234, r_id, 1e-14) );
86         TS_ASSERT( rotate_equalp(( NR::rotate(0.25) * NR::rotate(.5) ),
87                                  NR::rotate(.75),
88                                  1e-10) );
89     }
91     void testOpDivRotateRotate(void)
92     {
93         TS_ASSERT_EQUALS( rot234 / r_id, rot234 );
94         TS_ASSERT_EQUALS( rot234 / rot180, rot234 * rot180 );
95         TS_ASSERT( rotate_equalp(rot234 / rot234, r_id, 1e-14) );
96         TS_ASSERT( rotate_equalp(r_id / rot234, rot234.inverse(), 1e-14) );
97     }
99 };
101 /*
102   Local Variables:
103   mode:c++
104   c-file-style:"stroustrup"
105   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106   indent-tabs-mode:nil
107   fill-column:99
108   End:
109 */
110 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :