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

Clean up MaybePartial transform code #1361

Merged
merged 7 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 2 additions & 6 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_math::Transform;

use crate::{
objects::Objects,
partial::{MaybePartial, PartialGlobalEdge, PartialHalfEdge},
partial::{PartialGlobalEdge, PartialHalfEdge},
validate::ValidationError,
};

Expand All @@ -15,11 +15,7 @@ impl TransformObject for PartialHalfEdge {
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError> {
let curve: MaybePartial<_> = self
.curve
.into_partial()
.transform(transform, objects)?
.into();
let curve = self.curve.transform(transform, objects)?;
let vertices = self.vertices.try_map_ext(
|vertex| -> Result<_, ValidationError> {
let mut vertex =
Expand Down
16 changes: 10 additions & 6 deletions crates/fj-kernel/src/algorithms/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ where
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError> {
match self {
let transformed = match self {
Self::Full(full) => {
Ok(Self::Full(full.transform(transform, objects)?))
full.to_partial().transform(transform, objects)?
}
Self::Partial(partial) => {
Ok(Self::Partial(partial.transform(transform, objects)?))
}
}
Self::Partial(partial) => partial.transform(transform, objects)?,
};

// Transforming a `MaybePartial` *always* results in a partial object.
// This provides the most flexibility to the caller, who might want to
// use the transformed partial object for merging or whatever else,
// before building it themselves.
Ok(Self::Partial(transformed))
}
}
10 changes: 10 additions & 0 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ impl MaybePartial<GlobalEdge> {
}
}

impl MaybePartial<GlobalVertex> {
/// Access the position
pub fn position(&self) -> Option<Point<3>> {
match self {
Self::Full(full) => Some(full.position()),
Self::Partial(partial) => partial.position,
}
}
}

impl MaybePartial<HalfEdge> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<Curve> {
Expand Down
18 changes: 10 additions & 8 deletions crates/fj-kernel/src/partial/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct PartialSurfaceVertex {
impl PartialSurfaceVertex {
/// Build a full [`SurfaceVertex`] from the partial surface vertex
pub fn build(
self,
mut self,
objects: &Objects,
) -> Result<SurfaceVertex, ValidationError> {
let position = self
Expand All @@ -112,13 +112,15 @@ impl PartialSurfaceVertex {
.surface
.expect("Can't build `SurfaceVertex` without `Surface`");

let global_form = self
.global_form
.merge_with(PartialGlobalVertex::from_surface_and_position(
&surface.geometry(),
position,
))
.into_full(objects)?;
if self.global_form.position().is_none() {
self.global_form = self.global_form.merge_with(
PartialGlobalVertex::from_surface_and_position(
&surface.geometry(),
position,
),
)
}
let global_form = self.global_form.into_full(objects)?;

Ok(SurfaceVertex::new(position, surface, global_form))
}
Expand Down