From bae59caa568c5dbf0c96d7d4d9e8a7870119d492 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 11 Jan 2009 12:10:19 +0000 Subject: Optionally snap from/to midpoints of the edges of a bounding box (bzr r7108) --- src/object-snapper.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index c03a7c288..35841891f 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -238,11 +238,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapPreferences::PointType // of the item AND the bbox of the clipping path at the same time if (!(*i).clip_or_mask) { Geom::OptRect b = sp_item_bbox_desktop(root_item, bbox_type); - if (b) { - for ( unsigned k = 0 ; k < 4 ; k++ ) { - _points_to_snap_to->push_back(b->corner(k)); - } - } + getBBoxPoints(b, _points_to_snap_to, _snapmanager->snapprefs.getSnapMidpoints()); } } } @@ -736,6 +732,20 @@ void Inkscape::ObjectSnapper::_getBorderNodes(std::vector *points) points->push_back(Geom::Point(w,0)); } +void Inkscape::getBBoxPoints(Geom::OptRect const bbox, std::vector *points, bool const includeMidpoints) +{ + if (bbox) { + // collect the corners of the bounding box + for ( unsigned k = 0 ; k < 4 ; k++ ) { + points->push_back(bbox->corner(k)); + // optionally, collect the midpoints of the bounding box's edges too + if (includeMidpoints) { + points->push_back((bbox->corner(k) + bbox->corner((k+1) % 4))/2); + } + } + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3