-
-
Notifications
You must be signed in to change notification settings - Fork 119
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 #1879 from hannobraun/operations
Expand and update operations API
- Loading branch information
Showing
10 changed files
with
98 additions
and
45 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
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
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
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
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ pub mod cycle; | |
pub mod edge; | ||
pub mod face; | ||
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,55 @@ | ||
use fj_math::{Point, Scalar}; | ||
|
||
use crate::{ | ||
geometry::region::Region, | ||
objects::{Cycle, Sketch}, | ||
operations::{BuildCycle, Insert}, | ||
services::Services, | ||
}; | ||
|
||
/// Update a [`Sketch`] | ||
pub trait UpdateSketch { | ||
/// Add a region to the sketch | ||
fn add_region(&self, region: 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: 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); | ||
self.add_region(Region::new(exterior, [], None)) | ||
} | ||
|
||
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); | ||
self.add_region(Region::new(exterior, [], None)) | ||
} | ||
} |
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