Code

Merge from fe-moved
[inkscape.git] / src / libnr / nr-convert2geom.h
1 #ifndef INKSCAPE_LIBNR_CONVERT2GEOM_H
2 #define INKSCAPE_LIBNR_CONVERT2GEOM_H
4 /*
5  * Converts between NR and 2Geom types.
6  *
7 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #include <libnr/nr-matrix.h>
13 #include <libnr/nr-rect.h>
14 #include <libnr/nr-point.h>
15 #include <2geom/matrix.h>
16 #include <2geom/d2.h>
17 #include <2geom/transforms.h>
18 #include <2geom/point.h>
20 inline Geom::Point to_2geom(NR::Point const & _pt) {
21     return Geom::Point(_pt[0], _pt[1]);
22 }
23 inline NR::Point from_2geom(Geom::Point const & _pt) {
24     return NR::Point(_pt[0], _pt[1]);
25 }
27 inline Geom::Matrix to_2geom(NR::Matrix const & mat) {
28     Geom::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
29     return mat2geom;
30 }
31 inline NR::Matrix from_2geom(Geom::Matrix const & mat) {
32     NR::Matrix mat2geom(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
33     return mat2geom;
34 }
36 inline Geom::Translate to_2geom(NR::translate const & mat) {
37     return Geom::Translate( mat.offset[0], mat.offset[1] );
38 }
40 inline Geom::Rect to_2geom(NR::Rect const & rect) {
41     Geom::Rect rect2geom(to_2geom(rect.min()), to_2geom(rect.max()));
42     return rect2geom;
43 }
44 inline NR::Rect from_2geom(Geom::Rect const & rect2geom) {
45     NR::Rect rect(rect2geom.min(), rect2geom.max());
46     return rect;
47 }
48 inline Geom::OptRect to_2geom(boost::optional<NR::Rect> const & rect) {
49     Geom::OptRect rect2geom;
50     if (!rect) {
51         return rect2geom;
52     }
53     rect2geom = to_2geom(*rect);
54     return rect2geom;
55 }
57 inline NR::scale from_2geom(Geom::Scale const & in) {
58     return NR::scale(in[Geom::X], in[Geom::Y]);
59 }
60 inline Geom::Scale to_2geom(NR::scale const & in) {
61     return Geom::Scale(in[NR::X], in[NR::Y]);
62 }
64 #endif
66 /*
67   Local Variables:
68   mode:c++
69   c-file-style:"stroustrup"
70   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
71   indent-tabs-mode:nil
72   fill-column:99
73   End:
74 */
75 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :