22 _equal_distance(
Geom::infinity()),
25 _source_num(source_num),
27 _at_intersection (false),
28 _constrained_snap (constrained_snap),
29 _fully_constrained (fully_constrained),
31 _tolerance(
std::max(t,1.0)),
33 _second_distance (
Geom::infinity()),
34 _second_tolerance (1),
35 _second_always_snap (false),
36 _target_bbox(
std::move(target_bbox)),
37 _pointer_distance (
Geom::infinity())
41Inkscape::SnappedPoint::SnappedPoint(
Geom::Point const &p,
Geom::Point const &ap,
SnapSourceType const &source,
long source_num,
SnapTargetType const &target,
Geom::Coord const &d,
Geom::Coord const &t,
bool const &a,
bool const &constrained_snap,
bool const &fully_constrained,
Geom::OptRect target_bbox) :
43 _alignment_target(ap),
45 _alignment_target_type(target),
46 _equal_distance(
Geom::infinity()),
49 _source_num(source_num),
51 _at_intersection (false),
52 _constrained_snap (constrained_snap),
53 _fully_constrained (fully_constrained),
55 _tolerance(
std::max(t,1.0)),
57 _second_distance (
Geom::infinity()),
58 _second_tolerance (1),
59 _second_always_snap (false),
60 _target_bbox(
std::move(target_bbox)),
61 _pointer_distance (
Geom::infinity())
65Inkscape::SnappedPoint::SnappedPoint(
Geom::Point const &p,
Geom::Point const &ap,
Geom::Point const &ap2,
SnapSourceType const &source,
long source_num,
SnapTargetType const &target,
Geom::Coord const &d,
Geom::Coord const &t,
bool const &a,
bool const &constrained_snap,
bool const &fully_constrained,
Geom::OptRect target_bbox) :
67 _alignment_target(ap),
68 _alignment_target2(ap2),
69 _alignment_target_type(target),
70 _equal_distance(
Geom::infinity()),
73 _source_num(source_num),
75 _at_intersection (false),
76 _constrained_snap (constrained_snap),
77 _fully_constrained (fully_constrained),
79 _tolerance(
std::max(t,1.0)),
81 _second_distance (
Geom::infinity()),
82 _second_tolerance (1),
83 _second_always_snap (false),
84 _target_bbox(
std::move(target_bbox)),
85 _pointer_distance (
Geom::infinity())
89Inkscape::SnappedPoint::SnappedPoint(
Geom::Point const &p, std::vector<Geom::Rect>
const &bboxes,
Geom::Rect const &source_bbox,
Geom::Coord equal_dist,
SnapSourceType const &source,
long source_num,
SnapTargetType const &target,
Geom::Coord const &d,
Geom::Coord const &t,
bool const &a,
bool const &constrained_snap,
bool const &fully_constrained) :
91 _equal_distance(equal_dist),
92 _distribution_bboxes(
std::move(bboxes)),
93 _source_bbox(source_bbox),
96 _source_num(source_num),
98 _at_intersection (false),
99 _constrained_snap (constrained_snap),
100 _fully_constrained (fully_constrained),
102 _tolerance(
std::max(t,1.0)),
104 _second_distance (
Geom::infinity()),
105 _second_tolerance (1),
106 _second_always_snap (false),
108 _pointer_distance (
Geom::infinity())
112Inkscape::SnappedPoint::SnappedPoint(
Geom::Point const &p, std::vector<Geom::Rect>
const &bboxes, std::vector<Geom::Rect>
const &bboxes2,
Geom::Rect const &source_bbox,
Geom::Coord equal_dist,
Geom::Coord equal_dist2,
SnapSourceType const &source,
long source_num,
SnapTargetType const &target,
Geom::Coord const &d,
Geom::Coord const &t,
bool const &a,
bool const &constrained_snap,
bool const &fully_constrained) :
114 _equal_distance(equal_dist),
115 _equal_distance2(equal_dist2),
116 _distribution_bboxes(
std::move(bboxes)),
117 _distribution_bboxes2(
std::move(bboxes2)),
118 _source_bbox(source_bbox),
121 _source_num(source_num),
123 _at_intersection (false),
124 _constrained_snap (constrained_snap),
125 _fully_constrained (fully_constrained),
127 _tolerance(
std::max(t,1.0)),
129 _second_distance (
Geom::infinity()),
130 _second_tolerance (1),
131 _second_always_snap (false),
133 _pointer_distance (
Geom::infinity())
138 _point (p.getPoint()),
139 _equal_distance(
Geom::infinity()),
141 _source (p.getSourceType()),
142 _source_num (p.getSourceNum()),
144 _at_intersection (false),
145 _constrained_snap (constrained_snap),
146 _fully_constrained (fully_constrained),
148 _tolerance(
std::max(t,1.0)),
150 _second_distance (
Geom::infinity()),
151 _second_tolerance (1),
152 _second_always_snap (false),
153 _target_bbox (p.getTargetBBox()),
154 _pointer_distance (
Geom::infinity())
158Inkscape::SnappedPoint::SnappedPoint(
Geom::Point const &p,
SnapSourceType const &source,
long source_num,
SnapTargetType const &target,
Geom::Coord const &d,
Geom::Coord const &t,
bool const &a,
bool const &at_intersection,
bool const &constrained_snap,
bool const &fully_constrained,
Geom::Coord const &d2,
Geom::Coord const &t2,
bool const &a2) :
160 _equal_distance(
Geom::infinity()),
163 _source_num(source_num),
165 _at_intersection(at_intersection),
166 _constrained_snap(constrained_snap),
167 _fully_constrained(fully_constrained),
169 _tolerance(
std::max(t,1.0)),
171 _second_distance(d2),
172 _second_tolerance(
std::max(t2,1.0)),
173 _second_always_snap(a2),
176 _target_bbox (
Geom::OptRect()),
177 _pointer_distance (
Geom::infinity())
183 _equal_distance(
Geom::infinity()),
188 _at_intersection (false),
189 _constrained_snap (false),
190 _fully_constrained (false),
191 _distance (
Geom::infinity()),
193 _always_snap (false),
194 _second_distance (
Geom::infinity()),
195 _second_tolerance (1),
196 _second_always_snap (false),
197 _target_bbox (
Geom::OptRect()),
198 _pointer_distance (
Geom::infinity())
204 _equal_distance(
Geom::infinity()),
209 _at_intersection (false),
210 _constrained_snap (false),
211 _fully_constrained (false),
212 _distance (
Geom::infinity()),
214 _always_snap (false),
215 _second_distance (
Geom::infinity()),
216 _second_tolerance (1),
217 _second_always_snap (false),
218 _target_bbox (
Geom::OptRect()),
219 _pointer_distance (
Geom::infinity())
244 bool success =
false;
245 bool aligned_success =
false;
249 for (std::list<Inkscape::SnappedPoint>::const_iterator i = list.begin(); i != list.end(); ++i) {
251 if (i == list.begin()) {
253 success = !alignment;
255 aligned_success = alignment;
256 }
else if (alignment) {
257 if (!aligned_success || (*i).getSnapDistance() <= aligned.
getSnapDistance()) {
261 aligned_success =
true;
265 aligned_success =
true;
268 }
else if (!success || (*i).getSnapDistance() <
result.getSnapDistance()){
275 if (!success && aligned_success)
279 if (success && aligned_success) {
281 auto type =
result.getTarget();
304 if (!align_intersection) {
333 g_warning(
"getClosestSP(): unknown distribution snap target %i",
result.getTarget());
341 return success ? success : aligned_success;
347 if (getSnapped() && !other_one.
getSnapped()) {
351 if (!getSnapped() && other_one.
getSnapped()) {
356 double dist_this = getSnapDistance();
363 Geom::Coord const dist_pointer_this = getPointerDistance();
368 if (prefs->
getBool(
"/options/snapclosestonly/value",
false)) {
372 if (!(
w == 1 && dist_pointer_this == dist_pointer_other)) {
381 double const norm_p = std::min(dist_pointer_this, dist_pointer_other) + 1;
383 double const norm_t_other = std::min(50.0, other_one.
getTolerance());
384 double const norm_t_this = std::min(50.0, getTolerance());
385 dist_other =
w * dist_pointer_other / norm_p + (1-
w) * dist_other / norm_t_other;
386 dist_this =
w * dist_pointer_this / norm_p + (1-
w) * dist_this / norm_t_this;
401 bool c1 = dist_other < dist_this;
409 bool c3n = !other_one.
getFullyConstrained() && (getFullyConstrained() && !getConstrainedSnap());
418 bool c5a = (dist_other == dist_this);
423 bool other_is_better = (c1 || c2 || c3 || c4 || (c5a && (c5b || c5c))) && !c2n && (!c3n || c2) && !c4n;
431 return other_is_better;
436 std::vector<Inkscape::SnapTargetType> snaptargets_on_path{
448 return std::find(snaptargets_on_path.begin(), snaptargets_on_path.end(), _target) != snaptargets_on_path.end();
pair< double, double > Point
Axis-aligned rectangle that can be empty.
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
Axis aligned, non-empty rectangle.
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
double getDoubleLimited(Glib::ustring const &pref_path, double def=0.0, double min=DBL_MIN, double max=DBL_MAX, Glib::ustring const &unit="")
Retrieve a limited floating point value.
Class to store data for points which are snap candidates, either as a source or as a target.
Class describing the result of an attempt to snap.
std::optional< Geom::Point > getAlignmentTarget() const
bool getConstrainedSnap() const
void getPointIfSnapped(Geom::Point &p) const
SnapTargetType getTarget() const
std::optional< Geom::Point > getAlignmentTarget2() const
Geom::Point getPoint() const
Geom::Coord getTolerance() const
bool getAlwaysSnap() const
Geom::Coord getPointerDistance() const
Geom::Coord getSnapDistance() const
bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const
bool getAtIntersection() const
SnapTargetType getAlignmentTargetType() const
bool getFullyConstrained() const
Geom::Coord getSecondSnapDistance() const
Geom::Coord getDistanceToAlignTarget() const
constexpr Coord infinity()
Get a value representing infinity.
double Coord
Floating point type used to store coordinates.
Various utility functions.
SBasis L2(D2< SBasis > const &a, unsigned k)
SnapSourceType
enumerations of snap source types and snap target types.
@ SNAPTARGET_PATH_GUIDE_INTERSECTION
@ SNAPTARGET_DISTRIBUTION_XY
@ SNAPTARGET_DISTRIBUTION_LEFT
@ SNAPTARGET_DISTRIBUTION_DOWN
@ SNAPTARGET_LINE_MIDPOINT
@ SNAPTARGET_ALIGNMENT_CATEGORY
@ SNAPTARGET_ALIGNMENT_INTERSECTION
@ SNAPTARGET_DISTRIBUTION_UP
@ SNAPTARGET_ELLIPSE_QUADRANT_POINT
@ SNAPTARGET_DISTRIBUTION_CATEGORY
@ SNAPTARGET_DISTRIBUTION_X
@ SNAPTARGET_ALIGNMENT_BBOX_CORNER
@ SNAPTARGET_DISTRIBUTION_Y
@ SNAPTARGET_PATH_TANGENTIAL
@ SNAPTARGET_PATH_PERPENDICULAR
@ SNAPTARGET_PATH_INTERSECTION
@ SNAPTARGET_DISTRIBUTION_RIGHT
Singleton class to access the preferences file in a convenient way.
bool getClosestSP(std::list< Inkscape::SnappedPoint > const &list, Inkscape::SnappedPoint &result)