Code

Groundwork to snap to intersections, e.g. intersections of gridlines with guidelines...
[inkscape.git] / src / snapped-point.cpp
1 /**
2  *  \file src/snapped-point.cpp
3  *  \brief SnappedPoint class.
4  *
5  *  Authors:
6  *    Mathieu Dimanche <mdimanche@free.fr>
7  *
8  *  Released under GNU GPL, read the file 'COPYING' for more information.
9  */
11 #include "snapped-point.h"
12 #include <libnr/nr-values.h>
14 Inkscape::SnappedPoint::SnappedPoint(NR::Point p, NR::Coord d, bool at_intersection)
15     : _distance(d), _point(p), _at_intersection(at_intersection)
16 {
17 }
19 Inkscape::SnappedPoint::SnappedPoint()
20 {
21         _distance = NR_HUGE;
22         _point = NR::Point(0,0);
23         _at_intersection = false;
24 }
28 Inkscape::SnappedPoint::~SnappedPoint()
29 {
30 }
32 NR::Coord Inkscape::SnappedPoint::getDistance() const
33 {
34     return _distance;
35 }
37 NR::Point Inkscape::SnappedPoint::getPoint() const
38 {
39     return _point;
40 }
42 // search for the closest snapped point
43 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result) 
44 {
45         bool success = false;
46         
47         for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); i++) {
48                 if ((i == list.begin()) || (*i).getDistance() < result.getDistance()) {
49                         result = *i;
50                         success = true;
51                 }       
52         }
53         
54         return success;
55 }
57 /*
58   Local Variables:
59   mode:c++
60   c-file-style:"stroustrup"
61   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
62   indent-tabs-mode:nil
63   fill-column:99
64   End:
65 */
66 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :