14#ifndef INKSCAPE_UTIL_UNITS_H
15#define INKSCAPE_UTIL_UNITS_H
17#include <unordered_map>
18#include <boost/operators.hpp>
19#include <glibmm/ustring.h>
20#include <glibmm/ustring_hash.h>
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26#define DEFAULT_UNIT_NAME "mm"
43const char DEG[] =
"°";
46 : boost::equality_comparable<Unit>
86 double convert(
double from_dist,
Unit const *to)
const;
87 double convert(
double from_dist, Glib::ustring
const &to)
const;
88 double convert(
double from_dist,
char const *to)
const;
92 : boost::totally_ordered<Quantity>
100 Quantity(
double q, Glib::ustring
const &u);
110 double value(Glib::ustring
const &u)
const;
111 double value(
char const *u)
const;
115 Glib::ustring
string(Glib::ustring
const &u)
const;
116 Glib::ustring
string()
const;
120 static double convert(
double from_dist,
Unit const *from,
Unit const *to);
121 static double convert(
double from_dist, Glib::ustring
const &from,
Unit const *to);
122 static double convert(
double from_dist,
Unit const *from, Glib::ustring
const &to);
123 static double convert(
double from_dist, Glib::ustring
const &from, Glib::ustring
const &to);
124 static double convert(
double from_dist,
char const *from,
char const *to);
146 typedef std::unordered_map<Glib::ustring, Unit>
UnitMap;
189 bool load(std::string
const &filename);
bool compatibleWith(Unit const *u) const
Checks if a quantity is compatible with the specified unit.
double value(Unit const *u) const
Return the quantity's value in the specified unit.
Glib::ustring string() const
bool operator==(Quantity const &other) const
bool operator<(Quantity const &rhs) const
Comparison operators.
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
Unit const * findUnit(double factor, UnitType type) const
Try to find a unit based on its conversion factor to the primary.
Glib::ustring primary(UnitType type) const
Returns the default unit abbr for the given type.
Quantity parseQuantity(Glib::ustring const &q) const
Retrieve a quantity based on its string identifier.
std::unordered_map< Glib::ustring, Unit > UnitMap
UnitMap units(UnitType type) const
Provides an iterable list of items in the given unit table.
UnitTable operator=(UnitTable const &t)
bool load(std::string const &filename)
Load units from an XML file.
void addUnit(Unit const &u, bool primary)
Add a new unit to the table.
bool hasUnit(Glib::ustring const &name) const
Remove a unit definition from the given unit type table * / DISABLED, unsafe with the current passing...
UnitTable(UnitTable const &t)
std::unordered_map< unsigned, Unit * > UnitCodeMap
Glib::ustring _primary_unit[UNIT_TYPE_QTY]
Unit const * getUnit(Glib::ustring const &name) const
Retrieve a given unit based on its string identifier.
UnitTable()
Initializes the unit tables and identifies the primary unit types.
Glib::ustring description
double convert(double from_dist, Unit const *to) const
Convert value from this unit.
Glib::ustring name_plural
int defaultDigits() const
Returns the suggested precision to use for displaying numbers of this unit.
bool compatibleWith(char const *) const
bool compatibleWith(Unit const *u) const
Checks if a unit is compatible with the specified unit.
int svgUnit() const
Get SVG unit code.
bool operator==(Unit const &other) const
Check if units are equal.
Integral and real coordinate types and some basic utilities.
constexpr Coord EPSILON
Default "acceptably small" value.
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Miscellaneous supporting code.
@ UNIT_TYPE_LINEAR_SCALED
@ UNIT_TYPE_DIMENSIONLESS
bool are_near(Quantity const &a, Quantity const &b, double eps=Geom::EPSILON)
Helper class to stream background task notifications as a series of messages.