Code

Move all of the snapper code to 2geom
[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  *    Diederik van Lierop <mail@diedenrezi.nl>
8  *
9  *  Released under GNU GPL, read the file 'COPYING' for more information.
10  */
12 #include "snapped-point.h"
14 // overloaded constructor
15 Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a)
16     : _point(p), _target(target), _distance(d), _tolerance(t), _always_snap(a)
17 {
18     _at_intersection = false;
19     _second_distance = NR_HUGE;
20     _second_tolerance = 0;
21     _second_always_snap = false;
22     _transformation = Geom::Point(1,1);
23 }
25 Inkscape::SnappedPoint::SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2)
26     : _point(p), _target(target), _at_intersection(at_intersection), _distance(d), _tolerance(t), _always_snap(a),
27     _second_distance(d2), _second_tolerance(t2), _second_always_snap(a2)
28 {
29     _transformation = Geom::Point(1,1);
30 }
32 Inkscape::SnappedPoint::SnappedPoint()
33 {
34     _point = Geom::Point(0,0);
35     _target = SNAPTARGET_UNDEFINED, 
36     _distance = NR_HUGE;
37     _tolerance = 0;
38     _always_snap = false;
39     _at_intersection = false;
40     _second_distance = NR_HUGE;
41     _second_tolerance = 0;
42     _second_always_snap = false;
43     _transformation = Geom::Point(1,1);
44 }
48 Inkscape::SnappedPoint::~SnappedPoint()
49 {
50 }
52 Geom::Coord Inkscape::SnappedPoint::getDistance() const
53 {
54     return _distance;
55 }
57 Geom::Coord Inkscape::SnappedPoint::getTolerance() const
58 {
59     return _tolerance;
60 }
62 bool Inkscape::SnappedPoint::getAlwaysSnap() const
63 {
64     return _always_snap;
65 }
67 Geom::Coord Inkscape::SnappedPoint::getSecondDistance() const
68 {
69     return _second_distance;
70 }
72 Geom::Coord Inkscape::SnappedPoint::getSecondTolerance() const
73 {
74     return _second_tolerance;
75 }
77 bool Inkscape::SnappedPoint::getSecondAlwaysSnap() const
78 {
79     return _second_always_snap;
80 }
83 void Inkscape::SnappedPoint::getPoint(Geom::Point &p) const
84 {
85     // When we have snapped
86     if (getSnapped()) { 
87         // then return the snapped point by overwriting p
88         p = _point;
89     } //otherwise p will be left untouched; this way the caller doesn't have to check wether we've snapped
90 }
92 // search for the closest snapped point
93 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result)
94 {
95     bool success = false;
97     for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); i++) {
98         if ((i == list.begin()) || (*i).getDistance() < result.getDistance()) {
99             result = *i;
100             success = true;
101         }
102     }
104     return success;
107 /*
108   Local Variables:
109   mode:c++
110   c-file-style:"stroustrup"
111   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
112   indent-tabs-mode:nil
113   fill-column:99
114   End:
115 */
116 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :