Skip to content

Commit

Permalink
Add convenient constructors for points
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 committed Aug 19, 2024
1 parent 63ce8be commit 455c937
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 }
}

Check warning on line 269 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L267-L269

Added lines #L267 - L269 were not covered by tests
}
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,
}
}

Check warning on line 282 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L276-L282

Added lines #L276 - L282 were not covered by tests
}
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,
}
}

Check warning on line 296 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L289-L296

Added lines #L289 - L296 were not covered by tests
/// 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,
}
}

Check warning on line 306 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L299-L306

Added lines #L299 - L306 were not covered by tests
}

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 455c937

Please sign in to comment.