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

Replace CycleBuilder with PartialCycle #1169

Merged
merged 18 commits into from
Oct 5, 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
127 changes: 0 additions & 127 deletions crates/fj-kernel/src/builder/cycle.rs

This file was deleted.

11 changes: 7 additions & 4 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use fj_math::Point;

use crate::{
objects::{Cycle, Face, Surface},
partial::HasPartial,
stores::{Handle, Stores},
};

Expand Down Expand Up @@ -32,10 +33,11 @@ impl<'a> FaceBuilder<'a> {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.exterior = Some(
Cycle::builder(self.stores, self.surface.clone())
Cycle::partial()
.with_surface(self.surface.clone())
.with_poly_chain_from_points(points)
.close_with_line_segment()
.build(),
.build(self.stores),
);
self
}
Expand All @@ -46,10 +48,11 @@ impl<'a> FaceBuilder<'a> {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.interiors.push(
Cycle::builder(self.stores, self.surface.clone())
Cycle::partial()
.with_surface(self.surface.clone())
.with_poly_chain_from_points(points)
.close_with_line_segment()
.build(),
.build(self.stores),
);
self
}
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! API for building objects

mod cycle;
mod face;
mod shell;
mod sketch;
mod solid;

pub use self::{
cycle::CycleBuilder, face::FaceBuilder, shell::ShellBuilder,
sketch::SketchBuilder, solid::SolidBuilder,
face::FaceBuilder, shell::ShellBuilder, sketch::SketchBuilder,
solid::SolidBuilder,
};
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ impl<'a> ShellBuilder<'a> {
.zip(sides_down)
.zip(surfaces)
.map(|((((bottom, side_up), top), side_down), surface)| {
let cycle = Cycle::builder(self.stores, surface)
let cycle = Cycle::partial()
.with_surface(surface)
.with_half_edges([bottom, side_up, top, side_down])
.build();
.build(self.stores);

Face::from_exterior(cycle)
});
Expand Down
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ mod tests {
let stores = Stores::new();

let surface = stores.surfaces.insert(Surface::xy_plane());
let object = Cycle::builder(&stores, surface)
let object = Cycle::partial()
.with_surface(surface)
.with_poly_chain_from_points([[0., 0.], [1., 0.], [0., 1.]])
.close_with_line_segment()
.build();
.build(&stores);

assert_eq!(3, object.curve_iter().count());
assert_eq!(1, object.cycle_iter().count());
Expand Down
15 changes: 1 addition & 14 deletions crates/fj-kernel/src/objects/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use fj_math::{Scalar, Winding};
use pretty_assertions::assert_eq;

use crate::{
builder::CycleBuilder,
path::SurfacePath,
stores::{Handle, Stores},
};
use crate::{path::SurfacePath, stores::Handle};

use super::{HalfEdge, Surface};

Expand All @@ -17,15 +13,6 @@ pub struct Cycle {
}

impl Cycle {
/// Build a `Cycle` using [`CycleBuilder`]
pub fn builder(stores: &Stores, surface: Handle<Surface>) -> CycleBuilder {
CycleBuilder {
stores,
surface,
half_edges: Vec::new(),
}
}

/// Create a new cycle
///
/// # Panics
Expand Down
15 changes: 14 additions & 1 deletion crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use fj_math::Point;

use crate::{
objects::{Curve, GlobalCurve, GlobalEdge, Surface, SurfaceVertex, Vertex},
objects::{
Curve, GlobalCurve, GlobalEdge, HalfEdge, Surface, SurfaceVertex,
Vertex,
},
stores::{Handle, Stores},
};

Expand Down Expand Up @@ -101,6 +104,16 @@ impl MaybePartial<GlobalEdge> {
}
}

impl MaybePartial<HalfEdge> {
/// Access the vertices
pub fn vertices(&self) -> Option<[MaybePartial<Vertex>; 2]> {
match self {
Self::Full(full) => Some(full.vertices().clone().map(Into::into)),
Self::Partial(partial) => partial.vertices.clone(),
}
}
}

impl MaybePartial<SurfaceVertex> {
/// Access the position
pub fn position(&self) -> Option<Point<2>> {
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/partial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub use self::{
maybe_partial::MaybePartial,
objects::{
curve::PartialCurve,
cycle::PartialCycle,
edge::{PartialGlobalEdge, PartialHalfEdge},
vertex::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex},
},
Expand Down
Loading