-
-
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 #1140 from hannobraun/ready/partial
Make partial object API more flexible
- Loading branch information
Showing
5 changed files
with
192 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
objects::{GlobalCurve, GlobalEdge, Surface, SurfaceVertex, Vertex}, | ||
stores::{Handle, Stores}, | ||
}; | ||
|
||
use super::HasPartialForm; | ||
|
||
/// Either a partial object or a full one | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] | ||
pub enum MaybePartial<T: HasPartialForm> { | ||
/// A full object | ||
Full(T), | ||
|
||
/// A partial object | ||
Partial(T::PartialForm), | ||
} | ||
|
||
impl<T: HasPartialForm> MaybePartial<T> { | ||
/// Return the full object, either directly or by building it | ||
pub fn into_full(self, stores: &Stores) -> T { | ||
match self { | ||
Self::Partial(partial) => T::from_partial(partial, stores), | ||
Self::Full(full) => full, | ||
} | ||
} | ||
|
||
/// Return the partial object, either directly or via conversion | ||
pub fn into_partial(self) -> T::PartialForm { | ||
match self { | ||
Self::Partial(partial) => partial, | ||
Self::Full(full) => full.into(), | ||
} | ||
} | ||
} | ||
|
||
impl MaybePartial<GlobalEdge> { | ||
/// Access the curve | ||
pub fn curve(&self) -> Option<&Handle<GlobalCurve>> { | ||
match self { | ||
Self::Full(full) => Some(full.curve()), | ||
Self::Partial(partial) => partial.curve.as_ref(), | ||
} | ||
} | ||
} | ||
|
||
impl MaybePartial<SurfaceVertex> { | ||
/// Access the position | ||
pub fn position(&self) -> Option<Point<2>> { | ||
match self { | ||
Self::Full(full) => Some(full.position()), | ||
Self::Partial(partial) => partial.position, | ||
} | ||
} | ||
|
||
/// Access the surface | ||
pub fn surface(&self) -> Option<&Surface> { | ||
match self { | ||
Self::Full(full) => Some(full.surface()), | ||
Self::Partial(partial) => partial.surface.as_ref(), | ||
} | ||
} | ||
} | ||
|
||
impl MaybePartial<Vertex> { | ||
/// Access the surface form | ||
pub fn surface_form(&self) -> Option<MaybePartial<SurfaceVertex>> { | ||
match self { | ||
Self::Full(full) => Some((*full.surface_form()).into()), | ||
Self::Partial(partial) => partial.surface_form.clone(), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.