Fix Point display to respect formatting parameters
This changes Point Display formatting to match formatting of other geometry types, including Isometry, Scale, and Rotation. Fixes issue #1115 since it passes through the desired precision formatting parameter.
Example:
let point = nalgebra::Point3::new(1.12345678, 2.12345678, 3.12345678);
println!("{point:.4}");
Before:
{1.12345678, 2.12345678, 3.12345678}
After:
Point {
┌ ┐
│ 1.1235 │
│ 2.1235 │
│ 3.1235 │
└ ┘
}
I think it would be better to just forward to the underlying Vector's fmt. Reduces verbosity and handles flags other than precision correctly as well.
That does seem simpler, thanks. I've made that change. Which other flags were you expecting it to handle when forwarding? From what I can see it looks like the underlying matrix formatting ignores most parameters aside from precision. I'm wondering if it would be worth forwarding fmt for the other geometry types too.
Ah, if Matrix::display isn't handling e.g. padding and signs properly then we at least have a single place to fix that. What other types currently having Display impls did you have in mind?
The Isometry, Scale, Rotation, and Translation types all have similar Display impls that only pass through precision and have similar wrapping with “Typename {“ and “}”. I would prefer omitting the wrapper myself too but would probably want it to be consistent.
Ah, good call.
(reporter of the referenced issue here) Hm, I actually liked the concise single-line form of Point, while the new form makes it a bit more verbose.
I guess it does make it more consistent with other formats though...
(reporter of the referenced issue here) Hm, I actually liked the concise single-line form of Point, while the new form makes it a bit more verbose.
I guess it does make it more consistent with other formats though...
Ah, have you tried debug printing? It's concise and actually does follow all format specifiers:
let point = nalgebra::Point3::new(1.12345678, 2.12345678, 3.12345678);
println!("{point:.4?}");
Gives [1.1235, 2.1235, 3.1235]
Ah, have you tried debug printing? It's concise and actually does follow all format specifiers:
Huh, I haven't! It's actually a bit surprising that Debug formatting in this case looks more like what I'd expect from Display (being more human-readable and all) while Display formatting in this PR is more like what I'd expect from Debug (showing type names and all).
Conversely, fancy many-line 2D layout with unicode block drawing is worlds apart from what you'd expect in Debug.
Conversely, fancy many-line 2D layout with unicode block drawing is worlds apart from what you'd expect in
Debug.
Sounds like we're in agreement. For matrix types I'd expect neat block drawing in Display, but type names and such in Debug.
In case of Point it's just a bit different because, personally, I wouldn't want either of Display or Debug to show a vertical block but rather show values in line for convenience like Point does today.
I've tried to reduce these inconsistencies in #1119. Would appreciate feedback!