Skip to main content

Orientation

Enum Orientation 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const ALL: [Orientation; 8]

All 8 orientations in EXIF order (1-8).

Source

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.

Source

pub const fn to_exif(self) -> u8

Convert to EXIF orientation tag value (1-8).

Equivalent to self as u8 thanks to #[repr(u8)].

Source

pub const fn is_identity(self) -> bool

Whether this is the identity (no-op) transformation.

Source

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).

Source

pub const fn is_row_local(self) -> bool

Whether this can be applied per-row without buffering the full image.

Only Identity and FlipH are row-local — all other transforms require access to multiple rows.

Source

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.

Source

pub const fn then(self, other: Orientation) -> Orientation

Alias for compose. Reads naturally in chains: Rotate90.then(FlipH) = “apply Rotate90 first, then FlipH.”

Source

pub const fn inverse(self) -> Orientation

The inverse orientation: self.compose(self.inverse()) == Identity.

Source

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.

Source

pub const fn forward_map(self, sx: u32, sy: u32, w: u32, h: u32) -> (u32, u32)

Forward-map a source pixel (sx, sy) to its destination position.

(w, h) are the source (pre-orientation) dimensions. Returns (dx, dy) in the output coordinate space.

Trait Implementations§

Source§

impl Clone for Orientation

Source§

fn clone(&self) -> Orientation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Orientation

Source§

impl Debug for Orientation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Orientation

Source§

fn default() -> Orientation

Returns the “default value” for a type. Read more
Source§

impl Eq for Orientation

Source§

impl Hash for Orientation

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Orientation

Source§

fn eq(&self, other: &Orientation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Orientation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.