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:
parent
44d7aab53d
commit
dd52291af4
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue