From 6dce47129786142d032d0bf2cc8151b6acc3b64f Mon Sep 17 00:00:00 2001 From: Kurt Lawrence Date: Thu, 21 Dec 2023 08:42:54 +1000 Subject: [PATCH] Make OPoint call `T::fmt` to respect formatting modifiers (#1336) --- src/geometry/point.rs | 5 +++-- tests/geometry/point.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 5ccb6279..789d2e6a 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -511,10 +511,11 @@ where let mut it = self.coords.iter(); - write!(f, "{}", *it.next().unwrap())?; + ::fmt(it.next().unwrap(), f)?; for comp in it { - write!(f, ", {}", *comp)?; + write!(f, ", ")?; + ::fmt(comp, f)?; } write!(f, "}}") diff --git a/tests/geometry/point.rs b/tests/geometry/point.rs index 22b0f598..42adf118 100644 --- a/tests/geometry/point.rs +++ b/tests/geometry/point.rs @@ -92,3 +92,11 @@ fn to_homogeneous() { assert_eq!(a.to_homogeneous(), expected); } + +#[test] +fn display_fmt_respects_modifiers() { + let p = Point3::new(1.23, 3.45, 5.67); + assert_eq!(&format!("{p}"), "{1.23, 3.45, 5.67}"); + assert_eq!(&format!("{p:.1}"), "{1.2, 3.5, 5.7}"); + assert_eq!(&format!("{p:.0}"), "{1, 3, 6}"); +}