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 const &p, SnapTargetType const &target, NR::Coord const &d, NR::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 = NR::Point(1,1);
23 }
25 Inkscape::SnappedPoint::SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a, bool const &at_intersection, NR::Coord const &d2, NR::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 = NR::Point(1,1);
30 }
32 Inkscape::SnappedPoint::SnappedPoint()
33 {
34 _point = NR::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 = NR::Point(1,1);
44 }
48 Inkscape::SnappedPoint::~SnappedPoint()
49 {
50 }
52 NR::Coord Inkscape::SnappedPoint::getDistance() const
53 {
54 return _distance;
55 }
57 NR::Coord Inkscape::SnappedPoint::getTolerance() const
58 {
59 return _tolerance;
60 }
62 bool Inkscape::SnappedPoint::getAlwaysSnap() const
63 {
64 return _always_snap;
65 }
67 NR::Coord Inkscape::SnappedPoint::getSecondDistance() const
68 {
69 return _second_distance;
70 }
72 NR::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 NR::Point Inkscape::SnappedPoint::getPoint() const
84 {
85 return _point;
86 }
88 // search for the closest snapped point
89 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result)
90 {
91 bool success = false;
93 for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); i++) {
94 if ((i == list.begin()) || (*i).getDistance() < result.getDistance()) {
95 result = *i;
96 success = true;
97 }
98 }
100 return success;
101 }
103 /*
104 Local Variables:
105 mode:c++
106 c-file-style:"stroustrup"
107 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
108 indent-tabs-mode:nil
109 fill-column:99
110 End:
111 */
112 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :