diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 33f140de24417947879a3e595e78ec74aa55be05..f88d7b9e04b728f2047e9f031c752c98078f7275 100644 (file)
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
#include "filter-chemistry.h"
#include "sp-guide.h"
-#include "libnr/nr-matrix-div.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-matrix-scale-ops.h"
#include "libnr/nr-matrix-translate-ops.h"
*/
void
SPItem::setCenter(NR::Point object_centre) {
- NR::Maybe<NR::Rect> bbox = getBounds(from_2geom(sp_item_i2d_affine(this)));
+ boost::optional<NR::Rect> bbox = getBounds(sp_item_i2d_affine(this));
if (bbox) {
transform_center_x = object_centre[NR::X] - bbox->midpoint()[NR::X];
if (fabs(transform_center_x) < 1e-5) // rounding error
}
NR::Point SPItem::getCenter() const {
- NR::Maybe<NR::Rect> bbox = getBounds(from_2geom(sp_item_i2d_affine(this)));
+ boost::optional<NR::Rect> bbox = getBounds(sp_item_i2d_affine(this));
if (bbox) {
return bbox->midpoint() + NR::Point (this->transform_center_x, this->transform_center_y);
} else {
if (item->style->filter.set && item->display) {
NRRect item_bbox;
sp_item_invoke_bbox(item, &item_bbox, NR::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
- NR::Maybe<NR::Rect> i_bbox = item_bbox;
+ boost::optional<NR::Rect> i_bbox = item_bbox;
SPItemView *itemview = item->display;
do {
@@ -694,31 +693,22 @@ sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape
return repr;
}
-NR::Maybe<NR::Rect> SPItem::getBounds(NR::Matrix const &transform,
+boost::optional<NR::Rect> SPItem::getBounds(NR::Matrix const &transform,
SPItem::BBoxType type,
unsigned int /*dkey*/) const
{
- NR::Maybe<NR::Rect> r = NR::Nothing();
+ boost::optional<NR::Rect> r;
sp_item_invoke_bbox_full(this, &r, transform, type, TRUE);
return r;
}
-NR::Maybe<Geom::Rect>
-SPItem::getBounds(Geom::Matrix const &transform, SPItem::BBoxType type, unsigned int /*dkey*/)
-const
-{
- NR::Maybe<NR::Rect> r = NR::Nothing();
- sp_item_invoke_bbox_full(this, &r, from_2geom(transform), type, TRUE);
- return NR::Maybe<Geom::Rect>(to_2geom(*r));
-}
-
void
-sp_item_invoke_bbox(SPItem const *item, NR::Maybe<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
+sp_item_invoke_bbox(SPItem const *item, boost::optional<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
sp_item_invoke_bbox_full(item, bbox, transform, type, clear);
}
-// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe<NR::Rect>
+// DEPRECATED to phase out the use of NRRect in favor of boost::optional<NR::Rect>
void
sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
@@ -730,14 +720,14 @@ sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transfor
* transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
* clones), in turn, call this function in their bbox methods. */
void
-sp_item_invoke_bbox_full(SPItem const *item, NR::Maybe<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear)
+sp_item_invoke_bbox_full(SPItem const *item, boost::optional<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear)
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
g_assert(bbox != NULL);
if (clear) {
- *bbox = NR::Nothing();
+ *bbox = boost::optional<NR::Rect>();
}
// TODO: replace NRRect by NR::Rect, for all SPItemClasses, and for SP_CLIPPATH
@@ -794,7 +784,7 @@ sp_item_invoke_bbox_full(SPItem const *item, NR::Maybe<NR::Rect> *bbox, NR::Matr
}
// transform the expansions by the item's transform:
- NR::Matrix i2d = from_2geom(sp_item_i2d_affine (item));
+ NR::Matrix i2d(sp_item_i2d_affine (item));
dx0 *= NR::expansionX(i2d);
dx1 *= NR::expansionX(i2d);
dy0 *= NR::expansionY(i2d);
@@ -820,20 +810,20 @@ sp_item_invoke_bbox_full(SPItem const *item, NR::Maybe<NR::Rect> *bbox, NR::Matr
// or it has explicitely been set to be like this (e.g. in sp_shape_bbox)
// When x0 > x1 or y0 > y1, the bbox is considered to be "nothing", although it has not been
- // explicitely defined this way for NRRects (as opposed to NR::Maybe<NR::Rect>)
+ // explicitely defined this way for NRRects (as opposed to boost::optional<NR::Rect>)
// So union bbox with nothing = do nothing, just return
return;
}
- // Do not use temp_bbox.upgrade() here, because it uses a test that returns NR::Nothing
+ // Do not use temp_bbox.upgrade() here, because it uses a test that returns an empty boost::optional<NR::Rect>()
// for any rectangle with zero area. The geometrical bbox of for example a vertical line
- // would therefore be translated into NR::Nothing (see bug https://bugs.launchpad.net/inkscape/+bug/168684)
- NR::Maybe<NR::Rect> temp_bbox_new = NR::Rect(NR::Point(temp_bbox.x0, temp_bbox.y0), NR::Point(temp_bbox.x1, temp_bbox.y1));
+ // would therefore be translated into empty boost::optional<NR::Rect>() (see bug https://bugs.launchpad.net/inkscape/+bug/168684)
+ boost::optional<NR::Rect> temp_bbox_new = NR::Rect(NR::Point(temp_bbox.x0, temp_bbox.y0), NR::Point(temp_bbox.x1, temp_bbox.y1));
*bbox = NR::union_bounds(*bbox, temp_bbox_new);
}
-// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe<NR::Rect>
+// DEPRECATED to phase out the use of NRRect in favor of boost::optional<NR::Rect>
/** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
* unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
* transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
g_assert(SP_IS_ITEM(item));
g_assert(bbox != NULL);
- sp_item_invoke_bbox(item, bbox, from_2geom(sp_item_i2d_affine(item)), TRUE, type);
+ sp_item_invoke_bbox(item, bbox, sp_item_i2d_affine(item), TRUE, type);
}
-NR::Maybe<NR::Rect> sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
+boost::optional<NR::Rect> sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
{
- NR::Maybe<NR::Rect> rect = NR::Nothing();
- sp_item_invoke_bbox(item, &rect, from_2geom(sp_item_i2d_affine(item)), TRUE, type);
+ boost::optional<NR::Rect> rect = boost::optional<NR::Rect>();
+ sp_item_invoke_bbox(item, &rect, sp_item_i2d_affine(item), TRUE, type);
return rect;
}
static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p)
{
- NR::Maybe<NR::Rect> bbox = item->getBounds(from_2geom(sp_item_i2d_affine(item)));
+ boost::optional<NR::Rect> bbox = item->getBounds(sp_item_i2d_affine(item));
/* Just the corners of the bounding box suffices given that we don't yet
support angled guide lines. */
void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p)
{
- g_assert (item != NULL);
+ g_assert (item != NULL);
g_assert (SP_IS_ITEM(item));
+ // Get the snappoints of the item
SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(item);
if (item_class.snappoints) {
item_class.snappoints(item, p);
}
+ // Get the snappoints at the item's center
if (includeItemCenter) {
*p = item->getCenter();
+ }
+
+ // Get the snappoints of clipping paths and mask, if any
+ std::list<SPObject const *> clips_and_masks;
+
+ clips_and_masks.push_back(SP_OBJECT(item->clip_ref->getObject()));
+ clips_and_masks.push_back(SP_OBJECT(item->mask_ref->getObject()));
+
+ for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) {
+ if (*o) {
+ // obj is a group object, the children are the actual clippers
+ for (SPObject *child = (*o)->children ; child ; child = child->next) {
+ if (SP_IS_ITEM(child)) {
+ std::vector<NR::Point> p_clip_or_mask;
+ // Please note the recursive call here!
+ sp_item_snappoints(SP_ITEM(child), includeItemCenter, SnapPointsIter(p_clip_or_mask));
+ // Take into account the transformation of the item being clipped or masked
+ for (std::vector<NR::Point>::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
+ // All snappoints are in desktop coordinates, but the item's transformation is
+ // in document coordinates. Hence the awkward construction below
+ *p = (*p_orig) * from_2geom(matrix_to_desktop (matrix_from_desktop (item->transform, item), item));
+ }
+ }
+ }
+ }
}
}
@@ -1081,7 +1098,7 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
NR_ARENA_ITEM_SET_DATA(ai, item);
NRRect item_bbox;
sp_item_invoke_bbox(item, &item_bbox, NR::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
- NR::Maybe<NR::Rect> i_bbox = item_bbox;
+ boost::optional<NR::Rect> i_bbox = item_bbox;
nr_arena_item_set_item_bbox(ai, i_bbox);
}
@@ -1318,7 +1335,7 @@ sp_item_adjust_livepatheffect (SPItem *item, NR::Matrix const &postmul, bool set
if (lpeobj->lpe) {
Inkscape::LivePathEffect::Effect * effect = lpeobj->lpe;
- effect->transform_multiply(to_2geom(postmul), set);
+ effect->transform_multiply(postmul, set);
}
}
}
/* stop at first non-renderable ancestor */
while ( object != ancestor && SP_IS_ITEM(object) ) {
if (SP_IS_ROOT(object)) {
- ret *= to_2geom(SP_ROOT(object)->c2p);
+ ret *= SP_ROOT(object)->c2p;
}
- ret *= to_2geom(SP_ITEM(object)->transform);
+ ret *= SP_ITEM(object)->transform;
object = SP_OBJECT_PARENT(object);
}
return ret;
i2i_affine(SPObject const *src, SPObject const *dest) {
g_return_val_if_fail(src != NULL && dest != NULL, Geom::identity());
SPObject const *ancestor = src->nearestCommonAncestor(dest);
- return to_2geom( from_2geom(i2anc_affine(src, ancestor)) / from_2geom(i2anc_affine(dest, ancestor)) );
+ return i2anc_affine(src, ancestor) * i2anc_affine(dest, ancestor).inverse();
}
NR::Matrix SPItem::getRelativeTransform(SPObject const *dest) const {
- return from_2geom(i2i_affine(this, dest));
+ return i2i_affine(this, dest);
}
/**
Geom::Matrix ret(Geom::identity());
g_assert(ret.isIdentity());
while ( NULL != SP_OBJECT_PARENT(item) ) {
- ret *= to_2geom(item->transform);
+ ret *= item->transform;
item = SP_ITEM(SP_OBJECT_PARENT(item));
}
g_assert(SP_IS_ROOT(item));
- ret *= to_2geom(item->transform);
+ ret *= item->transform;
return ret;
}
}
Geom::Matrix const i2p( i2dt * dt2p );
- sp_item_set_item_transform(item, from_2geom(i2p));
+ sp_item_set_item_transform(item, i2p);
}
SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
- NR::Maybe<NR::Rect> bbox = sp_item_bbox_desktop(item, bbox_type);
+ boost::optional<NR::Rect> bbox = sp_item_bbox_desktop(item, bbox_type);
if (!bbox) {
g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
return;
NR::Point B(A[NR::X], C[NR::Y]);
NR::Point D(C[NR::X], A[NR::Y]);
- pts.push_back(std::make_pair(A.to_2geom(), B.to_2geom()));
- pts.push_back(std::make_pair(B.to_2geom(), C.to_2geom()));
- pts.push_back(std::make_pair(C.to_2geom(), D.to_2geom()));
- pts.push_back(std::make_pair(D.to_2geom(), A.to_2geom()));
+ pts.push_back(std::make_pair(A, B));
+ pts.push_back(std::make_pair(B, C));
+ pts.push_back(std::make_pair(C, D));
+ pts.push_back(std::make_pair(D, A));
- sp_guide_pt_pairs_to_guides(SP_OBJECT_DOCUMENT(item), pts);
+ sp_guide_pt_pairs_to_guides(dt, pts);
}
/*