Skip to content

Commit

Permalink
Merge pull request #1520 from hannobraun/builder
Browse files Browse the repository at this point in the history
Add `FaceBuilder::infer_curves`
  • Loading branch information
hannobraun authored Jan 18, 2023
2 parents 9021f6f + a28e57a commit ceea642
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
1 change: 0 additions & 1 deletion crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.iter_mut()
.zip(other.read().vertices.iter().rev())
{
this.write().position = other.read().position;
this.write()
.surface_form
.write()
Expand Down
58 changes: 52 additions & 6 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::collections::VecDeque;
use fj_interop::ext::ArrayExt;

use crate::{
geometry::path::SurfacePath,
objects::{Cycle, HalfEdge, Surface},
partial::{Partial, PartialCycle, PartialFace},
partial::{MaybeSurfacePath, Partial, PartialCycle, PartialFace},
};

use super::{CycleBuilder, HalfEdgeBuilder, ObjectArgument, SurfaceBuilder};
Expand Down Expand Up @@ -52,6 +53,9 @@ pub trait FaceBuilder {
/// otherwise. This is a temporary limitation, not a fundamental one. It
/// could be overcome with some more work.
fn update_surface_as_plane(&mut self) -> Partial<Surface>;

/// Infer any undefined curves in the face
fn infer_curves(&mut self);
}

impl FaceBuilder for PartialFace {
Expand Down Expand Up @@ -105,11 +109,9 @@ impl FaceBuilder for PartialFace {

fn update_surface_as_plane(&mut self) -> Partial<Surface> {
let mut exterior = self.exterior.write();
let mut vertices = {
exterior.half_edges.iter().map(|half_edge| {
half_edge.read().back().read().surface_form.clone()
})
};
let mut vertices = exterior.half_edges.iter().map(|half_edge| {
half_edge.read().back().read().surface_form.clone()
});

let vertices = {
let array = [
Expand Down Expand Up @@ -143,4 +145,48 @@ impl FaceBuilder for PartialFace {

exterior.surface.clone()
}

fn infer_curves(&mut self) {
for half_edge in &mut self.exterior.write().half_edges {
let mut half_edge = half_edge.write();

let mut curve = half_edge.curve();
let mut curve = curve.write();

if let Some(path) = &mut curve.path {
match path {
MaybeSurfacePath::Defined(_) => {
// Path is already defined. Nothing to infer.
}
MaybeSurfacePath::UndefinedCircle => todo!(
"Inferring undefined circles is not supported yet"
),
MaybeSurfacePath::UndefinedLine => {
let points_surface =
half_edge.vertices.each_ref_ext().map(|vertex| {
vertex
.read()
.surface_form
.read()
.position
.expect(
"Can't infer curve without surface points",
)
});
let (line, points_curve) =
SurfacePath::line_from_points(points_surface);

*path = MaybeSurfacePath::Defined(line);
for (vertex, point) in half_edge
.vertices
.each_mut_ext()
.zip_ext(points_curve)
{
vertex.write().position = Some(point);
}
}
}
}
}
}
}

0 comments on commit ceea642

Please sign in to comment.