Skip to content

Commit

Permalink
Merge pull request #1851 from hannobraun/cuboid
Browse files Browse the repository at this point in the history
Clean up `cuboid` example
  • Loading branch information
hannobraun authored May 30, 2023
2 parents 2d1385b + 08f522a commit 41774c2
Showing 1 changed file with 13 additions and 37 deletions.
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

0 comments on commit 41774c2

Please sign in to comment.