From f6060c9447e6f2e5a70e957c19bd4eb1ae4babef Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Feb 2014 20:32:07 +0100 Subject: inspired by r13052, fix up the code to hopefully work when someone has different units for height and width of the page. Fixed bugs: - https://launchpad.net/bugs/1240308 (bzr r13053) --- src/util/units.cpp | 13 ++++++++++--- src/util/units.h | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/util') diff --git a/src/util/units.cpp b/src/util/units.cpp index 40cce028d..d2053f60b 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -505,16 +505,23 @@ double Quantity::convert(double from_dist, char const *from, char const *to) return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); } -bool Quantity::operator<(Quantity const &other) const +bool Quantity::operator<(Quantity const &rhs) const { - if (unit->type != other.unit->type) { + if (unit->type != rhs.unit->type) { g_warning("Incompatible units"); return false; } - return quantity < other.value(unit); + return quantity < rhs.value(unit); } bool Quantity::operator==(Quantity const &other) const { + /** \fixme This is overly strict. I think we should change this to: + if (unit->type != other.unit->type) { + g_warning("Incompatible units"); + return false; + } + return are_near(quantity, other.value(unit)); + */ return (*unit == *other.unit) && (quantity == other.quantity); } diff --git a/src/util/units.h b/src/util/units.h index 597371369..efe1dbec7 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -16,6 +16,7 @@ #include #include #include +#include <2geom/coord.h> #include "svg/svg-length.h" #include "unordered-containers.h" @@ -112,10 +113,15 @@ public: static double convert(double from_dist, char const *from, char const *to); /** Comparison operators. */ - bool operator<(Quantity const &other) const; + bool operator<(Quantity const &rhs) const; bool operator==(Quantity const &other) const; }; +inline bool are_near(Quantity const &a, Quantity const &b, double eps=Geom::EPSILON) +{ + return Geom::are_near(a.quantity, b.value(a.unit), eps); +} + class UnitTable { public: /** -- cgit v1.2.3