From 154f95d615ad4bac8fca866960b816b411f0c1bc Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Mon, 19 Aug 2024 11:35:31 -0500 Subject: [PATCH] Add convenient constructors for points (#464) Add methods to make a 2D/3D/4D point where all the components are the same. --- modeling-cmds/src/shared.rs | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index e95711e8..a0cf2c1d 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -259,6 +259,53 @@ pub struct Point4d { pub w: T, } +impl Point2d +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 Point3d +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 Point4d +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 for Point3d { fn from(v: euler::Vec3) -> Self { Self { x: v.x, y: v.y, z: v.z }