Skip to content

Commit

Permalink
Scalar operations on points (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers authored Oct 24, 2023
1 parent 733048c commit 2fbcbe7
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions kittycad/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,49 @@ impl Angle {
}
}

impl Add<f64> for Point2D {
type Output = Self;

fn add(self, rhs: f64) -> Self::Output {
Self {
x: self.x + rhs,
y: self.y + rhs,
}
}
}

impl Sub<f64> for Point2D {
type Output = Self;

fn sub(self, rhs: f64) -> Self::Output {
Self {
x: self.x - rhs,
y: self.y - rhs,
}
}
}

impl Mul<f64> for Point2D {
type Output = Self;

fn mul(self, rhs: f64) -> Self::Output {
Self {
x: self.x * rhs,
y: self.y * rhs,
}
}
}

impl Div<f64> for Point2D {
type Output = Self;

fn div(self, rhs: f64) -> Self::Output {
Self {
x: self.x / rhs,
y: self.y / rhs,
}
}
}
impl Add for Point2D {
type Output = Self;

Expand Down Expand Up @@ -134,6 +177,54 @@ impl Div for Point3D {
}
}

impl Add<f64> for Point3D {
type Output = Self;

fn add(self, rhs: f64) -> Self::Output {
Self {
x: self.x + rhs,
y: self.y + rhs,
z: self.z + rhs,
}
}
}

impl Sub<f64> for Point3D {
type Output = Self;

fn sub(self, rhs: f64) -> Self::Output {
Self {
x: self.x - rhs,
y: self.y - rhs,
z: self.z - rhs,
}
}
}

impl Mul<f64> for Point3D {
type Output = Self;

fn mul(self, rhs: f64) -> Self::Output {
Self {
x: self.x * rhs,
y: self.y * rhs,
z: self.z * rhs,
}
}
}

impl Div<f64> for Point3D {
type Output = Self;

fn div(self, rhs: f64) -> Self::Output {
Self {
x: self.x / rhs,
y: self.y / rhs,
z: self.z / rhs,
}
}
}

impl Point3D {
/// Add a Z component to a 2D point.
pub fn with_z(Point2D { x, y }: Point2D, z: f64) -> Self {
Expand Down

0 comments on commit 2fbcbe7

Please sign in to comment.