Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenient constructors for points #464

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
Loading