Commit 64b79917 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

graphics: add from_{unit,px,pt,rem} helper methods

parent 31645c90
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -43,6 +43,22 @@ Measure::operator double() const {
  return value;
}

Measure from_unit(double v) {
  return Measure{.unit = Unit::UNIT, .value = v};
}

Measure from_px(double v) {
  return Measure{.unit = Unit::PX, .value = v};
}

Measure from_pt(double v) {
  return Measure{.unit = Unit::PT, .value = v};
}

Measure from_rem(double v) {
  return Measure{.unit = Unit::REM, .value = v};
}

Measure to_px(const MeasureTable& t, const Measure& v) {
  double v_px;

+6 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
namespace plotfx {

enum class Unit {
  UNIT, PT, PX, REM
  UNIT, PX, PT, REM
};

struct MeasureTable {
@@ -51,6 +51,11 @@ struct Measure {
  operator double() const;
};

Measure from_unit(double v);
Measure from_px(double v);
Measure from_pt(double v);
Measure from_rem(double v);

Measure to_px(const MeasureTable& t, const Measure& v);

} // namespace plotfx