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(NR::Point p, NR::Coord d, NR::Coord t, bool a)
16 : _point(p), _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 = NR::Point(1,1);
23 }
25 Inkscape::SnappedPoint::SnappedPoint(NR::Point p, NR::Coord d, NR::Coord t, bool a, bool at_intersection, NR::Coord d2, NR::Coord t2, bool a2)
26 : _point(p), _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 = NR::Point(1,1);
30 }
32 Inkscape::SnappedPoint::SnappedPoint()
33 {
34 _point = NR::Point(0,0);
35 _distance = NR_HUGE;
36 _tolerance = 0;
37 _always_snap = false;
38 _at_intersection = false;
39 _second_distance = NR_HUGE;
40 _second_tolerance = 0;
41 _second_always_snap = false;
42 _transformation = NR::Point(1,1);
43 }
47 Inkscape::SnappedPoint::~SnappedPoint()
48 {
49 }
51 NR::Coord Inkscape::SnappedPoint::getDistance() const
52 {
53 return _distance;
54 }
56 NR::Coord Inkscape::SnappedPoint::getTolerance() const
57 {
58 return _tolerance;
59 }
61 bool Inkscape::SnappedPoint::getAlwaysSnap() const
62 {
63 return _always_snap;
64 }
66 NR::Coord Inkscape::SnappedPoint::getSecondDistance() const
67 {
68 return _second_distance;
69 }
71 NR::Coord Inkscape::SnappedPoint::getSecondTolerance() const
72 {
73 return _second_tolerance;
74 }
76 bool Inkscape::SnappedPoint::getSecondAlwaysSnap() const
77 {
78 return _second_always_snap;
79 }
82 NR::Point Inkscape::SnappedPoint::getPoint() const
83 {
84 return _point;
85 }
87 // search for the closest snapped point
88 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result)
89 {
90 bool success = false;
92 for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); i++) {
93 if ((i == list.begin()) || (*i).getDistance() < result.getDistance()) {
94 result = *i;
95 success = true;
96 }
97 }
99 return success;
100 }
102 /*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :