Repository: bevyengine/bevy
File: crates/bevy_sprite_render/src/tilemap_chunk/tile_orientation.rs (Rust)

Code before:
use core::fmt::Display;

use bevy_math::IVec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};

/// The set of possible tile orientations based on any combination of mirroring in
/// x and/or y axes, and/or rotation by 90 degree increments.
/// The ordering starts from the default orientation (no rotation or mirroring),
/// then we have 90 degree clockwise rotations, then we start from a mirror in the x
/// and perform 90 degree rotations of that.
/// The representation is a u8 value where the bits (from most significant to least
/// significant), represent mirroring in the x axis, then the y axis, then the diagonal
/// axis running from the top-left of the tile to the bottom-right (which corresponds to
/// swapping the x and y axes).
/// This allows easy conversion to the format used for tile indices in Tiled maps,
/// where bits 31, 30 and 29 correspond to bits 2, 1 and 0 of this enum's values.
/// So for a given enum value, we can just use `value << 29` to produce the bits required
/// in a Tiled index.
#[derive(Debug, Clone, Copy, Reflect, Default, PartialEq, Eq, Hash)]
#[reflect(Default, Clone, PartialEq, Hash)]
#[repr(u8)]
pub enum TileOrientation {
    #[default]
    Default = 0b000,
    Rotate90 = 0b101,
    Rotate180 = 0b110,
    Rotate270 = 0b011,
    MirrorX = 0b100,
    MirrorXRotate90 = 0b111,
    MirrorXRotate180 = 0b010,
    MirrorXRotate270 = 0b001,
}

Review comment (suggestion):
I think it makes sense to mention whether the rotations are CW or CCW in this first doc comment sentence

But I also question about whether “clockwise” should be the standard here. At least in `bevy_math`, [Rot2](https://docs.rs/bevy/latest/bevy/math/struct.Rot2.html) is defined with counterclockwise angles. I don’t have an answer, but I just bring it up as a potential point of confusion

Code after:
use core::fmt::Display;

use bevy_math::IVec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};

/// The set of possible tile orientations.
/// These represent all possible results of mirroring the tile horizontally
/// and/or vertically, and/or rotation by 90 degree increments.
///
/// Rotation is measured counter-clockwise as elsewhere in Bevy.
///
/// The representation is a u8 value where the bits (from most significant to least
/// significant), represent:
///
/// - Bit 2: Mirroring the tile horizontally (left and right sides are swapped)
/// - Bit 1: Mirroring the tile vertically (top and bottom are swapped)
/// - Bit 0: Mirroring the tile diagonally (top-right and bottom-left corners are swapped)
///
/// The order in which the mirroring is performed matters - the tile is first mirrored
/// horizontally (if specified), then vertically, then finally diagonally, in the UV
/// coordinate system.
///
/// Note that different coordinate systems are used for UV mapping and Bevy world
/// coordinates (e.g. in UV maps, the y component increases towards the bottom of
/// the tile, in Bevy it increases towards the top). This means that the ordering
/// in which the mirroring is applied differs in different coordinate systems.
///
/// The ordering of the enum starts from the default orientation (no rotation or mirroring),
/// then we have successive 90 degree counter-clockwise rotations. Then we have a tile
/// mirrored horizontally, and then the results of successive 90 degree counter-clockwise
/// rotations of the mirrored tile.
///