-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1884 from hannobraun/operations
Improve `Sketch` operations
- Loading branch information
Showing
5 changed files
with
49 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod cycle; | ||
pub mod edge; | ||
pub mod face; | ||
pub mod region; | ||
pub mod shell; | ||
pub mod sketch; | ||
pub mod solid; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use fj_math::{Point, Scalar}; | ||
|
||
use crate::{ | ||
objects::{Cycle, Region}, | ||
operations::{BuildCycle, Insert}, | ||
services::Services, | ||
}; | ||
|
||
/// Build a [`Region`] | ||
pub trait BuildRegion { | ||
/// Build a circle | ||
fn circle( | ||
center: impl Into<Point<2>>, | ||
radius: impl Into<Scalar>, | ||
services: &mut Services, | ||
) -> Region { | ||
let exterior = Cycle::circle(center, radius, services).insert(services); | ||
Region::new(exterior, [], None) | ||
} | ||
|
||
/// Build a polygon | ||
fn polygon<P, Ps>(points: Ps, services: &mut Services) -> Region | ||
where | ||
P: Into<Point<2>>, | ||
Ps: IntoIterator<Item = P>, | ||
Ps::IntoIter: Clone + ExactSizeIterator, | ||
{ | ||
let exterior = Cycle::polygon(points, services).insert(services); | ||
Region::new(exterior, [], None) | ||
} | ||
} | ||
|
||
impl BuildRegion for Region {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,16 @@ | ||
use fj_math::{Point, Scalar}; | ||
|
||
use crate::{ | ||
objects::{Cycle, Region, Sketch}, | ||
operations::{BuildCycle, Insert}, | ||
services::Services, | ||
objects::{Region, Sketch}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Update a [`Sketch`] | ||
pub trait UpdateSketch { | ||
/// Add a region to the sketch | ||
fn add_region(&self, region: Handle<Region>) -> Self; | ||
|
||
/// Add a circle to the sketch | ||
fn add_circle( | ||
&self, | ||
center: impl Into<Point<2>>, | ||
radius: impl Into<Scalar>, | ||
services: &mut Services, | ||
) -> Self; | ||
|
||
/// Add a polygon to the sketch | ||
fn add_polygon<P, Ps>(&self, points: Ps, services: &mut Services) -> Self | ||
where | ||
P: Into<Point<2>>, | ||
Ps: IntoIterator<Item = P>, | ||
Ps::IntoIter: Clone + ExactSizeIterator; | ||
} | ||
|
||
impl UpdateSketch for Sketch { | ||
fn add_region(&self, region: Handle<Region>) -> Self { | ||
Sketch::new(self.regions().cloned().chain([region])) | ||
} | ||
|
||
fn add_circle( | ||
&self, | ||
center: impl Into<Point<2>>, | ||
radius: impl Into<Scalar>, | ||
services: &mut Services, | ||
) -> Self { | ||
let exterior = Cycle::circle(center, radius, services).insert(services); | ||
let region = Region::new(exterior, [], None).insert(services); | ||
self.add_region(region) | ||
} | ||
|
||
fn add_polygon<P, Ps>(&self, points: Ps, services: &mut Services) -> Self | ||
where | ||
P: Into<Point<2>>, | ||
Ps: IntoIterator<Item = P>, | ||
Ps::IntoIter: Clone + ExactSizeIterator, | ||
{ | ||
let exterior = Cycle::polygon(points, services).insert(services); | ||
let region = Region::new(exterior, [], None).insert(services); | ||
self.add_region(region) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters