dimforge / dimforge/nalgebra

Matrix Display output alignment is not Unicode-aware

Open
#1,354 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Hi,

Thanks for all the wonderful work on this library. I'm coming back after a Rust hiatus and I can't believe the const generics work as well as they do.

I'm using a custom scalar type that uses a combining overline character instead of a minus sign, to match the style of this reference work:

![image](https://github.com/dimforge/nalgebra/assets/26395633/f274eec5-81d8-40b5-9c8f-479156214b2b)

Somewhat ironically, a typesetting convention designed to make alignment easier in print breaks alignment for `Matrix` output using this custom type:

```rs
┌ ┐
│ 0 ̅1 0 0 │
│ 0 ̅1 0 0 │
│ ⅔ 0 1 0 │
│ 0 0 0 1 │
└ ┘
```

The `Display` implementation [here](https://docs.rs/nalgebra/latest/src/nalgebra/base/matrix.rs.html#1897) uses `.char().count()` instead of [grapheme](https://docs.rs/unicode-segmentation/latest/unicode_segmentation/struct.Graphemes.html) counting, which is what causes the misalignment seen here. I imagine this would also affect less frivolous custom `Display` impls, like Chinese characters.

`unicode-segmentation` is a large dependency to make a tiny edge case look nicer, so I'm not exactly saying this *should* be implemented differently, but I'd be interested if anyone else has had this issue or if there's a solution that doesn't require increasing the code size too massively.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.