Skip to content

Commit

Permalink
Use BuildCycle to simplify cuboid
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed May 30, 2023
1 parent 2d1385b commit 0ea99f8
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
use fj_kernel::{
algorithms::sweep::Sweep,
geometry::region::Region,
objects::{Cycle, HalfEdge, Sketch, Solid},
operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle},
objects::{Cycle, Sketch, Solid},
operations::{BuildCycle, 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 = [
let exterior = Cycle::polygon(
[
[-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)
};
[x / 2., -y / 2.],
[x / 2., y / 2.],
[-x / 2., y / 2.],
],
&mut services,
)
.insert(&mut services);

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

Expand Down

0 comments on commit 0ea99f8

Please sign in to comment.