https://github.com/ickshonpe/math_type_display_hack
compact math type display
https://github.com/ickshonpe/math_type_display_hack
bevy math
Last synced: about 1 month ago
JSON representation
compact math type display
- Host: GitHub
- URL: https://github.com/ickshonpe/math_type_display_hack
- Owner: ickshonpe
- License: mit
- Created: 2022-06-10T12:23:49.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-12T21:03:42.000Z (about 4 years ago)
- Last Synced: 2026-02-14T04:53:08.889Z (4 months ago)
- Topics: bevy, math
- Language: Rust
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# math type display hack
Bashed this together because Bevy doesn't implement ```Display``` for its math types like ```Transform``` and ```GlobalTransform```.
## examples
### With ```Debug```:
```rust
let translation = 2.0_f32.sqrt() * Vec3::X;
let tf = Transform {
translation,
..Default::default()
};
println!("{:?}", translation);
println!("{:.1?}", translation);
println!("{:?}", translation.as_ref());
println!("{:.1?}", translation.as_ref());
println!("{:?}", tf);
println!("{:.1?}", tf);
```
which outputs
```
Vec3(1.4142135, 0.0, 0.0)
Vec3(1.4, 0.0, 0.0)
[1.4142135, 0.0, 0.0]
[1.4, 0.0, 0.0]
Transform { translation: Vec3(1.4142135, 0.0, 0.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
Transform { translation: Vec3(1.4, 0.0, 0.0), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }
```
### With ```math_type_display_hack```:
```rust
use math_type_display_hack::*;
let translation = 2.0_f32.sqrt() * Vec3::X;
let tf = Transform {
translation,
..Default::default()
};
println!("{}", translation.display());
println!("{:.1}", translation.display());
println!("{}", tf.display());
println!("{:.1}", tf.display());
```
which outputs
```
[1.4142135, 0.0, 0.0]
[1.4, 0.0, 0.0]
{ [1.4142135, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0] }
{ [1.4, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0] }
```