bevy/crates
Joona Aalto f418de8eb6
Rename Direction2d/3d to Dir2/3 (#12189)
# Objective

Split up from #12017, rename Bevy's direction types.

Currently, Bevy has the `Direction2d`, `Direction3d`, and `Direction3dA`
types, which provide a type-level guarantee that their contained vectors
remain normalized. They can be very useful for a lot of APIs for safety,
explicitness, and in some cases performance, as they can sometimes avoid
unnecessary normalizations.

However, many consider them to be inconvenient to use, and opt for
standard vector types like `Vec3` because of this. One reason is that
the direction type names are a bit long and can be annoying to write (of
course you can use autocomplete, but just typing `Vec3` is still nicer),
and in some intances, the extra characters can make formatting worse.
The naming is also inconsistent with Glam's shorter type names, and
results in names like `Direction3dA`, which (in my opinion) are
difficult to read and even a bit ugly.

This PR proposes renaming the types to `Dir2`, `Dir3`, and `Dir3A`.
These names are nice and easy to write, consistent with Glam, and work
well for variants like the SIMD aligned `Dir3A`. As a bonus, it can also
result in nicer formatting in a lot of cases, which can be seen from the
diff of this PR.

Some examples of what it looks like: (copied from #12017)

```rust
// Before
let ray_cast = RayCast2d::new(Vec2::ZERO, Direction2d::X, 5.0);

// After
let ray_cast = RayCast2d::new(Vec2::ZERO, Dir2::X, 5.0);
```

```rust
// Before (an example using Bevy XPBD)
let hit = spatial_query.cast_ray(
    Vec3::ZERO,
    Direction3d::X,
    f32::MAX,
    true,
    SpatialQueryFilter::default(),
);

// After
let hit = spatial_query.cast_ray(
    Vec3::ZERO,
    Dir3::X,
    f32::MAX,
    true,
    SpatialQueryFilter::default(),
);
```

```rust
// Before
self.circle(
    Vec3::new(0.0, -2.0, 0.0),
    Direction3d::Y,
    5.0,
    Color::TURQUOISE,
);

// After (formatting is collapsed in this case)
self.circle(Vec3::new(0.0, -2.0, 0.0), Dir3::Y, 5.0, Color::TURQUOISE);
```

## Solution

Rename `Direction2d`, `Direction3d`, and `Direction3dA` to `Dir2`,
`Dir3`, and `Dir3A`.

---

## Migration Guide

The `Direction2d` and `Direction3d` types have been renamed to `Dir2`
and `Dir3`.

## Additional Context

This has been brought up on the Discord a few times, and we had a small
[poll](https://discord.com/channels/691052431525675048/1203087353850364004/1212465038711984158)
on this. `Dir2`/`Dir3`/`Dir3A` was quite unanimously chosen as the best
option, but of course it was a very small poll and inconclusive, so
other opinions are certainly welcome too.

---------

Co-authored-by: IceSentry <c.giguere42@gmail.com>
2024-02-28 22:48:43 +00:00
..
bevy_a11y Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_animation Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_app Use immutable key for HashMap and HashSet (#12086) 2024-02-26 16:27:40 +00:00
bevy_asset Add methods to directly load assets from World (#12023) 2024-02-27 00:28:26 +00:00
bevy_audio Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_color bevy_color: Add sequence_dispersed to Hsla, Lcha, Oklcha (#12173) 2024-02-28 21:45:48 +00:00
bevy_core Check cfg during CI and fix feature typos (#12103) 2024-02-25 15:19:27 +00:00
bevy_core_pipeline Register fxaa::Sensitivity and derive Debug (#12167) 2024-02-28 03:22:08 +00:00
bevy_derive Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_diagnostic Make sysinfo diagnostic plugin optional (#12164) 2024-02-28 20:00:42 +00:00
bevy_dylib Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_dynamic_plugin Document all members of bevy_dynamic_plugin (#12029) 2024-02-22 13:28:52 +00:00
bevy_ecs include links in error messages (#12165) 2024-02-28 00:01:18 +00:00
bevy_ecs_compile_fail_tests Remove APIs deprecated in 0.13 (#11974) 2024-02-19 19:04:47 +00:00
bevy_encase_derive Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_gilrs Make Gilrs a normal resource on non-Wasm targets (#12092) 2024-02-26 00:23:42 +00:00
bevy_gizmos Rename Direction2d/3d to Dir2/3 (#12189) 2024-02-28 22:48:43 +00:00
bevy_gltf Use immutable key for HashMap and HashSet (#12086) 2024-02-26 16:27:40 +00:00
bevy_hierarchy Add a colon to error message link (#12174) 2024-02-28 03:23:27 +00:00
bevy_input Fix missing renaming of Input -> ButtonInput (#12096) 2024-02-24 18:41:17 +00:00
bevy_internal Make sysinfo diagnostic plugin optional (#12164) 2024-02-28 20:00:42 +00:00
bevy_log Update tracing-log requirement from 0.1.2 to 0.2.0 (#10404) 2024-02-27 03:25:42 +00:00
bevy_macro_utils fix some typos (#12038) 2024-02-22 18:55:22 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Rename Direction2d/3d to Dir2/3 (#12189) 2024-02-28 22:48:43 +00:00
bevy_mikktspace fix some typos (#12038) 2024-02-22 18:55:22 +00:00
bevy_pbr Add random shader utils, fix cluster_debug_visualization (#11956) 2024-02-26 15:59:44 +00:00
bevy_ptr Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_reflect Rename Direction2d/3d to Dir2/3 (#12189) 2024-02-28 22:48:43 +00:00
bevy_reflect_compile_fail_tests bevy_reflect_derive: Clean up attribute logic (#11777) 2024-02-12 15:16:27 +00:00
bevy_render Rename Direction2d/3d to Dir2/3 (#12189) 2024-02-28 22:48:43 +00:00
bevy_scene Replace FromWorld requirement on ReflectResource and reflect Resource for State<S> (#12136) 2024-02-27 15:49:39 +00:00
bevy_sprite Prefer UVec2 when working with texture dimensions (#11698) 2024-02-25 15:23:04 +00:00
bevy_tasks Loosen lifetime requirements for single-threaded Scope::spawn to match the multi-threaded version. (#12073) 2024-02-24 06:01:34 +00:00
bevy_text include links in error messages (#12165) 2024-02-28 00:01:18 +00:00
bevy_time Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_transform Rename Direction2d/3d to Dir2/3 (#12189) 2024-02-28 22:48:43 +00:00
bevy_ui ui materials respect target camera (#12183) 2024-02-28 17:43:24 +00:00
bevy_utils fix some typos (#12038) 2024-02-22 18:55:22 +00:00
bevy_window Bump Version after Release (#12020) 2024-02-21 20:58:59 +00:00
bevy_winit Check cfg during CI and fix feature typos (#12103) 2024-02-25 15:19:27 +00:00