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 cuboid example #1851

Merged
merged 2 commits into from
May 30, 2023
Merged
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
50 changes: 13 additions & 37 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
use fj_kernel::{
algorithms::sweep::Sweep,
geometry::region::Region,
objects::{Cycle, HalfEdge, Sketch, Solid},
operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle},
objects::{Sketch, Solid},
operations::{BuildSketch, Insert},
services::Services,
storage::Handle,
};
use fj_math::{Point, Vector};
use itertools::Itertools;
use fj_math::Vector;

pub fn cuboid(x: f64, y: f64, z: f64) -> Handle<Solid> {
let mut services = Services::new();

let sketch = {
let exterior = {
#[rustfmt::skip]
let rectangle = [
[-x / 2., -y / 2.],
[ x / 2., -y / 2.],
[ x / 2., y / 2.],
[-x / 2., y / 2.],
];

let mut cycle = Cycle::empty();

let segments = rectangle
.into_iter()
.map(Point::from)
.circular_tuple_windows();

for (start, end) in segments {
let half_edge =
HalfEdge::line_segment([start, end], None, &mut services)
.insert(&mut services);

cycle = cycle.add_half_edges([half_edge]);
}

cycle.insert(&mut services)
};

let region = Region::new(exterior, Vec::new(), None);

Sketch::new([region]).insert(&mut services)
};
let sketch = Sketch::polygon(
[
[-x / 2., -y / 2.],
[x / 2., -y / 2.],
[x / 2., y / 2.],
[-x / 2., y / 2.],
],
&mut services,
)
.insert(&mut services);

let surface = services.objects.surfaces.xy_plane();

Expand Down