Skip to content

Commit

Permalink
Simplify PartialHalfEdge field
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Oct 28, 2022
1 parent 2648fc8 commit a0fdfd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
32 changes: 13 additions & 19 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fj_interop::ext::ArrayExt;
use fj_math::Transform;

use crate::{
objects::{Curve, Objects},
objects::Objects,
partial::{MaybePartial, PartialGlobalEdge, PartialHalfEdge},
validate::ValidationError,
};
Expand All @@ -19,34 +19,28 @@ impl TransformObject for PartialHalfEdge {
.surface
.map(|surface| surface.transform(transform, objects))
.transpose()?;
let curve = self
let curve: MaybePartial<_> = self
.curve
.clone()
.map(|curve| -> Result<_, ValidationError> {
Ok(curve
.into_partial()
.transform(transform, objects)?
.with_surface(surface.clone())
.into())
})
.transpose()?;
.into_partial()
.transform(transform, objects)?
.with_surface(surface.clone())
.into();
let vertices = self.vertices.clone().try_map_ext(
|vertex| -> Result<_, ValidationError> {
Ok(vertex
.into_partial()
.transform(transform, objects)?
.with_curve(curve.clone())
.with_curve(Some(curve.clone()))
.into())
},
)?;
let global_form =
self.global_form
.into_partial()
.transform(transform, objects)?
.with_curve(curve.as_ref().and_then(
|curve: &MaybePartial<Curve>| curve.global_form(),
))
.into();
let global_form = self
.global_form
.into_partial()
.transform(transform, objects)?
.with_curve(curve.global_form())
.into();

Ok(Self {
surface,
Expand Down
13 changes: 6 additions & 7 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PartialHalfEdge {
pub surface: Option<Handle<Surface>>,

/// The curve that the [`HalfEdge`] is defined in
pub curve: Option<MaybePartial<Curve>>,
pub curve: MaybePartial<Curve>,

/// The vertices that bound this [`HalfEdge`] in the [`Curve`]
pub vertices: [MaybePartial<Vertex>; 2],
Expand All @@ -36,7 +36,7 @@ impl PartialHalfEdge {
///
/// If a global curve is available through both, the curve is preferred.
pub fn extract_global_curve(&self) -> Option<Handle<GlobalCurve>> {
let global_curve_from_curve = || self.curve.as_ref()?.global_form();
let global_curve_from_curve = || self.curve.global_form();
let global_curve_from_global_form =
|| self.global_form.curve().cloned();

Expand All @@ -62,7 +62,7 @@ impl PartialHalfEdge {
curve: Option<impl Into<MaybePartial<Curve>>>,
) -> Self {
if let Some(curve) = curve {
self.curve = Some(curve.into());
self.curve = curve.into();
}
self
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl PartialHalfEdge {
.into()
});

self.curve = Some(curve.into());
self.curve = curve.into();
self.vertices = [back, front];

Ok(self)
Expand Down Expand Up @@ -260,7 +260,7 @@ impl PartialHalfEdge {
})
};

self.curve = Some(curve.into());
self.curve = curve.into();
self.vertices = [back, front];

self
Expand All @@ -274,7 +274,6 @@ impl PartialHalfEdge {
let surface = self.surface;
let curve = self
.curve
.expect("Can't build `HalfEdge` without curve")
.update_partial(|curve| curve.with_surface(surface))
.into_full(objects)?;
let vertices = self.vertices.try_map_ext(|vertex| {
Expand Down Expand Up @@ -303,7 +302,7 @@ impl From<&HalfEdge> for PartialHalfEdge {

Self {
surface: Some(half_edge.curve().surface().clone()),
curve: Some(half_edge.curve().clone().into()),
curve: half_edge.curve().clone().into(),
vertices: [back_vertex, front_vertex],
global_form: half_edge.global_form().clone().into(),
}
Expand Down

0 comments on commit a0fdfd2

Please sign in to comment.