1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2025 the Kurbo Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
use crate::{Point, Size, Vec2};
/// An axis in the plane.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum Axis {
/// The x axis.
Horizontal,
/// The y axis.
Vertical,
}
impl Axis {
/// Get the axis perpendicular to this one.
#[inline]
pub const fn cross(self) -> Self {
match self {
Self::Horizontal => Self::Vertical,
Self::Vertical => Self::Horizontal,
}
}
/// Create a new [`Point`] by arranging the given magnitudes.
///
/// The axis value is the one matching the axis (e.g. `y` for [`Self::Vertical`]).
/// The cross value is the other one.
#[inline]
pub const fn pack_point(self, axis_value: f64, cross_value: f64) -> Point {
match self {
Self::Horizontal => Point::new(axis_value, cross_value),
Self::Vertical => Point::new(cross_value, axis_value),
}
}
/// Create a new [`Size`] by arranging the given magnitudes.
///
/// The axis value is the one matching the axis (e.g. `height` for [`Self::Vertical`]).
/// The cross value is the other one.
#[inline]
pub const fn pack_size(self, axis_value: f64, cross_value: f64) -> Size {
match self {
Self::Horizontal => Size::new(axis_value, cross_value),
Self::Vertical => Size::new(cross_value, axis_value),
}
}
/// Create a new [`Vec2`] by arranging the given magnitudes.
///
/// The axis value is the one matching the axis (e.g. `y` for [`Self::Vertical`]).
/// The cross value is the other one.
#[inline]
pub const fn pack_vec2(self, axis_value: f64, cross_value: f64) -> Vec2 {
match self {
Self::Horizontal => Vec2::new(axis_value, cross_value),
Self::Vertical => Vec2::new(cross_value, axis_value),
}
}
/// Create a new `(x, y)` pair by arranging the given magnitudes.
///
/// The axis value is the one matching the axis (e.g. `y` for [`Self::Vertical`]).
/// The cross value is the other one.
#[inline]
pub const fn pack_xy(self, axis_value: f64, cross_value: f64) -> (f64, f64) {
match self {
Self::Horizontal => (axis_value, cross_value),
Self::Vertical => (cross_value, axis_value),
}
}
}