Skip to content

Commit

Permalink
Add convenient constructors for points (#464)
Browse files Browse the repository at this point in the history
Add methods to make a 2D/3D/4D point where all the components are the same.
  • Loading branch information
adamchalmers authored Aug 19, 2024
1 parent 63ce8be commit 154f95d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,53 @@ pub struct Point4d<T = f32> {
pub w: T,
}

impl<T> Point2d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self { x: value, y: value }
}
}
impl<T> Point3d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self {
x: value,
y: value,
z: value,
}
}
}
impl<T> Point4d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self {
x: value,
y: value,
z: value,
w: value,
}
}
/// Make a point where the X, Y and Z components have the same value,
/// but the W component has a different one.
pub fn uniform_3d(xyz: T, w: T) -> Self {
Self {
x: xyz,
y: xyz,
z: xyz,
w,
}
}
}

impl From<euler::Vec3> for Point3d<f32> {
fn from(v: euler::Vec3) -> Self {
Self { x: v.x, y: v.y, z: v.z }
Expand Down

0 comments on commit 154f95d

Please sign in to comment.