Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::DistributionSnapper Class Reference

Snapping equidistant objects. More...

#include <distribution-snapper.h>

Inheritance diagram for Inkscape::DistributionSnapper:
Inkscape::Snapper

Public Member Functions

 DistributionSnapper (SnapManager *sm, Geom::Coord const d)
 
 ~DistributionSnapper () override
 
bool ThisSnapperMightSnap () const override
 
Geom::Coord getSnapperTolerance () const override
 
bool getSnapperAlwaysSnap (SnapSourceType const &source) const override
 
void freeSnap (IntermSnapResults &isr, Inkscape::SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, std::vector< SPObject const * > const *it, std::vector< SnapCandidatePoint > *unselected_nodes) const override
 
void constrainedSnap (IntermSnapResults &isr, Inkscape::SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, SnapConstraint const &c, std::vector< SPObject const * > const *it, std::vector< SnapCandidatePoint > *unselected_nodes) const override
 
- Public Member Functions inherited from Inkscape::Snapper
 Snapper (SnapManager *sm, ::Geom::Coord const t)
 Construct new Snapper for named view.
 
virtual ~Snapper ()=default
 
void setEnabled (bool s)
 
void setSnapVisibleOnly (bool s)
 
bool getEnabled () const
 
bool getSnapVisibleOnly () const
 

Private Types

enum class  Direction { RIGHT , LEFT , UP , DOWN }
 

Private Member Functions

void _collectBBoxes (Geom::OptRect const &bbox_to_snap, bool const &first_point) const
 Collects and caches bounding boxes to the left, right, up, and down of the selected object.
 
void _snapEquidistantPoints (IntermSnapResults &isr, SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, std::vector< SnapCandidatePoint > *unselected_nodes, SnapConstraint const &c=SnapConstraint(), Geom::Point const &p_proj_on_constraint=Geom::Point()) const
 Finds and snaps to points that is equidistant from surrounding bboxes.
 
void _correctSelectionBBox (Geom::Point &target, Geom::Point const &p, Geom::Rect const &bbox_to_snap) const
 When the selection has more than one objects in it, the bounding box of the object that the selection is grabbed from (closest to the pointer) is snapped to the center of the overall bounding box of the selection.
 
bool _findSidewaysSnaps (Geom::Rect const &source_bbox, std::vector< Geom::Rect >::iterator it, std::vector< Geom::Rect >::iterator end, std::vector< Geom::Rect > &vec, Geom::Coord &dist, Geom::Coord tol, std::function< Geom::Coord(Geom::Rect const &, Geom::Rect const &)> const &distance_func, int level=0) const
 Finds and stores the bounding boxes that are at equal distance from each other.
 
void _addBBoxForIntersectingBoxes (std::vector< Geom::Rect > *vec, Direction dir) const
 This functions adds overlapping bounding boxes to the list of bounding boxes.
 

Static Private Member Functions

static Geom::Coord distRight (Geom::Rect const &a, Geom::Rect const &b)
 
static Geom::Coord distLeft (Geom::Rect const &a, Geom::Rect const &b)
 
static Geom::Coord distUp (Geom::Rect const &a, Geom::Rect const &b)
 
static Geom::Coord distDown (Geom::Rect const &a, Geom::Rect const &b)
 

Private Attributes

std::unique_ptr< std::vector< Geom::Rect > > _bboxes_left
 
std::unique_ptr< std::vector< Geom::Rect > > _bboxes_right
 
std::unique_ptr< std::vector< Geom::Rect > > _bboxes_down
 
std::unique_ptr< std::vector< Geom::Rect > > _bboxes_up
 

Additional Inherited Members

- Protected Attributes inherited from Inkscape::Snapper
SnapManager_snapmanager
 
bool _snap_enabled
 true if this snapper is enabled, otherwise false
 
bool _snap_visible_only
 

Detailed Description

Snapping equidistant objects.

Definition at line 33 of file distribution-snapper.h.

Member Enumeration Documentation

◆ Direction

enum class Inkscape::DistributionSnapper::Direction
strongprivate
Enumerator
RIGHT 
LEFT 
UP 
DOWN 

Definition at line 124 of file distribution-snapper.h.

Constructor & Destructor Documentation

◆ DistributionSnapper()

Inkscape::DistributionSnapper::DistributionSnapper ( SnapManager sm,
Geom::Coord const  d 
)

Definition at line 64 of file distribution-snapper.cpp.

References _bboxes_down, _bboxes_left, _bboxes_right, and _bboxes_up.

◆ ~DistributionSnapper()

Inkscape::DistributionSnapper::~DistributionSnapper ( )
override

Definition at line 73 of file distribution-snapper.cpp.

Member Function Documentation

◆ _addBBoxForIntersectingBoxes()

void Inkscape::DistributionSnapper::_addBBoxForIntersectingBoxes ( std::vector< Geom::Rect > *  vec,
Direction  dir 
) const
private

This functions adds overlapping bounding boxes to the list of bounding boxes.

The new bounding boxes are added such that the union bounding box is placed before its constituents. This extra step is needed so that the overall union of any overlapping bounding boxes is also considered during distribution snapping.

Definition at line 267 of file distribution-snapper.cpp.

References num, and Geom::GenericRect< C >::unionWith().

◆ _collectBBoxes()

void Inkscape::DistributionSnapper::_collectBBoxes ( Geom::OptRect const &  bbox_to_snap,
bool const &  first_point 
) const
private

Collects and caches bounding boxes to the left, right, up, and down of the selected object.

Parameters
boundingbox of the selected object
isthe point first point in the selection?

