Skip to content

Commit

Permalink
Extend automatic unit conversions with additional units
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Nov 28, 2024
1 parent cb1944a commit 58d0d1d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
44 changes: 27 additions & 17 deletions library/cpp/src/core/config/value_with_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@
namespace wavemap::param {
// clang-format off
static const std::map<std::string, std::pair<FloatingPoint, SiUnit::Id>> UnitToSi{
{"meters", {1e0f, SiUnit::kMeters}},
{"m", {1e0f, SiUnit::kMeters}},
{"decimeters", {1e-1f, SiUnit::kMeters}},
{"dm", {1e-1f, SiUnit::kMeters}},
{"centimeters", {1e-2f, SiUnit::kMeters}},
{"cm", {1e-2f, SiUnit::kMeters}},
{"millimeters", {1e-3f, SiUnit::kMeters}},
{"mm", {1e-3f, SiUnit::kMeters}},
{"radians", {1.f, SiUnit::kRadians}},
{"rad", {1.f, SiUnit::kRadians}},
{"degrees", {kPi / 180.f, SiUnit::kRadians}},
{"deg", {kPi / 180.f, SiUnit::kRadians}},
{"pixels", {1.f, SiUnit::kPixels}},
{"px", {1.f, SiUnit::kPixels}},
{"seconds", {1.f, SiUnit::kSeconds}},
{"sec", {1.f, SiUnit::kSeconds}},
{"s", {1.f, SiUnit::kSeconds}},
{"kilometers", {1e3f, SiUnit::kMeters}},
{"km", {1e3f, SiUnit::kMeters}},
{"meters", {1e0f, SiUnit::kMeters}},
{"m", {1e0f, SiUnit::kMeters}},
{"decimeters", {1e-1f, SiUnit::kMeters}},
{"dm", {1e-1f, SiUnit::kMeters}},
{"centimeters", {1e-2f, SiUnit::kMeters}},
{"cm", {1e-2f, SiUnit::kMeters}},
{"millimeters", {1e-3f, SiUnit::kMeters}},
{"mm", {1e-3f, SiUnit::kMeters}},
{"radians", {1.f, SiUnit::kRadians}},
{"rad", {1.f, SiUnit::kRadians}},
{"degrees", {kPi / 180.f, SiUnit::kRadians}},
{"deg", {kPi / 180.f, SiUnit::kRadians}},
{"pixels", {1.f, SiUnit::kPixels}},
{"px", {1.f, SiUnit::kPixels}},
{"hours", {3600.f, SiUnit::kSeconds}},
{"h", {3600.f, SiUnit::kSeconds}},
{"minutes", {60.f, SiUnit::kSeconds}},
{"seconds", {1.f, SiUnit::kSeconds}},
{"sec", {1.f, SiUnit::kSeconds}},
{"s", {1.f, SiUnit::kSeconds}},
{"milliseconds", {1e-3f, SiUnit::kSeconds}},
{"ms", {1e-3f, SiUnit::kSeconds}},
{"microseconds", {1e-6f, SiUnit::kSeconds}},
{"nanoseconds", {1e-9f, SiUnit::kSeconds}},
{"ns", {1e-9f, SiUnit::kSeconds}},
};
// clang-format on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"minProperties": 1,
"maxProperties": 1,
"properties": {
"kilometers": {
"type": "number"
},
"km": {
"type": "number"
},
"meters": {
"type": "number"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"minProperties": 1,
"maxProperties": 1,
"properties": {
"hours": {
"type": "number"
},
"h": {
"type": "number"
},
"minutes": {
"type": "number"
},
"seconds": {
"type": "number"
},
Expand All @@ -13,6 +22,21 @@
},
"s": {
"type": "number"
},
"milliseconds": {
"type": "number"
},
"ms": {
"type": "number"
},
"microseconds": {
"type": "number"
},
"nanoseconds": {
"type": "number"
},
"ns": {
"type": "number"
}
}
}

0 comments on commit 58d0d1d

Please sign in to comment.