khora_core/math/dimension.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Provides structs for representing extents (sizes) and origins (offsets) in 1D, 2D, and 3D.
16//!
17//! These types are commonly used to describe the dimensions of textures, windows, or
18//! regions within them. They use integer (`u32`) components, making them suitable
19//! for representing pixel-based coordinates and sizes.
20
21/// A one-dimensional extent, typically representing a width.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
23pub struct Extent1D {
24 /// The width component of the extent.
25 pub width: u32,
26}
27
28/// A two-dimensional extent, typically representing width and height.
29///
30/// This is commonly used for texture dimensions or window sizes.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
32pub struct Extent2D {
33 /// The width component of the extent.
34 pub width: u32,
35 /// The height component of the extent.
36 pub height: u32,
37}
38
39/// A three-dimensional extent, representing width, height, and depth.
40///
41/// This is used for 3D textures, texture arrays, or cubemaps.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
43pub struct Extent3D {
44 /// The width component of the extent.
45 pub width: u32,
46 /// The height component of the extent.
47 pub height: u32,
48 /// The depth or number of array layers.
49 pub depth_or_array_layers: u32,
50}
51
52/// A two-dimensional origin, typically representing an (x, y) offset.
53///
54/// This is often used to specify the top-left corner of a rectangular region.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
56pub struct Origin2D {
57 /// The x-coordinate of the origin.
58 pub x: u32,
59 /// The y-coordinate of the origin.
60 pub y: u32,
61}
62
63/// A three-dimensional origin, representing an (x, y, z) offset.
64///
65/// This is often used to specify the corner of a 3D volume or an offset
66/// into a texture array.
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
68pub struct Origin3D {
69 /// The x-coordinate of the origin.
70 pub x: u32,
71 /// The y-coordinate of the origin.
72 pub y: u32,
73 /// The z-coordinate or array layer of the origin.
74 pub z: u32,
75}