summaryrefslogtreecommitdiff
path: root/src/geom/angle.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-15 15:43:59 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-15 15:43:59 +0100
commit0f0416054f263b80ccec1a463ce4ab20913bdf71 (patch)
tree09cc642c361327c386e88e89f81f512248d59514 /src/geom/angle.rs
parent469d78d610085044845f0fba462f1d8170b62cd4 (diff)
Move value tests + smarter number formatting 🔢
Diffstat (limited to 'src/geom/angle.rs')
-rw-r--r--src/geom/angle.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs
index 47541cb8..07471a02 100644
--- a/src/geom/angle.rs
+++ b/src/geom/angle.rs
@@ -56,7 +56,16 @@ impl Angle {
impl Display for Angle {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{}{}", self.to_deg(), AngularUnit::Deg)
+ // Format with the unit that yields the shortest output, preferring
+ // degrees when tied.
+ let mut buf = ryu::Buffer::new();
+ let unit = [AngularUnit::Deg, AngularUnit::Rad]
+ .iter()
+ .copied()
+ .min_by_key(|&unit| buf.format(self.to_unit(unit)).len())
+ .unwrap();
+
+ write!(f, "{}{}", buf.format(self.to_unit(unit)), unit)
}
}