Code

Next steps in implementing the snapping indicator
[inkscape.git] / src / snapped-line.h
1 #ifndef SEEN_SNAPPEDLINE_H
2 #define SEEN_SNAPPEDLINE_H
4 /**
5  *    \file src/snapped-line.h
6  *    \brief SnappedLine class.
7  *
8  *    Authors:
9  *      Diederik van Lierop <mail@diedenrezi.nl>
10  *
11  *    Released under GNU GPL, read the file 'COPYING' for more information.
12  */
14 #include <vector>
15 #include <list>
16 #include "libnr/nr-coord.h"
17 #include "libnr/nr-point.h"
18 #include <libnr/nr-point-fns.h>
19 #include "snapped-point.h"
21 namespace Inkscape
22 {
24 /// Class describing the result of an attempt to snap to a line segment.
25 class SnappedLineSegment : public SnappedPoint
26 {
27 public:
28     SnappedLineSegment();
29     SnappedLineSegment(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &start_point_of_line, NR::Point const &end_point_of_line);
30     ~SnappedLineSegment();
31     Inkscape::SnappedPoint intersect(SnappedLineSegment const &line) const; //intersect with another SnappedLineSegment
32     
33 private:
34     NR::Point _start_point_of_line;
35     NR::Point _end_point_of_line;    
36 };
39 /// Class describing the result of an attempt to snap to a line.
40 class SnappedLine : public SnappedPoint
41 {
42 public:
43     SnappedLine();
44     SnappedLine(NR::Point const &snapped_point, NR::Coord const &snapped_distance, NR::Coord const &snapped_tolerance, bool const &always_snap, NR::Point const &normal_to_line, NR::Point const &point_on_line);
45     ~SnappedLine();
46     Inkscape::SnappedPoint intersect(SnappedLine const &line) const; //intersect with another SnappedLine
47     // This line is described by this equation:
48     //        a*x + b*y = c  <->  nx*px + ny+py = c  <->  n.p = c
49     NR::Point getNormal() const {return _normal_to_line;}                             // n = (nx, ny)
50     NR::Point getPointOnLine() const {return _point_on_line;}                         // p = (px, py)
51     NR::Coord getConstTerm() const {return dot(_normal_to_line, _point_on_line);}     // c = n.p = nx*px + ny*py;
52     
53 private:
54     NR::Point _normal_to_line;
55     NR::Point _point_on_line;    
56 };
58 }
60 bool getClosestSLS(std::list<Inkscape::SnappedLineSegment> const &list, Inkscape::SnappedLineSegment &result);
61 bool getClosestIntersectionSLS(std::list<Inkscape::SnappedLineSegment> const &list, Inkscape::SnappedPoint &result);
62 bool getClosestSL(std::list<Inkscape::SnappedLine> const &list, Inkscape::SnappedLine &result);
63 bool getClosestIntersectionSL(std::list<Inkscape::SnappedLine> const &list, Inkscape::SnappedPoint &result);
64 bool getClosestIntersectionSL(std::list<Inkscape::SnappedLine> const &list1, std::list<Inkscape::SnappedLine> const &list2, Inkscape::SnappedPoint &result);
65  
67 #endif /* !SEEN_SNAPPEDLINE_H */
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :