diff options
| author | Matthew Petroff <matthew@mpetroff.net> | 2013-06-25 00:47:57 +0000 |
|---|---|---|
| committer | Matthew Petroff <matthew@mpetroff.net> | 2013-06-25 00:47:57 +0000 |
| commit | 1c06fa5e2552b291534f0b96542070f00fd0778b (patch) | |
| tree | f2d0db888f30ff84ace9923a6116f6a6f1bc1c80 /src/util/units.cpp | |
| parent | Fix my own mis-credit and some symbols labels (diff) | |
| download | inkscape-1c06fa5e2552b291534f0b96542070f00fd0778b.tar.gz inkscape-1c06fa5e2552b291534f0b96542070f00fd0778b.zip | |
Added length class.
(bzr r12380.1.1)
Diffstat (limited to 'src/util/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp index f822d01de..3bcbabf89 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -334,10 +334,47 @@ void UnitsSAXHandler::_endElement(xmlChar const *xname) } } +/** Initialize a length. */ +Length::Length(Unit *u, double l) { + unit = u; + length = l; +} + +/** Checks if a length is compatible with the specified unit. */ +bool Length::compatibleWith(Unit *u) { + // Percentages + if (unit->type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) { + return true; + } + + // Other units with same type + if (unit->type == u->type) { + return true; + } + + // Different, incompatible types + return false; +} + +/** Return the length's value in the specified unit. */ +double Length::value(Unit *u) { + return convert(length, unit, u); +} + +/** Convert distances. */ +double Length::convert(double from_dist, Unit *from, Unit *to) const { + // Incompatible units + if (from->type != to->type) { + return -1; + } + + // Compatible units + return from_dist / from->factor * to->factor; +} + } // namespace Util } // namespace Inkscape - /* Local Variables: mode:c++ |