Definition at line 200 of file distribution-snapper.cpp.

References SPItem::desktopBounds(), Geom::GenericRect< C >::expandBy(), SPItem::GEOMETRIC_BBOX, Inkscape::Preferences::get(), Inkscape::Preferences::getBool(), Geom::GenericOptRect< C >::intersects(), Geom::GenericRect< C >::intersects(), sortBoxesDown(), sortBoxesLeft(), sortBoxesRight(), sortBoxesUp(), and SPItem::VISUAL_BBOX.

◆ _correctSelectionBBox()

void Inkscape::DistributionSnapper::_correctSelectionBBox ( Geom::Point target,
Geom::Point const &  p,
Geom::Rect const &  bbox_to_snap 
) const
private

When the selection has more than one objects in it, the bounding box of the object that the selection is grabbed from (closest to the pointer) is snapped to the center of the overall bounding box of the selection.

This function corrects the target point to be a point where the bounding box of that particular object must be snapped to.

Parameters
snaptarget point that need to be snapped to
sourcepoint to snap (this bbox midpoint of the object closest to the mouse pointer)
boundingbox of the active selection to snap

Definition at line 549 of file distribution-snapper.cpp.

References Geom::GenericRect< C >::midpoint().

◆ _findSidewaysSnaps()

bool Inkscape::DistributionSnapper::_findSidewaysSnaps ( Geom::Rect const &  source_bbox,
std::vector< Geom::Rect >::iterator  it,
std::vector< Geom::Rect >::iterator  end,
std::vector< Geom::Rect > &  vec,
Geom::Coord dist,
Geom::Coord  tol,
std::function< Geom::Coord(Geom::Rect const &, Geom::Rect const &)> const &  distance_func,
int  level = 0 
) const
private

Finds and stores the bounding boxes that are at equal distance from each other.

Parameters
thedistance between the object that needs to be snapped and the first object in the sideways vectors.
firstiterator of the sideways vector
endof the sideways vector
vectorwhere the snapped bboxes will be stored
equaldistance between consecutive vectors
snappedtolerance
afunction pointer to the distance function
levelof recursion - do not pass this while calling the function

Definition at line 101 of file distribution-snapper.cpp.

References compare_double(), end, and result.

◆ _snapEquidistantPoints()

void Inkscape::DistributionSnapper::_snapEquidistantPoints ( IntermSnapResults isr,
SnapCandidatePoint const &  p,
Geom::OptRect const &  bbox_to_snap,
std::vector< SnapCandidatePoint > *  unselected_nodes,
SnapConstraint const &  c = SnapConstraint(),
Geom::Point const &  p_proj_on_constraint = Geom::Point() 
) const
private

◆ constrainedSnap()

void Inkscape::DistributionSnapper::constrainedSnap ( IntermSnapResults isr,
Inkscape::SnapCandidatePoint const &  p,
Geom::OptRect const &  bbox_to_snap,
SnapConstraint const &  c,
std::vector< SPObject const * > const *  it,
std::vector< SnapCandidatePoint > *  unselected_nodes 
) const
overridevirtual

◆ distDown()

Geom::Coord Inkscape::DistributionSnapper::distDown ( Geom::Rect const &  a,
Geom::Rect const &  b 
)
staticprivate

◆ distLeft()

Geom::Coord Inkscape::DistributionSnapper::distLeft ( Geom::Rect const &  a,
Geom::Rect const &  b 
)
staticprivate

◆ distRight()

Geom::Coord Inkscape::DistributionSnapper::distRight ( Geom::Rect const &  a,
Geom::Rect const &  b 
)
staticprivate

◆ distUp()

Geom::Coord Inkscape::DistributionSnapper::distUp ( Geom::Rect const &  a,
Geom::Rect const &  b 
)
staticprivate

◆ freeSnap()

◆ getSnapperAlwaysSnap()

bool Inkscape::DistributionSnapper::getSnapperAlwaysSnap ( SnapSourceType const &  source) const
overridevirtual

◆ getSnapperTolerance()

Geom::Coord Inkscape::DistributionSnapper::getSnapperTolerance ( ) const
overridevirtual
Returns
Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels.

Implements Inkscape::Snapper.

Definition at line 621 of file distribution-snapper.cpp.

References SPDesktop::current_zoom().

◆ ThisSnapperMightSnap()

bool Inkscape::DistributionSnapper::ThisSnapperMightSnap ( ) const
overridevirtual
Returns
true if this Snapper will snap at least one kind of point.

Reimplemented from Inkscape::Snapper.

Definition at line 611 of file distribution-snapper.cpp.

Member Data Documentation

◆ _bboxes_down

std::unique_ptr<std::vector<Geom::Rect> > Inkscape::DistributionSnapper::_bboxes_down
private

Definition at line 68 of file distribution-snapper.h.

Referenced by DistributionSnapper().

◆ _bboxes_left

std::unique_ptr<std::vector<Geom::Rect> > Inkscape::DistributionSnapper::_bboxes_left
private

Definition at line 66 of file distribution-snapper.h.

Referenced by DistributionSnapper().

◆ _bboxes_right

std::unique_ptr<std::vector<Geom::Rect> > Inkscape::DistributionSnapper::_bboxes_right
private

Definition at line 67 of file distribution-snapper.h.

Referenced by DistributionSnapper().

◆ _bboxes_up

std::unique_ptr<std::vector<Geom::Rect> > Inkscape::DistributionSnapper::_bboxes_up
private

Definition at line 69 of file distribution-snapper.h.

Referenced by DistributionSnapper().


The documentation for this class was generated from the following files: