diff options
| author | Ted Gould <ted@gould.cx> | 2008-10-11 15:16:23 +0000 |
|---|---|---|
| committer | Ted Gould <ted@canonical.com> | 2008-10-11 15:16:23 +0000 |
| commit | 2f5eb047d9e05be5e68549ef6b75070d2faa7d2f (patch) | |
| tree | ca2e94164b6d7aaebfc17196ca46bfc825a7665a /src/sp-item-transform.cpp | |
| parent | Merge from trunk. (diff) | |
| download | inkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.tar.gz inkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.zip | |
Merging from trunk
(bzr r6884)
Diffstat (limited to 'src/sp-item-transform.cpp')
| -rw-r--r-- | src/sp-item-transform.cpp | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/src/sp-item-transform.cpp b/src/sp-item-transform.cpp index 0d9118ac9..3b0b1e054 100644 --- a/src/sp-item-transform.cpp +++ b/src/sp-item-transform.cpp @@ -7,24 +7,16 @@ * Lauris Kaplinski <lauris@kaplinski.com> * Frank Felfe <innerspace@iname.com> * bulia byak <buliabyak@gmail.com> + * Johan Engelen <goejendaagh@zonnet.nl> * - * Copyright (C) 1999-2005 authors + * Copyright (C) 1999-2008 authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <libnr/nr-matrix-ops.h> -#include "libnr/nr-matrix-rotate-ops.h" -#include "libnr/nr-matrix-scale-ops.h" -#include "libnr/nr-matrix-translate-ops.h" +#include <2geom/transforms.h> #include "sp-item.h" -static NR::translate inverse(NR::translate const m) -{ - /* TODO: Move this to nr-matrix-fns.h or the like. */ - return NR::translate(-m[0], -m[1]); -} - void sp_item_rotate_rel(SPItem *item, Geom::Rotate const &rotation) { @@ -46,7 +38,7 @@ sp_item_rotate_rel(SPItem *item, Geom::Rotate const &rotation) void sp_item_scale_rel (SPItem *item, Geom::Scale const &scale) { - boost::optional<NR::Rect> bbox = sp_item_bbox_desktop(item); + boost::optional<Geom::Rect> bbox = sp_item_bbox_desktop(item); if (bbox) { Geom::Translate const s(bbox->midpoint()); // use getCenter? sp_item_set_i2d_affine(item, sp_item_i2d_affine(item) * s.inverse() * scale * s); @@ -86,29 +78,29 @@ preference value passed to it. Has to solve a quadratic equation to make sure the goal is met exactly and the stroke scaling is obeyed. */ -NR::Matrix -get_scale_transform_with_stroke (NR::Rect &bbox_param, gdouble strokewidth, bool transform_stroke, gdouble x0, gdouble y0, gdouble x1, gdouble y1) +Geom::Matrix +get_scale_transform_with_stroke (Geom::Rect const &bbox_param, gdouble strokewidth, bool transform_stroke, gdouble x0, gdouble y0, gdouble x1, gdouble y1) { - NR::Rect bbox (bbox_param); + Geom::Rect bbox (bbox_param); - NR::Matrix p2o = NR::Matrix (NR::translate (-bbox.min())); - NR::Matrix o2n = NR::Matrix (NR::translate (x0, y0)); + Geom::Matrix p2o = Geom::Translate (-bbox.min()); + Geom::Matrix o2n = Geom::Translate (x0, y0); - NR::Matrix scale = NR::Matrix (NR::scale (1, 1)); // scale component - NR::Matrix unbudge = NR::Matrix (NR::translate (0, 0)); // move component to compensate for the drift caused by stroke width change + Geom::Matrix scale = Geom::Scale (1, 1); // scale component + Geom::Matrix unbudge = Geom::Translate (0, 0); // move component to compensate for the drift caused by stroke width change - gdouble w0 = bbox.extent(NR::X); // will return a value >= 0, as required further down the road - gdouble h0 = bbox.extent(NR::Y); + gdouble w0 = bbox[Geom::X].extent(); // will return a value >= 0, as required further down the road + gdouble h0 = bbox[Geom::Y].extent(); gdouble w1 = x1 - x0; // can have any sign gdouble h1 = y1 - y0; gdouble r0 = strokewidth; if (bbox.isEmpty()) { - NR::Matrix move = NR::Matrix(NR::translate(x0 - bbox.min()[NR::X], y0 - bbox.min()[NR::Y])); + Geom::Matrix move = Geom::Translate(x0 - bbox.min()[Geom::X], y0 - bbox.min()[Geom::Y]); return (move); // cannot scale from empty boxes at all, so only translate } - NR::Matrix direct = NR::Matrix (NR::scale(w1 / w0, h1 / h0)); + Geom::Matrix direct = Geom::Scale(w1 / w0, h1 / h0); if (fabs(w0 - r0) < 1e-6 || fabs(h0 - r0) < 1e-6 || (!transform_stroke && (fabs(w1 - r0) < 1e-6 || fabs(h1 - r0) < 1e-6))) { return (p2o * direct * o2n); // can't solve the equation: one of the dimensions is equal to stroke width, so return the straightforward scaler @@ -127,7 +119,7 @@ get_scale_transform_with_stroke (NR::Rect &bbox_param, gdouble strokewidth, bool gdouble ratio_x = (w1 - r0) / (w0 - r0); gdouble ratio_y = (h1 - r0) / (h0 - r0); - NR::Matrix direct_constant_r = NR::Matrix (NR::scale(flip_x * ratio_x, flip_y * ratio_y)); + Geom::Matrix direct_constant_r = Geom::Scale(flip_x * ratio_x, flip_y * ratio_y); if (transform_stroke && r0 != 0 && r0 != NR_HUGE) { // there's stroke, and we need to scale it // These coefficients are obtained from the assumption that scaling applies to the @@ -148,8 +140,8 @@ get_scale_transform_with_stroke (NR::Rect &bbox_param, gdouble strokewidth, bool // Here we also need the absolute values of w0, w1, h0, h1, and r1 gdouble scale_x = (w1 - r1)/(w0 - r0); gdouble scale_y = (h1 - r1)/(h0 - r0); - scale *= NR::scale(flip_x * scale_x, flip_y * scale_y); - unbudge *= NR::translate (-flip_x * 0.5 * (r0 * scale_x - r1), -flip_y * 0.5 * (r0 * scale_y - r1)); + scale *= Geom::Scale(flip_x * scale_x, flip_y * scale_y); + unbudge *= Geom::Translate (-flip_x * 0.5 * (r0 * scale_x - r1), -flip_y * 0.5 * (r0 * scale_y - r1)); } else { scale *= direct; } @@ -158,15 +150,15 @@ get_scale_transform_with_stroke (NR::Rect &bbox_param, gdouble strokewidth, bool scale *= direct; } else {// nonscaling strokewidth scale *= direct_constant_r; - unbudge *= NR::translate (flip_x * 0.5 * r0 * (1 - ratio_x), flip_y * 0.5 * r0 * (1 - ratio_y)); + unbudge *= Geom::Translate (flip_x * 0.5 * r0 * (1 - ratio_x), flip_y * 0.5 * r0 * (1 - ratio_y)); } } return (p2o * scale * unbudge * o2n); } -NR::Rect -get_visual_bbox (boost::optional<NR::Rect> const &initial_geom_bbox, NR::Matrix const &abs_affine, gdouble const initial_strokewidth, bool const transform_stroke) +Geom::Rect +get_visual_bbox (boost::optional<Geom::Rect> const &initial_geom_bbox, Geom::Matrix const &abs_affine, gdouble const initial_strokewidth, bool const transform_stroke) { g_assert(initial_geom_bbox); @@ -174,23 +166,23 @@ get_visual_bbox (boost::optional<NR::Rect> const &initial_geom_bbox, NR::Matrix // Find the new geometric bounding box; Do this by transforming each corner of // the initial geometric bounding box individually and fitting a new boundingbox // around the transformerd corners - NR::Point const p0 = initial_geom_bbox->corner(0) * abs_affine; - NR::Rect new_geom_bbox = NR::Rect(p0, p0); + Geom::Point const p0 = Geom::Point(initial_geom_bbox->corner(0)) * abs_affine; + Geom::Rect new_geom_bbox(p0, p0); for (unsigned i = 1 ; i < 4 ; i++) { - new_geom_bbox.expandTo(initial_geom_bbox->corner(i) * abs_affine); + new_geom_bbox.expandTo(Geom::Point(initial_geom_bbox->corner(i)) * abs_affine); } - NR::Rect new_visual_bbox = new_geom_bbox; + Geom::Rect new_visual_bbox = new_geom_bbox; if (initial_strokewidth > 0 && initial_strokewidth < NR_HUGE) { if (transform_stroke) { // scale stroke by: sqrt (((w1-r0)/(w0-r0))*((h1-r0)/(h0-r0))) (for visual bboxes, see get_scale_transform_with_stroke) // equals scaling by: sqrt ((w1/w0)*(h1/h0)) for geometrical bboxes // equals scaling by: sqrt (area1/area0) for geometrical bboxes gdouble const new_strokewidth = initial_strokewidth * sqrt (new_geom_bbox.area() / initial_geom_bbox->area()); - new_visual_bbox.growBy(0.5 * new_strokewidth); + new_visual_bbox.expandBy(0.5 * new_strokewidth); } else { // Do not transform the stroke - new_visual_bbox.growBy(0.5 * initial_strokewidth); + new_visual_bbox.expandBy(0.5 * initial_strokewidth); } } |
