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

Expand BuildSketch #2366

Merged
merged 2 commits into from
May 27, 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
42 changes: 41 additions & 1 deletion crates/fj-core/src/operations/build/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use crate::topology::{Sketch, Topology};
use fj_math::{Point, Scalar};

use crate::{
operations::update::UpdateSketch,
topology::{Region, Sketch, Topology},
Core,
};

use super::BuildRegion;

/// Build a [`Sketch`]
///
Expand All @@ -10,6 +18,38 @@ pub trait BuildSketch {
fn empty(topology: &Topology) -> Sketch {
Sketch::new(topology.surfaces.space_2d(), [])
}

/// Build a circle
fn circle(
center: impl Into<Point<2>>,
radius: impl Into<Scalar>,
core: &mut Core,
) -> Sketch {
let sketch = Sketch::empty(&core.layers.topology);
sketch.add_regions(
[Region::circle(
center,
radius,
sketch.surface().clone(),
core,
)],
core,
)
}

/// Build a polygon
fn polygon<P, Ps>(points: Ps, core: &mut Core) -> Sketch
where
P: Into<Point<2>>,
Ps: IntoIterator<Item = P>,
Ps::IntoIter: Clone + ExactSizeIterator,
{
let sketch = Sketch::empty(&core.layers.topology);
sketch.add_regions(
[Region::polygon(points, sketch.surface().clone(), core)],
core,
)
}
}

impl BuildSketch for Sketch {}