diff options
| author | Richard White <rwhite8282@gmail.com> | 2016-05-19 01:17:29 +0000 |
|---|---|---|
| committer | Richard White <rwhite8282@gmail.com> | 2016-05-19 01:17:29 +0000 |
| commit | 1fe9c2603c33fddcd9f2688b30e843f91e1a86fa (patch) | |
| tree | 13289cbe033a46a40eb829437e115b5393e2ca84 /src/util/units.cpp | |
| parent | Corrected frame extension stroke and fill values on 64 bit machine. (diff) | |
| parent | GTK3: Another widget named. (diff) | |
| download | inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.tar.gz inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.zip | |
Merge from Inkscape trunk.
(bzr r14668.1.3)
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) { |
