nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Fix Point display to respect formatting parameters

Open owenbrooks opened this issue 3 years ago • 11 comments

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 │
  └        ┘

}

owenbrooks avatar Jun 06 '22 09:06 owenbrooks

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.

Ralith avatar Jun 06 '22 17:06 Ralith

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.

owenbrooks avatar Jun 07 '22 00:06 owenbrooks

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?

Ralith avatar Jun 07 '22 00:06 Ralith

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.

owenbrooks avatar Jun 07 '22 01:06 owenbrooks

Ah, good call.

Ralith avatar Jun 07 '22 01:06 Ralith

(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...

RReverser avatar Jun 07 '22 08:06 RReverser

(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]

owenbrooks avatar Jun 07 '22 08:06 owenbrooks

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).

RReverser avatar Jun 07 '22 09:06 RReverser

Conversely, fancy many-line 2D layout with unicode block drawing is worlds apart from what you'd expect in Debug.

Ralith avatar Jun 07 '22 21:06 Ralith

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.

RReverser avatar Jun 07 '22 23:06 RReverser

I've tried to reduce these inconsistencies in #1119. Would appreciate feedback!

owenbrooks avatar Jun 11 '22 06:06 owenbrooks