Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
snap-candidate.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_SNAP_CANDIDATE_H
3#define SEEN_SNAP_CANDIDATE_H
4
9/*
10 * Authors:
11 * Diederik van Lierop <mail@diedenrezi.nl>
12 *
13 * Copyright (C) 2010 - 2012 Authors
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#include <2geom/point.h>
19#include <2geom/rect.h>
20#include <2geom/pathvector.h>
21#include <cstdio>
22#include <utility>
23
24#include "snap-enums.h"
25
26class SPItem; // forward declaration
27
28namespace Inkscape {
29
32{
33public:
34 SnapCandidatePoint() = default;; // only needed / used for resizing() of a vector in seltrans.cpp; do not use uninitialized instances!
35
36 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::OptRect bbox)
37 : _point(point),
38 _source_type(source),
39 _target_type(target),
40 _source_num(source_num),
41 _target_bbox(std::move(bbox)),
42 _dist(),
43 _alignment(false)
44 {
45 };
46
48 : _point(point),
49 _source_type(source),
50 _target_type(target),
51 _target_bbox(Geom::OptRect()),
52 _dist(),
53 _alignment(true)
54 {
55 _source_num = -1;
56 }
57
59 : _point(point),
60 _source_type(source),
62 _source_num(-1),
63 _target_bbox(Geom::OptRect()),
64 _dist(),
65 _alignment(true)
66 {
67 };
68
69 inline Geom::Point const & getPoint() const {return _point;}
73
74 inline long getSourceNum() const {return _source_num;}
76
77 void setDistance(Geom::Coord dist) {_dist = dist;}
79
80 void addOrigin(Geom::Point pt) { _origins_and_vectors.emplace_back(pt, false); }
81 void addVector(Geom::Point v) { _origins_and_vectors.emplace_back(v, true); }
82 std::vector<std::pair<Geom::Point, bool> > const & getOriginsAndVectors() const {return _origins_and_vectors;}
83
84 bool operator <(const SnapCandidatePoint &other) const { return _dist < other._dist; } // Needed for sorting the SnapCandidatePoints
85 inline Geom::OptRect const getTargetBBox() const {return _target_bbox;}
86
87 inline bool considerForAlignment() const {return _alignment;}
88
89 inline void setPoint(const Geom::Point &pt) {_point = pt;}
90 inline void movePoint(const Geom::Point &pt) {_point += pt;}
91
92private:
93 // Coordinates of the point
95 // For perpendicular or tangential snapping of a ROTATING line we need to know its (stationary) starting point.
96 // In case of editing with the node tool, a node can be connected to two lines simultaneously, in which case we
97 // need to consider two starting points; Therefore a vector containing multiple starting points is used here. However,
98 // for perpendicular or tangential snapping of a TRANSLATING line we need to know its direction vector instead. This
99 // vector will be stored in the same way as the starting point is, i.e. as a Geom::Point. A boolean is paired to this
100 // point, which is true for vectors but false for origins
101 std::vector<std::pair<Geom::Point, bool> > _origins_and_vectors;
102
103 // If this SnapCandidatePoint is a snap source, then _source_type must be defined. If it
104 // is a snap target, then _target_type must be defined. If it's yet unknown whether it will
105 // be a source or target, then both may be defined
108
109 //Sequence number of the source point within the set of points that is to be snapped.
110 // - Starts counting at zero, but only if there might be more points following (e.g. in the selector tool)
111 // - Minus one (-1) if we're sure that we have only a single point
113
114 // If this is a target and it belongs to a bounding box, e.g. when the target type is
115 // SNAPTARGET_BBOX_EDGE_MIDPOINT, then _target_bbox stores the relevant bounding box
117
118 // For finding the snap candidate closest to the mouse pointer
120
121 // Consider this point for alignment snapping
123};
124
126{
127public:
130 ~SnapCandidateItem() = default;;
131
132 SPItem* item; // An item that is to be considered for snapping to
133 bool clip_or_mask; // If true, then item refers to a clipping path or a mask
134
135 /* To find out the absolute position of a clipping path or mask, we not only need to know
136 * the transformation of the clipping path or mask itself, but also the transformation of
137 * the object to which the clip or mask is being applied; that transformation is stored here
138 */
140}
141;
142
144{
145
146public:
147 SnapCandidatePath(Geom::PathVector path, SnapTargetType target, Geom::OptRect bbox, bool edited = false)
148 : path_vector(std::move(path)), target_type(target), target_bbox(std::move(bbox)), currently_being_edited(edited) {};
149
153 bool currently_being_edited; // true for the path that's currently being edited in the node tool (if any)
154
155};
156} // end of namespace Inkscape
157#endif /* !SEEN_SNAP_CANDIDATE_H */
Cartesian point / 2D vector and related operations.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
SnapCandidateItem(SPItem *item, bool clip_or_mask, Geom::Affine additional_affine)
SnapCandidatePath(Geom::PathVector path, SnapTargetType target, Geom::OptRect bbox, bool edited=false)
Class to store data for points which are snap candidates, either as a source or as a target.
Inkscape::SnapTargetType _target_type
Geom::OptRect const getTargetBBox() const
std::vector< std::pair< Geom::Point, bool > > const & getOriginsAndVectors() const
Inkscape::SnapSourceType getSourceType() const
Geom::Point const & getPoint() const
Inkscape::SnapSourceType _source_type
Inkscape::SnapTargetType getTargetType() const
SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::OptRect bbox)
void addOrigin(Geom::Point pt)
void addVector(Geom::Point v)
void setPoint(const Geom::Point &pt)
SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, Inkscape::SnapTargetType const target)
SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source)
bool operator<(const SnapCandidatePoint &other) const
void setDistance(Geom::Coord dist)
std::vector< std::pair< Geom::Point, bool > > _origins_and_vectors
void movePoint(const Geom::Point &pt)
Base class for visual SVG elements.
Definition sp-item.h:109
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
Various utility functions.
Definition affine.h:22
Helper class to stream background task notifications as a series of messages.
SnapSourceType
enumerations of snap source types and snap target types.
Definition snap-enums.h:18
@ SNAPSOURCE_OTHER_HANDLE
Definition snap-enums.h:56
@ SNAPSOURCE_NODE_HANDLE
Definition snap-enums.h:43
@ SNAPTARGET_UNDEFINED
Definition snap-enums.h:71
STL namespace.
PathVector - a sequence of subpaths.
Axis-aligned rectangle.
int num
Definition scribble.cpp:47