diff options
| author | Martin Owens <doctormo@gmail.com> | 2016-03-22 19:17:52 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2016-03-22 19:17:52 +0000 |
| commit | c7d0b04c70397faadf0131ab5d846068f44d5062 (patch) | |
| tree | 2b9407b328d13ccee3b26b1ea003c57aca2b4e19 /src/util/units.cpp | |
| parent | Make sure adjustment is attached to spin button (diff) | |
| download | inkscape-c7d0b04c70397faadf0131ab5d846068f44d5062.tar.gz inkscape-c7d0b04c70397faadf0131ab5d846068f44d5062.zip | |
Un-revert: Allow Unit object to do conversions, pipe Quality class method via that.
(bzr r14739)
Diffstat (limited to 'src/util/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp index 2c72ec3ae..cf4bfd146 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -231,6 +231,30 @@ int Unit::svgUnit() const return 0; } +double Unit::convert(double from_dist, Unit const *to) const +{ + // Percentage + if (to->type == UNIT_TYPE_DIMENSIONLESS) { + return from_dist * to->factor; + } + + // Incompatible units + if (type != to->type) { + return -1; + } + + // Compatible units + return from_dist * factor / to->factor; +} +double Unit::convert(double from_dist, Glib::ustring const &to) const +{ + return convert(from_dist, unit_table.getUnit(to)); +} +double Unit::convert(double from_dist, char const *to) const +{ + return convert(from_dist, unit_table.getUnit(to)); +} + Unit UnitTable::_empty_unit; @@ -505,18 +529,7 @@ Glib::ustring Quantity::string() const { double Quantity::convert(double from_dist, Unit const *from, Unit const *to) { - // Percentage - if (to->type == UNIT_TYPE_DIMENSIONLESS) { - return from_dist * to->factor; - } - - // Incompatible units - if (from->type != to->type) { - return -1; - } - - // Compatible units - return from_dist * from->factor / to->factor; + return from->convert(from_dist, to); } double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to) { |
