Code

Use subdirectories with icon sizes.
[inkscape.git] / src / libnr / nr-rotate-fns.cpp
1 /** \file
2  * Functions to/from NR::rotate.
3  */
4 #include <glib.h>
5 #include "libnr/nr-rotate-ops.h"
6 #include "libnr/nr-rotate-fns.h"
8 /**
9  * Returns a rotation matrix corresponding by the specified angle about the origin.
10  *
11  * Angle direction in Inkscape code: If you use the traditional mathematics convention that y
12  * increases upwards, then positive angles are anticlockwise as per the mathematics convention.  If
13  * you take the common non-mathematical convention that y increases downwards, then positive angles
14  * are clockwise, as is common outside of mathematics.
15  */
16 NR::rotate
17 rotate_degrees(double degrees)
18 {
19     if (degrees < 0) {
20         return rotate_degrees(-degrees).inverse();
21     }
23     double const degrees0 = degrees;
24     if (degrees >= 360) {
25         degrees = fmod(degrees, 360);
26     }
28     NR::rotate ret(1., 0.);
30     if (degrees >= 180) {
31         NR::rotate const rot180(-1., 0.);
32         degrees -= 180;
33         ret = rot180;
34     }
36     if (degrees >= 90) {
37         NR::rotate const rot90(0., 1.);
38         degrees -= 90;
39         ret *= rot90;
40     }
42     if (degrees == 45) {
43         NR::rotate const rot45(M_SQRT1_2, M_SQRT1_2);
44         ret *= rot45;
45     } else {
46         double const radians = M_PI * ( degrees / 180 );
47         ret *= NR::rotate(cos(radians), sin(radians));
48     }
50     NR::rotate const raw_ret( M_PI * ( degrees0 / 180 ) );
51     g_return_val_if_fail(rotate_equalp(ret, raw_ret, 1e-8),
52                          raw_ret);
53     return ret;
54 }
57 /*
58   Local Variables:
59   mode:c++
60   c-file-style:"stroustrup"
61   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
62   indent-tabs-mode:nil
63   fill-column:99
64   End:
65 */
66 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :