1 /*
2 * Routines for dealing with lines (intersections, etc.)
3 *
4 * Authors:
5 * Maximilian Albert <Anhalter42@gmx.de>
6 *
7 * Copyright (C) 2007 authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifndef SEEN_LINE_GEOMETRY_H
13 #define SEEN_LINE_GEOMETRY_H
15 #include "libnr/nr-point.h"
16 #include "libnr/nr-point-fns.h"
17 #include "libnr/nr-maybe.h"
18 #include "glib.h"
19 #include "display/sp-ctrlline.h"
20 #include "vanishing-point.h"
22 #include "document.h"
23 #include "ui/view/view.h"
25 namespace Box3D {
27 class Line {
28 public:
29 Line(NR::Point const &start, NR::Point const &vec, bool is_endpoint = true);
30 Line(Line const &line);
31 Line &operator=(Line const &line);
32 virtual NR::Maybe<NR::Point> intersect(Line const &line);
33 void set_direction(NR::Point const &dir); // FIXME: Can we avoid this explicit assignment?
35 NR::Point closest_to(NR::Point const &pt); // returns the point on the line closest to pt
37 friend inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line);
38 //private:
39 NR::Point pt;
40 NR::Point v_dir;
41 NR::Point normal;
42 NR::Coord d0;
43 };
45 std::pair<double, double> coordinates (NR::Point const &v1, NR::Point const &v2, NR::Point const &w);
46 bool lies_in_sector (NR::Point const &v1, NR::Point const &v2, NR::Point const &w);
47 std::pair<NR::Point, NR::Point> side_of_intersection (NR::Point const &A, NR::Point const &B,
48 NR::Point const &C, NR::Point const &D,
49 NR::Point const &pt, NR::Point const &dir);
51 /*** For testing purposes: Draw a knot/node of specified size and color at the given position ***/
52 void create_canvas_point(NR::Point const &pos, double size = 4.0, guint32 rgba = 0xff00007f);
54 /*** For testing purposes: Draw a line between the specified points ***/
55 void create_canvas_line(NR::Point const &p1, NR::Point const &p2, guint32 rgba = 0xff00007f);
58 /** A function to print out the Line. It just prints out the coordinates of start point and
59 direction on the given output stream */
60 inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line) {
61 out_file << "Start: " << in_line.pt << " Direction: " << in_line.v_dir;
62 return out_file;
63 }
65 } // namespace Box3D
68 #endif /* !SEEN_LINE_GEOMETRY_H */
70 /*
71 Local Variables:
72 mode:c++
73 c-file-style:"stroustrup"
74 c-file-offsets:((innamespace . 0)(inline-open . 0))
75 indent-tabs-mode:nil
76 fill-column:99
77 End:
78 */
79 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :