#[non_exhaustive]#[repr(u8)]pub enum Orientation {
Identity = 1,
FlipH = 2,
Rotate180 = 3,
FlipV = 4,
Transpose = 5,
Rotate90 = 6,
Transverse = 7,
Rotate270 = 8,
}Expand description
Image orientation — the 8-element D4 dihedral group.
Values 1-8 match EXIF tag 274 exactly.
#[repr(u8)] means o as u8 gives the EXIF value directly.
§Decomposition
| Variant | Rotation | FlipH? | Swaps axes? |
|------------|----------|--------|-------------|
| Identity | 0° | no | no |
| FlipH | 0° | yes | no |
| Rotate180 | 180° | no | no |
| FlipV | 180° | yes | no |
| Transpose | 90° CW | yes | yes |
| Rotate90 | 90° CW | no | yes |
| Transverse | 270° CW | yes | yes |
| Rotate270 | 270° CW | no | yes |§D4 group operations
compose implements group multiplication (verified
against a full Cayley table). inverse returns the
element that undoes the transformation.
use zenpixels::Orientation;
let combined = Orientation::Rotate90.then(Orientation::FlipH);
assert_eq!(combined, Orientation::Transpose);
let roundtrip = Orientation::Rotate90.compose(Orientation::Rotate90.inverse());
assert_eq!(roundtrip, Orientation::Identity);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Identity = 1
No transformation. EXIF 1.
FlipH = 2
Horizontal flip (mirror left-right). EXIF 2.
Rotate180 = 3
180° rotation. EXIF 3.
FlipV = 4
Vertical flip (= Rotate180 + FlipH). EXIF 4.
Transpose = 5
Transpose: reflect over main diagonal (= Rotate90 + FlipH). EXIF 5. Swaps axes.
Rotate90 = 6
90° clockwise rotation. EXIF 6. Swaps axes.
Transverse = 7
Transverse: reflect over anti-diagonal (= Rotate270 + FlipH). EXIF 7. Swaps axes.
Rotate270 = 8
270° clockwise rotation (= 90° counter-clockwise). EXIF 8. Swaps axes.
Implementations§
Source§impl Orientation
impl Orientation
Sourcepub const ALL: [Orientation; 8]
pub const ALL: [Orientation; 8]
All 8 orientations in EXIF order (1-8).
Sourcepub const fn from_exif(value: u8) -> Option<Orientation>
pub const fn from_exif(value: u8) -> Option<Orientation>
Create from EXIF orientation tag value (1-8).
Returns None for values outside 1-8. Use .unwrap_or_default()
if you want fallback to Identity.
Sourcepub const fn to_exif(self) -> u8
pub const fn to_exif(self) -> u8
Convert to EXIF orientation tag value (1-8).
Equivalent to self as u8 thanks to #[repr(u8)].
Sourcepub const fn is_identity(self) -> bool
pub const fn is_identity(self) -> bool
Whether this is the identity (no-op) transformation.
Sourcepub const fn swaps_axes(self) -> bool
pub const fn swaps_axes(self) -> bool
Whether this orientation swaps width and height.
True for orientations involving a 90° or 270° rotation (EXIF 5-8).
Sourcepub const fn is_row_local(self) -> bool
pub const fn is_row_local(self) -> bool
Sourcepub const fn compose(self, other: Orientation) -> Orientation
pub const fn compose(self, other: Orientation) -> Orientation
Compose two orientations: apply self first, then other.
This is D4 group multiplication, verified against the full Cayley table.
Sourcepub const fn then(self, other: Orientation) -> Orientation
pub const fn then(self, other: Orientation) -> Orientation
Alias for compose. Reads naturally in chains:
Rotate90.then(FlipH) = “apply Rotate90 first, then FlipH.”
Sourcepub const fn inverse(self) -> Orientation
pub const fn inverse(self) -> Orientation
The inverse orientation: self.compose(self.inverse()) == Identity.
Sourcepub const fn output_dimensions(self, w: u32, h: u32) -> (u32, u32)
pub const fn output_dimensions(self, w: u32, h: u32) -> (u32, u32)
Compute output dimensions after applying this orientation.
Returns (width, height) — swapped when swaps_axes is true.
Trait Implementations§
Source§impl Clone for Orientation
impl Clone for Orientation
Source§fn clone(&self) -> Orientation
fn clone(&self) -> Orientation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more