Skip to content

Commit

Permalink
Add the rest of the sketch primitives
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed May 28, 2024
1 parent a108e03 commit e1de1e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/cadmium/src/isketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,36 @@ impl ISketch {
Ok(point_id)
}

pub(super) fn add_arc(&mut self, center: IDType, radius: f64, clockwise: bool, start_angle: f64, end_angle: f64) -> Result<IDType, anyhow::Error> {
let mut sketch = self.sketch.borrow_mut();

let center_point = if let PrimitiveCell::Point2(point) = sketch.get_primitive_by_id(center).unwrap() {
point
} else {
return Err(anyhow::anyhow!("Center point is not a point"));
};

let arc = PrimitiveCell::Arc(Rc::new(RefCell::new(isotope::primitives::arc::Arc::new(center_point.clone(), radius, clockwise, start_angle, end_angle))));

let point_id = sketch.add_primitive(arc)?;
Ok(point_id)
}

pub(super) fn add_circle(&mut self, center: IDType, radius: f64) -> Result<IDType, anyhow::Error> {
let mut sketch = self.sketch.borrow_mut();

let center_point = if let PrimitiveCell::Point2(point) = sketch.get_primitive_by_id(center).unwrap() {
point
} else {
return Err(anyhow::anyhow!("Center point is not a point"));
};

let circle = PrimitiveCell::Circle(Rc::new(RefCell::new(isotope::primitives::circle::Circle::new(center_point.clone(), radius))));

let point_id = sketch.add_primitive(circle)?;
Ok(point_id)
}

pub(super) fn add_line(&mut self, start: IDType, end: IDType) -> Result<IDType, anyhow::Error> {
let mut sketch = self.sketch.borrow_mut();

Expand Down
13 changes: 12 additions & 1 deletion packages/cadmium/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ define_steps! {
// },
"sketches" => ISketch {
Point {
point: Point2
point: Point2,
},
Arc {
center: IDType,
radius: f64,
clockwise: bool,
start_angle: f64,
end_angle: f64,
},
Circle {
center: IDType,
radius: f64,
},
Line {
start: IDType,
Expand Down

0 comments on commit e1de1e0

Please sign in to comment.