Make `Debug` format of `Vec2/Pos2/Rot2` respect user precision (#4671)

* closes #4665

pretty self explanatory, i opted for 3 instead of 2 since i think that's
what display does
This commit is contained in:
Joe Sorensen 2024-06-18 15:03:23 -06:00 committed by GitHub
parent 44d7aab53d
commit dd52291af4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 8 deletions

View File

@ -319,7 +319,11 @@ impl Div<f32> for Pos2 {
impl fmt::Debug for Pos2 { impl fmt::Debug for Pos2 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{:.1} {:.1}]", self.x, self.y) if let Some(precision) = f.precision() {
write!(f, "[{1:.0$} {2:.0$}]", precision, self.x, self.y)
} else {
write!(f, "[{:.1} {:.1}]", self.x, self.y)
}
} }
} }

View File

@ -91,12 +91,22 @@ impl Rot2 {
impl std::fmt::Debug for Rot2 { impl std::fmt::Debug for Rot2 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!( if let Some(precision) = f.precision() {
f, write!(
"Rot2 {{ angle: {:.1}°, length: {} }}", f,
self.angle().to_degrees(), "Rot2 {{ angle: {:.2$}°, length: {} }}",
self.length() self.angle().to_degrees(),
) self.length(),
precision
)
} else {
write!(
f,
"Rot2 {{ angle: {:.1}°, length: {} }}",
self.angle().to_degrees(),
self.length(),
)
}
} }
} }

View File

@ -468,7 +468,11 @@ impl Div<f32> for Vec2 {
impl fmt::Debug for Vec2 { impl fmt::Debug for Vec2 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{:.1} {:.1}]", self.x, self.y) if let Some(precision) = f.precision() {
write!(f, "[{1:.0$} {2:.0$}]", precision, self.x, self.y)
} else {
write!(f, "[{:.1} {:.1}]", self.x, self.y)
}
} }
} }