Code

Draw perspective lines for infinite VPs, too (they are updated during scrolling or...
[inkscape.git] / src / perspective-line.cpp
1 #define __PERSPECTIVE_LINE_C__
3 /*
4  * Perspective line for 3D perspectives
5  *
6  * Authors:
7  *   Maximilian Albert <Anhalter42@gmx.de>
8  *
9  * Copyright (C) 2007 authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "perspective-line.h"
15 #include "desktop.h"
17 namespace Box3D {
19 PerspectiveLine::PerspectiveLine (NR::Point const &pt, Box3D::Axis const axis, Perspective3D *perspective) :
20         Line (pt, *(perspective->get_vanishing_point(axis)), true)
21 {
22     g_assert (perspective != NULL);
23     g_assert (Box3D::is_single_axis_direction (axis));
25     if (perspective->get_vanishing_point(axis)->state == VP_INFINITE) {
26         this->set_direction(perspective->get_vanishing_point(axis)->v_dir);
27     }
28     this->vp_dir = axis;
29     this->persp  = perspective;
30 }
32 // This function makes sure not to return NR::Nothing()
33 // FIXME: How to gracefully handle parallel lines?
34 NR::Maybe<NR::Point> PerspectiveLine::intersect (Line const &line)
35 {
36     NR::Maybe<NR::Point> pt = this->Line::intersect(line);
37     if (!pt) {
38         Box3D::VanishingPoint vp = *(persp->get_vanishing_point(vp_dir));
39         if (vp.state == VP_INFINITE) {
40             pt = vp;
41         } else {
42             pt = NR::Point (0.0, 0.0); // FIXME: Better solution needed
43         }
44     }
45     return pt; 
46 }
48 // FIXME: Do we really need two intersection methods?
49 NR::Point PerspectiveLine::meet(Line const &line)
50 {
51     return *intersect(line); // works since intersect() does not return NR::Nothing()
52 }
54 NR::Maybe<NR::Point> PerspectiveLine::intersection_with_viewbox (SPDesktop *desktop)
55 {
56     NR::Rect vb = desktop->get_display_area();
57     /* remaining viewbox corners */
58     NR::Point ul (vb.min()[NR::X], vb.max()[NR::Y]);
59     NR::Point lr (vb.max()[NR::X], vb.min()[NR::Y]);
61     std::pair <NR::Point, NR::Point> e = side_of_intersection (vb.min(), lr, vb.max(), ul, this->pt, this->v_dir);
62     if (e.first == e.second) {
63         // perspective line lies outside the canvas
64         return NR::Nothing();
65     }
67     Line line (e.first, e.second);
68     return this->intersect (line);
69 }
71 } // namespace Box3D 
72  
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 :