Code

make spcurve::first_point and last_point boost::optional
[inkscape.git] / src / transf_mat_3x4.h
1 #ifndef SEEN_TRANSF_MAT_3x4_H
2 #define SEEN_TRANSF_MAT_3x4_H
4 /*
5  * 3x4 transformation matrix to map points from projective 3-space into the projective plane
6  *
7  * Authors:
8  *   Maximilian Albert <Anhalter42@gmx.de>
9  *
10  * Copyright (C) 2007  Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "libnr/nr-point-fns.h"
16 #include "proj_pt.h"
17 #include "axis-manip.h"
19 namespace Proj {
21 class TransfMat3x4 {
22 public:
23     TransfMat3x4();
24     TransfMat3x4(Pt2 vp_x, Pt2 vp_y, Pt2 vp_z, Pt2 origin);
25     TransfMat3x4(TransfMat3x4 const &rhs);
26     Pt2 column (Proj::Axis axis) const;
27     Pt2 image (Pt3 const &point);
28     Pt3 preimage (NR::Point const &pt, double coord = 0, Axis = Z);
29     void set_image_pt (Proj::Axis axis, Proj::Pt2 const &pt);
30     void toggle_finite (Proj::Axis axis);
31     double get_infinite_angle (Proj::Axis axis) {
32         if (has_finite_image(axis)) {
33             return NR_HUGE;
34         }
35         Pt2 vp(column(axis));
36         return NR::atan2(NR::Point(vp[0], vp[1])) * 180.0/M_PI;
37     }
38     void set_infinite_direction (Proj::Axis axis, double angle) { // angle is in degrees
39         g_return_if_fail(tmat[2][axis] == 0); // don't set directions for finite VPs
41         double a = angle * M_PI/180;
42         NR::Point pt(tmat[0][axis], tmat[1][axis]);
43         double rad = NR::L2(pt);
44         set_image_pt(axis, Proj::Pt2(cos (a) * rad, sin (a) * rad, 0.0));
45     }
46     inline bool has_finite_image (Proj::Axis axis) { return (tmat[2][axis] != 0.0); }
48     gchar * pt_to_str (Proj::Axis axis);
50     bool operator==(const TransfMat3x4 &rhs) const;
51     TransfMat3x4 operator*(NR::Matrix const &A) const;
52     TransfMat3x4 &operator*=(NR::Matrix const &A);
54     void print() const;
56     void copy_tmat(double rhs[3][4]);
58 private:
59     // FIXME: Is changing a single column allowed when a projective coordinate system is specified!?!?!
60     void normalize_column (Proj::Axis axis);
61     inline void set_column (Proj::Axis axis, Proj::Pt2 pt) {
62         tmat[0][axis] = pt[0];
63         tmat[1][axis] = pt[1];
64         tmat[2][axis] = pt[2];
65     }
66     double tmat[3][4];
67 };
69 } // namespace Proj
71 #endif /* __TRANSF_MAT_3x4_H__ */
73 /*
74   Local Variables:
75   mode:c++
76   c-file-style:"stroustrup"
77   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
78   indent-tabs-mode:nil
79   fill-column:99
80   End:
81 */
82 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :