Code

bulk whitespace removal patch #1198588 by gigaclon
[inkscape.git] / src / snapper.cpp
1 /**
2  *  \file src/snapper.cpp
3  *  \brief Snapper class.
4  *
5  *  Authors:
6  *    Carl Hetherington <inkscape@carlh.net>
7  *
8  *  Released under GNU GPL, read the file 'COPYING' for more information.
9  */
11 #include "libnr/nr-values.h"
12 #include "sp-namedview.h"
14 Inkscape::Snapper::PointType const Inkscape::Snapper::BBOX_POINT = 0x1;
15 Inkscape::Snapper::PointType const Inkscape::Snapper::SNAP_POINT = 0x2;
17 /**
18  *  Construct new Snapper for named view.
19  *  \param nv Named view.
20  *  \param d Snap distance.
21  */
22 Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_view(nv), _distance(d)
23 {
24     g_assert(_named_view != NULL);
25     g_assert(SP_IS_NAMEDVIEW(_named_view));
26     
27     setSnapTo(BBOX_POINT, true);
28 }
30 /**
31  *  Set snap distance.
32  *  \param d New snap distance (desktop coordinates)
33  */
34 void Inkscape::Snapper::setDistance(NR::Coord const d)
35 {
36     _distance = d;
37 }
39 /**
40  *  \return Snap distance (desktop coordinates)
41  */
42 NR::Coord Inkscape::Snapper::getDistance() const
43 {
44     return _distance;
45 }
47 /**
48  *  Turn on/off snapping of specific point types.
49  *  \param t Point type.
50  *  \param s true to snap to this point type, otherwise false;
51  */
52 void Inkscape::Snapper::setSnapTo(PointType t, bool s)
53 {
54     if (s) {
55         _snap_to |= t;
56     } else {
57         _snap_to &= ~t;
58     }
59 }
61 /**
62  *  \param t Point type.
63  *  \return true if snapper will snap this type of point, otherwise false.
64  */
65 bool Inkscape::Snapper::getSnapTo(PointType t) const
66 {
67     return (_snap_to & t);
68 }
70 /**
71  *  \return true if this Snapper will snap at least one kind of point.
72  */
73 bool Inkscape::Snapper::willSnapSomething() const
74 {
75     return (_snap_to != 0);
76 }
80 /**
81  *  Try to snap a point to whatever this snapper is interested in.  Any
82  *  snap that occurs will be to the nearest "interesting" thing (e.g. a
83  *  grid or guide line)
84  *
85  *  \param t Point type.
86  *  \param p Point to snap (desktop coordinates).
87  *  \param it Item that should not be snapped to.
88  *  \return Snapped point.
89  */
91 Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
92                                                    NR::Point const &p,
93                                                    SPItem const *it) const
94 {
95     std::list<SPItem const *> lit;
96     lit.push_back(it);
97     return freeSnap(t, p, lit);
98 }
101 /**
102  *  Try to snap a point to whatever this snapper is interested in.  Any
103  *  snap that occurs will be to the nearest "interesting" thing (e.g. a
104  *  grid or guide line)
105  *
106  *  \param t Point type.
107  *  \param p Point to snap (desktop coordinates).
108  *  \param it Items that should not be snapped to.
109  *  \return Snapped point.
110  */
112 Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
113                                                    NR::Point const &p,
114                                                    std::list<SPItem const *> const &it) const
116     if (getSnapTo(t) == false) {
117         return SnappedPoint(p, NR_HUGE);
118     }
120     return _doFreeSnap(p, it);
126 /**
127  *  Try to snap a point to whatever this snapper is interested in, where
128  *  the snap point is constrained to lie along a specified vector from the
129  *  original point.
130  *
131  *  \param p Point to snap (desktop coordinates).
132  *  \param c Vector to constrain the snap to.
133  *  \param it Items that should not be snapped to.
134  *  \return Snapped point.
135  */
137 Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType t,
138                                                           NR::Point const &p,
139                                                           NR::Point const &c,
140                                                           SPItem const *it) const
142     std::list<SPItem const *> lit;
143     lit.push_back(it);
144     return constrainedSnap(t, p, c, lit);
148 /**
149  *  Try to snap a point to whatever this snapper is interested in, where
150  *  the snap point is constrained to lie along a specified vector from the
151  *  original point.
152  *
153  *  \param p Point to snap (desktop coordinates).
154  *  \param c Vector to constrain the snap to.
155  *  \param it Items that should not be snapped to.
156  *  \return Snapped point.
157  */
159 Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType t,
160                                                           NR::Point const &p,
161                                                           NR::Point const &c,
162                                                           std::list<SPItem const *> const &it) const
164     if (getSnapTo(t) == false) {
165         return SnappedPoint(p, NR_HUGE);
166     }
168     return _doConstrainedSnap(p, c, it);
171 /*
172   Local Variables:
173   mode:c++
174   c-file-style:"stroustrup"
175   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
176   indent-tabs-mode:nil
177   fill-column:99
178   End:
179 */
180 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :