From 4847a7f261731ebbd9396d56c12244f721b006d7 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 1 Jul 2013 23:05:45 +0200 Subject: LPE bend path: fix crash on "uskeleton.cuts.back()" because of empty uskeleton. Fixed bugs: - https://launchpad.net/bugs/616198 (bzr r12398) --- src/live_effects/lpe-bendpath.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 49660c91b..eaf9fe4a6 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -94,6 +94,10 @@ LPEBendPath::doEffect_pwd2 (Geom::Piecewise > const & pwd bend_path.changed = false; } + if (uskeleton.empty()) { + return pwd2_in; /// \todo or throw an exception instead? might be better to throw an exception so that the UI can display an error message or smth + } + D2 > patternd2 = make_cuts_independent(pwd2_in); Piecewise x = vertical_pattern.get_value() ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); Piecewise y = vertical_pattern.get_value() ? Piecewise(patternd2[0]) : Piecewise(patternd2[1]); @@ -105,9 +109,9 @@ LPEBendPath::doEffect_pwd2 (Geom::Piecewise > const & pwd x-= bboxHorizontal.min(); y-= bboxVertical.middle(); - double scaling = uskeleton.cuts.back()/bboxHorizontal.extent(); + double scaling = uskeleton.cuts.back()/bboxHorizontal.extent(); - if (scaling != 1.0) { + if (scaling != 1.0) { x*=scaling; } @@ -117,7 +121,6 @@ LPEBendPath::doEffect_pwd2 (Geom::Piecewise > const & pwd if (prop_scale != 1.0) y *= prop_scale; } - Piecewise > output = compose(uskeleton,x) + y*compose(n,x); return output; } -- cgit v1.2.3 From c60177d361dd435e58caa902a395fa21c9415f51 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 18:12:31 -0400 Subject: Removed "helper/unit.*" dependency from "ui/widget/registered-widget.*". (bzr r12380.1.21) --- src/live_effects/parameter/unit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 602d806a0..fffbabb1d 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -74,7 +74,7 @@ UnitParam::param_newWidget() param_effect->getRepr(), param_effect->getSPDoc())); - unit_menu->setUnit(unit); + unit_menu->setUnit(unit->abbr); unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter")); return dynamic_cast (unit_menu); -- cgit v1.2.3 From 5b8a6e510cb69d33bc8834a7586142be800471b5 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 16:31:57 -0400 Subject: Ported "live_effects/parameter/unit.*". (bzr r12380.1.41) --- src/live_effects/lpe-path_length.cpp | 5 +++-- src/live_effects/lpe-ruler.cpp | 8 ++++---- src/live_effects/parameter/unit.cpp | 22 ++++++++++++---------- src/live_effects/parameter/unit.h | 15 +++++++++------ 4 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index d3edcda27..504fb53c0 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -15,6 +15,7 @@ #include "live_effects/lpe-path_length.h" #include "sp-metrics.h" +#include "util/units.h" #include "2geom/sbasis-geometric.h" @@ -52,11 +53,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise > const & p /* convert the measured length to the correct unit ... */ double lengthval = Geom::length(pwd2_in) * scale; - gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit); + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation()); /* ... set it as the canvas text ... */ gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, - display_unit ? (success ? unit.get_abbreviation() : "px") : ""); + display_unit ? unit.get_abbreviation() : ""); info_text.param_setValue(arc_length); g_free(arc_length); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index fefdad95a..788ab593a 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -81,9 +81,9 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const using namespace Geom; double real_mark_length = mark_length; - sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px"); double real_minor_mark_length = minor_mark_length; - sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px"); n_major = real_mark_length * n; n_minor = real_minor_mark_length * n; @@ -133,10 +133,10 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_i std::vector s_cuts; double real_mark_distance = mark_distance; - sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px"); double real_offset = offset; - sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px"); for (double s = real_offset; sabbr.c_str()); } void UnitParam::param_set_default() { - param_set_value(defunit); + param_set_value(*defunit); } void -UnitParam::param_set_value(SPUnit const *val) +UnitParam::param_set_value(Inkscape::Util::Unit const &val) { - unit = val; + unit = new Inkscape::Util::Unit(val); } const gchar * UnitParam::get_abbreviation() const { - return sp_unit_get_abbreviation(unit); + return unit->abbr.c_str(); } Gtk::Widget * diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index ea7a0112a..59a483018 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -10,10 +10,13 @@ */ #include "live_effects/parameter/parameter.h" -#include namespace Inkscape { +namespace Util { + class Unit; +} + namespace LivePathEffect { class UnitParam : public Parameter { @@ -23,22 +26,22 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - SPUnitId default_value = SP_UNIT_PX); + Glib::ustring default_unit = "px"); virtual ~UnitParam(); virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; virtual void param_set_default(); - void param_set_value(SPUnit const *val); + void param_set_value(Inkscape::Util::Unit const &val); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); - operator SPUnit const *() const { return unit; } + operator Inkscape::Util::Unit const *() const { return unit; } private: - SPUnit const *unit; - SPUnit const *defunit; + Inkscape::Util::Unit const *unit; + Inkscape::Util::Unit const *defunit; UnitParam(const UnitParam&); UnitParam& operator=(const UnitParam&); -- cgit v1.2.3 From fdf69629c66f6c1a69d88a00bb6c1311c97b631b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 15:08:31 -0400 Subject: Ported away from and removed "sp-metrics.*". (bzr r12380.1.47) --- src/live_effects/lpe-path_length.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 504fb53c0..4ca380c15 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -14,7 +14,6 @@ #include #include "live_effects/lpe-path_length.h" -#include "sp-metrics.h" #include "util/units.h" #include "2geom/sbasis-geometric.h" -- cgit v1.2.3 From 6ae6c0bea96eef09907091279e0678aa5f83102d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 4 Aug 2013 18:01:18 -0400 Subject: Switched to global UnitTable. (bzr r12380.1.62) --- src/live_effects/parameter/unit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 264b4b9ee..561766920 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -12,6 +12,8 @@ #include "verbs.h" #include "util/units.h" +using Inkscape::Util::unit_table; + namespace Inkscape { namespace LivePathEffect { @@ -22,7 +24,6 @@ UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, Glib::ustring default_unit) : Parameter(label, tip, key, wr, effect) { - Inkscape::Util::UnitTable unit_table; defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit)); unit = defunit; } @@ -34,7 +35,6 @@ UnitParam::~UnitParam() bool UnitParam::param_readSVGValue(const gchar * strvalue) { - Inkscape::Util::UnitTable unit_table; if (strvalue) { param_set_value(unit_table.getUnit(strvalue)); return true; -- cgit v1.2.3 From c0f2f5606f0884e00f426653168b84b23d26ffb3 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 5 Aug 2013 23:07:35 +0200 Subject: code cleanup (cppcheck) (bzr r12469) --- src/live_effects/spiro.cpp | 242 +++++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 120 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index f50399a77..46e53a0da 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -677,163 +677,165 @@ add_mat_line(bandmat *m, double *v, } static double -spiro_iter(spiro_seg *s, bandmat *m, int *perm, double *v, int n) +spiro_iter(spiro_seg *s, bandmat *m, int *perm, double *v, const int n) { int cyclic = s[0].ty != '{' && s[0].ty != 'v'; - int i, j, jj; int nmat = count_vec(s, n); - double norm; int n_invert; - for (i = 0; i < nmat; i++) { - v[i] = 0.; - for (j = 0; j < 11; j++) - m[i].a[j] = 0.; - for (j = 0; j < 5; j++) - m[i].al[j] = 0.; + for (int i = 0; i < nmat; i++) { + v[i] = 0.; + for (int j = 0; j < 11; j++) { + m[i].a[j] = 0.; + } + for (int j = 0; j < 5; j++) { + m[i].al[j] = 0.; + } } - j = 0; - if (s[0].ty == 'o') - jj = nmat - 2; - else if (s[0].ty == 'c') - jj = nmat - 1; - else - jj = 0; - for (i = 0; i < n; i++) { - char ty0 = s[i].ty; - char ty1 = s[i + 1].ty; - int jinc = compute_jinc(ty0, ty1); - double th = s[i].bend_th; - double ends[2][4]; - double derivs[4][2][4]; - int jthl = -1, jk0l = -1, jk1l = -1, jk2l = -1; - int jthr = -1, jk0r = -1, jk1r = -1, jk2r = -1; - - compute_pderivs(&s[i], ends, derivs, jinc); - - /* constraints crossing left */ - if (ty0 == 'o' || ty0 == 'c' || ty0 == '[' || ty0 == ']') { - jthl = jj++; - jj %= nmat; - jk0l = jj++; - } - if (ty0 == 'o') { - jj %= nmat; - jk1l = jj++; - jk2l = jj++; - } + int j = 0; + int jj; + if (s[0].ty == 'o') { + jj = nmat - 2; + } else if (s[0].ty == 'c') { + jj = nmat - 1; + } else { + jj = 0; + } + for (int i = 0; i < n; i++) { + char ty0 = s[i].ty; + char ty1 = s[i + 1].ty; + int jinc = compute_jinc(ty0, ty1); + double th = s[i].bend_th; + double ends[2][4]; + double derivs[4][2][4]; + int jthl = -1, jk0l = -1, jk1l = -1, jk2l = -1; + int jthr = -1, jk0r = -1, jk1r = -1, jk2r = -1; + + compute_pderivs(&s[i], ends, derivs, jinc); + + /* constraints crossing left */ + if (ty0 == 'o' || ty0 == 'c' || ty0 == '[' || ty0 == ']') { + jthl = jj++; + jj %= nmat; + jk0l = jj++; + } + if (ty0 == 'o') { + jj %= nmat; + jk1l = jj++; + jk2l = jj++; + } - /* constraints on left */ - if ((ty0 == '[' || ty0 == 'v' || ty0 == '{' || ty0 == 'c') && - jinc == 4) { - if (ty0 != 'c') - jk1l = jj++; - jk2l = jj++; - } + /* constraints on left */ + if ((ty0 == '[' || ty0 == 'v' || ty0 == '{' || ty0 == 'c') && + jinc == 4) { + if (ty0 != 'c') + jk1l = jj++; + jk2l = jj++; + } - /* constraints on right */ - if ((ty1 == ']' || ty1 == 'v' || ty1 == '}' || ty1 == 'c') && - jinc == 4) { - if (ty1 != 'c') - jk1r = jj++; - jk2r = jj++; - } + /* constraints on right */ + if ((ty1 == ']' || ty1 == 'v' || ty1 == '}' || ty1 == 'c') && + jinc == 4) { + if (ty1 != 'c') + jk1r = jj++; + jk2r = jj++; + } - /* constraints crossing right */ - if (ty1 == 'o' || ty1 == 'c' || ty1 == '[' || ty1 == ']') { - jthr = jj; - jk0r = (jj + 1) % nmat; - } - if (ty1 == 'o') { - jk1r = (jj + 2) % nmat; - jk2r = (jj + 3) % nmat; - } + /* constraints crossing right */ + if (ty1 == 'o' || ty1 == 'c' || ty1 == '[' || ty1 == ']') { + jthr = jj; + jk0r = (jj + 1) % nmat; + } + if (ty1 == 'o') { + jk1r = (jj + 2) % nmat; + jk2r = (jj + 3) % nmat; + } - add_mat_line(m, v, derivs[0][0], th - ends[0][0], 1, j, jthl, jinc, nmat); - add_mat_line(m, v, derivs[1][0], ends[0][1], -1, j, jk0l, jinc, nmat); - add_mat_line(m, v, derivs[2][0], ends[0][2], -1, j, jk1l, jinc, nmat); - add_mat_line(m, v, derivs[3][0], ends[0][3], -1, j, jk2l, jinc, nmat); - add_mat_line(m, v, derivs[0][1], -ends[1][0], 1, j, jthr, jinc, nmat); - add_mat_line(m, v, derivs[1][1], -ends[1][1], 1, j, jk0r, jinc, nmat); - add_mat_line(m, v, derivs[2][1], -ends[1][2], 1, j, jk1r, jinc, nmat); - add_mat_line(m, v, derivs[3][1], -ends[1][3], 1, j, jk2r, jinc, nmat); - if (jthl >= 0) - v[jthl] = mod_2pi(v[jthl]); - if (jthr >= 0) - v[jthr] = mod_2pi(v[jthr]); - j += jinc; + add_mat_line(m, v, derivs[0][0], th - ends[0][0], 1, j, jthl, jinc, nmat); + add_mat_line(m, v, derivs[1][0], ends[0][1], -1, j, jk0l, jinc, nmat); + add_mat_line(m, v, derivs[2][0], ends[0][2], -1, j, jk1l, jinc, nmat); + add_mat_line(m, v, derivs[3][0], ends[0][3], -1, j, jk2l, jinc, nmat); + add_mat_line(m, v, derivs[0][1], -ends[1][0], 1, j, jthr, jinc, nmat); + add_mat_line(m, v, derivs[1][1], -ends[1][1], 1, j, jk0r, jinc, nmat); + add_mat_line(m, v, derivs[2][1], -ends[1][2], 1, j, jk1r, jinc, nmat); + add_mat_line(m, v, derivs[3][1], -ends[1][3], 1, j, jk2r, jinc, nmat); + if (jthl >= 0) + v[jthl] = mod_2pi(v[jthl]); + if (jthr >= 0) + v[jthr] = mod_2pi(v[jthr]); + j += jinc; } if (cyclic) { - memcpy(m + nmat, m, sizeof(bandmat) * nmat); - memcpy(m + 2 * nmat, m, sizeof(bandmat) * nmat); - memcpy(v + nmat, v, sizeof(double) * nmat); - memcpy(v + 2 * nmat, v, sizeof(double) * nmat); - n_invert = 3 * nmat; - j = nmat; + memcpy(m + nmat, m, sizeof(bandmat) * nmat); + memcpy(m + 2 * nmat, m, sizeof(bandmat) * nmat); + memcpy(v + nmat, v, sizeof(double) * nmat); + memcpy(v + 2 * nmat, v, sizeof(double) * nmat); + n_invert = 3 * nmat; + j = nmat; } else { - n_invert = nmat; - j = 0; + n_invert = nmat; + j = 0; } #ifdef VERBOSE - for (i = 0; i < n; i++) { - int k; - for (k = 0; k < 11; k++) - printf(" %2.4f", m[i].a[k]); - printf(": %2.4f\n", v[i]); + for (int i = 0; i < n; i++) { + for (int k = 0; k < 11; k++) { + printf(" %2.4f", m[i].a[k]); + } + printf(": %2.4f\n", v[i]); } printf("---\n"); #endif bandec11(m, perm, n_invert); banbks11(m, perm, v, n_invert); - norm = 0.; - for (i = 0; i < n; i++) { - char ty0 = s[i].ty; - char ty1 = s[i + 1].ty; - int jinc = compute_jinc(ty0, ty1); - int k; + + double norm = 0.; + for (int i = 0; i < n; i++) { + char ty0 = s[i].ty; + char ty1 = s[i + 1].ty; + int jinc = compute_jinc(ty0, ty1); + int k; - for (k = 0; k < jinc; k++) { - double dk = v[j++]; + for (k = 0; k < jinc; k++) { + double dk = v[j++]; #ifdef VERBOSE - printf("s[%d].ks[%d] += %f\n", i, k, dk); + printf("s[%d].ks[%d] += %f\n", i, k, dk); #endif - s[i].ks[k] += dk; - norm += dk * dk; - } + s[i].ks[k] += dk; + norm += dk * dk; + } s[i].ks[0] = 2.0*mod_2pi(s[i].ks[0]/2.0); } return norm; } static int -solve_spiro(spiro_seg *s, int nseg) +solve_spiro(spiro_seg *s, const int nseg) { - bandmat *m; - double *v; - int *perm; int nmat = count_vec(s, nseg); int n_alloc = nmat; - double norm; - int i; - if (nmat == 0) - return 0; - if (s[0].ty != '{' && s[0].ty != 'v') - n_alloc *= 3; - if (n_alloc < 5) - n_alloc = 5; - m = (bandmat *)malloc(sizeof(bandmat) * n_alloc); - v = (double *)malloc(sizeof(double) * n_alloc); - perm = (int *)malloc(sizeof(int) * n_alloc); - - for (i = 0; i < 10; i++) { - norm = spiro_iter(s, m, perm, v, nseg); + if (nmat == 0) { + return 0; + } + if (s[0].ty != '{' && s[0].ty != 'v') { + n_alloc *= 3; + } + if (n_alloc < 5) { + n_alloc = 5; + } + + bandmat *m = (bandmat *)malloc(sizeof(bandmat) * n_alloc); + double *v = (double *)malloc(sizeof(double) * n_alloc); + int *perm = (int *)malloc(sizeof(int) * n_alloc); + + for (unsigned i = 0; i < 10; i++) { + double norm = spiro_iter(s, m, perm, v, nseg); #ifdef VERBOSE - printf("%% norm = %g\n", norm); + printf("%% norm = %g\n", norm); #endif - if (norm < 1e-12) break; + if (norm < 1e-12) break; } free(m); -- cgit v1.2.3