Code

compile depending on WITH_LIBWPG
[inkscape.git] / src / libnr / nr-translate-test.cpp
1 #include <utest/utest.h>
2 #include <libnr/nr-point-ops.h>
3 #include <libnr/nr-matrix.h>
4 #include <libnr/nr-matrix-fns.h>
5 #include <libnr/nr-matrix-ops.h>
6 #include <libnr/nr-point-matrix-ops.h>
7 #include <libnr/nr-translate.h>
8 #include <libnr/nr-translate-ops.h>
9 using NR::X;
10 using NR::Y;
13 int main(int argc, char *argv[])
14 {
15     utest_start("translate");
17     NR::Point const b(-2.0, 3.0);
18     NR::translate const tb(b);
19     NR::translate const tc(-3.0, -2.0);
20     UTEST_TEST("constructors, operator[]") {
21         UTEST_ASSERT( tc[X] == -3.0 && tc[Y] == -2.0 );
22         UTEST_ASSERT( tb[0] == b[X] && tb[1] == b[Y] );
23     }
25     UTEST_TEST("operator=") {
26         NR::translate tb_eq(tc);
27         tb_eq = tb;
28         UTEST_ASSERT( tb == tb_eq );
29         UTEST_ASSERT( tb_eq != tc );
30     }
32     NR::translate const tbc( tb * tc );
33     UTEST_TEST("operator*(translate, translate)") {
34         UTEST_ASSERT( tbc.offset == NR::Point(-5.0, 1.0) );
35         UTEST_ASSERT( tbc.offset == ( tc * tb ).offset );
36         UTEST_ASSERT( NR::Matrix(tbc) == NR::Matrix(tb) * NR::Matrix(tc) );
37     }
39     UTEST_TEST("operator*(Point, translate)") {
40         UTEST_ASSERT( tbc.offset == b * tc );
41         UTEST_ASSERT( b * tc == b * NR::Matrix(tc) );
42     }
44     NR::translate const t_id(0.0, 0.0);
45     NR::Matrix const m_id(NR::identity());
46     UTEST_TEST("identity") {
47         UTEST_ASSERT( b * t_id == b );
48         UTEST_ASSERT( NR::Matrix(t_id) == m_id );
49     }
51     return ( utest_end()
52              ? EXIT_SUCCESS
53              : EXIT_FAILURE );
54 }
56 /*
57   Local Variables:
58   mode:c++
59   c-file-style:"stroustrup"
60   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
61   indent-tabs-mode:nil
62   fill-column:99
63   End:
64 */
65 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :