Skip to content

Commit

Permalink
Convert between 2D points and 2-arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Oct 24, 2023
1 parent 2fbcbe7 commit a694d5c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions kittycad/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ impl Angle {
}
}

impl From<[f64; 2]> for Point2D {
fn from([x, y]: [f64; 2]) -> Self {
Self { x, y }
}
}

impl From<&[f64; 2]> for Point2D {
fn from(p: &[f64; 2]) -> Self {
let [x, y] = *p;
Self { x, y }
}
}

impl From<Point2D> for [f64; 2] {
fn from(Point2D { x, y }: Point2D) -> Self {
[x, y]
}
}

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

Expand Down Expand Up @@ -129,6 +148,24 @@ impl Div for Point2D {
}
}

impl From<[f64; 3]> for Point3D {
fn from([x, y, z]: [f64; 3]) -> Self {
Self { x, y, z }
}
}

impl From<&[f64; 3]> for Point3D {
fn from(p: &[f64; 3]) -> Self {
let [x, y, z] = *p;
Self { x, y, z }
}
}

impl From<Point3D> for [f64; 3] {
fn from(Point3D { x, y, z }: Point3D) -> Self {
[x, y, z]
}
}
impl Add for Point3D {
type Output = Self;

Expand Down

0 comments on commit a694d5c

Please sign in to comment.