diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-08-09 11:47:56 +0000 |
|---|---|---|
| committer | Javiertxo <jtx@jtx.marker.es> | 2013-08-09 11:47:56 +0000 |
| commit | 4e358f420a7a1512c722d9eccd864416bc4c075b (patch) | |
| tree | 223e826158e09ab2c864abf0214fe1e6a714ab61 /src/live_effects | |
| parent | Update to trunk (diff) | |
| parent | Remove missing files from POTFILES.in (diff) | |
| download | inkscape-4e358f420a7a1512c722d9eccd864416bc4c075b.tar.gz inkscape-4e358f420a7a1512c722d9eccd864416bc4c075b.zip | |
update to trunk
(bzr r11950.1.127)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/lpe-path_length.cpp | 6 | ||||
| -rw-r--r-- | src/live_effects/lpe-ruler.cpp | 8 | ||||
| -rw-r--r-- | src/live_effects/parameter/unit.cpp | 24 | ||||
| -rw-r--r-- | src/live_effects/parameter/unit.h | 15 | ||||
| -rw-r--r-- | src/live_effects/spiro.cpp | 242 |
5 files changed, 151 insertions, 144 deletions
diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index d3edcda27..4ca380c15 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -14,7 +14,7 @@ #include <glibmm/i18n.h> #include "live_effects/lpe-path_length.h" -#include "sp-metrics.h" +#include "util/units.h" #include "2geom/sbasis-geometric.h" @@ -52,11 +52,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis> > const & pwd2_i std::vector<double> 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; s<totlength; s+=real_mark_distance){ s_cuts.push_back(s); } diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 602d806a0..561766920 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -10,6 +10,9 @@ #include "live_effects/parameter/unit.h" #include "live_effects/effect.h" #include "verbs.h" +#include "util/units.h" + +using Inkscape::Util::unit_table; namespace Inkscape { @@ -18,10 +21,10 @@ namespace LivePathEffect { UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, SPUnitId default_value) + Effect* effect, Glib::ustring default_unit) : Parameter(label, tip, key, wr, effect) { - defunit = &sp_unit_get_by_id(default_value);; + defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit)); unit = defunit; } @@ -32,9 +35,8 @@ UnitParam::~UnitParam() bool UnitParam::param_readSVGValue(const gchar * strvalue) { - SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue); - if (newval) { - param_set_value(newval); + if (strvalue) { + param_set_value(unit_table.getUnit(strvalue)); return true; } return false; @@ -43,25 +45,25 @@ UnitParam::param_readSVGValue(const gchar * strvalue) gchar * UnitParam::param_getSVGValue() const { - return g_strdup(sp_unit_get_abbreviation(unit)); + return g_strdup(unit->abbr.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 * @@ -74,7 +76,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<Gtk::Widget *> (unit_menu); 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 <helper/units.h> 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&); 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); |
