Code

Indent support for XSLT extensions output.
[inkscape.git] / src / line-geometry.h
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 <boost/optional.hpp>
16 #include "glib.h"
17 #include "display/sp-ctrlline.h"
18 #include "axis-manip.h" // FIXME: This is only for Box3D::epsilon; move that to a better location
20 #include "document.h"
21 #include "ui/view/view.h"
23 namespace Box3D {
25 class Line {
26 public:
27     Line(Geom::Point const &start, Geom::Point const &vec, bool is_endpoint = true);
28     Line(Line const &line);
29     virtual ~Line() {}
30     Line &operator=(Line const &line);
31     virtual boost::optional<Geom::Point> intersect(Line const &line);
32     inline Geom::Point direction () { return v_dir; }
33     
34     Geom::Point closest_to(Geom::Point const &pt); // returns the point on the line closest to pt 
36     friend inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line);
37     boost::optional<Geom::Point> intersection_with_viewbox (SPDesktop *desktop);
38     inline bool lie_on_same_side (Geom::Point const &A, Geom::Point const &B) {
39         /* If A is a point in the plane and n is the normal vector of the line then
40            the sign of dot(A, n) specifies the half-plane in which A lies.
41            Thus A and B lie on the same side if the dot products have equal sign. */
42         return ((Geom::dot(A, normal) - d0) * (Geom::dot(B, normal) - d0)) > 0;
43     }
45     double lambda (Geom::Point const pt);
46     inline Geom::Point point_from_lambda (double const lambda) { 
47         return (pt + lambda * Geom::unit_vector (v_dir)); }
49 protected:
50     void set_direction(Geom::Point const &dir);
51     inline static bool pts_coincide (Geom::Point const pt1, Geom::Point const pt2)
52     {
53         return (Geom::L2 (pt2 - pt1) < epsilon);
54     }
56     Geom::Point pt;
57     Geom::Point v_dir;
58     Geom::Point normal;
59     Geom::Coord d0;
60 };
62 inline double determinant (Geom::Point const &a, Geom::Point const &b)
63 {
64     return (a[Geom::X] * b[Geom::Y] - a[Geom::Y] * b[Geom::X]);
65 }
66 std::pair<double, double> coordinates (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w);
67 bool lies_in_sector (Geom::Point const &v1, Geom::Point const &v2, Geom::Point const &w);
68 bool lies_in_quadrangle (Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::Point const &D, Geom::Point const &pt);
69 std::pair<Geom::Point, Geom::Point> side_of_intersection (Geom::Point const &A, Geom::Point const &B,
70                                                           Geom::Point const &C, Geom::Point const &D,
71                                                           Geom::Point const &pt, Geom::Point const &dir);
73 /*** For debugging purposes: Draw a knot/node of specified size and color at the given position ***/
74 void create_canvas_point(Geom::Point const &pos, double size = 4.0, guint32 rgba = 0xff00007f);
76 /*** For debugging purposes: Draw a line between the specified points ***/
77 void create_canvas_line(Geom::Point const &p1, Geom::Point const &p2, guint32 rgba = 0xff00007f);
80 /** A function to print out the Line.  It just prints out the coordinates of start point and
81     direction on the given output stream */
82 inline std::ostream &operator<< (std::ostream &out_file, const Line &in_line) {
83     out_file << "Start: " << in_line.pt << "  Direction: " << in_line.v_dir;
84     return out_file;
85 }
87 } // namespace Box3D
90 #endif /* !SEEN_LINE_GEOMETRY_H */
92 /*
93   Local Variables:
94   mode:c++
95   c-file-style:"stroustrup"
96   c-file-offsets:((innamespace . 0)(inline-open . 0))
97   indent-tabs-mode:nil
98   fill-column:99
99   End:
100 */
101 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :