Merge pull request #2143 from hannobraun/models

Clean up code of models
This commit is contained in:
Hanno Braun 2023-12-15 13:47:17 +01:00 committed by GitHub
commit d882a63b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 69 deletions

1
Cargo.lock generated
View File

@ -2989,6 +2989,7 @@ dependencies = [
name = "split"
version = "0.1.0"
dependencies = [
"cuboid",
"fj",
]

View File

@ -19,22 +19,22 @@ pub fn model(
) -> Handle<Solid> {
let [x, y, z] = size.into().components;
let sketch = Sketch::empty().add_region(
Region::polygon(
[
[-x / 2., -y / 2.],
[x / 2., -y / 2.],
[x / 2., y / 2.],
[-x / 2., y / 2.],
],
services,
)
.insert(services),
);
let bottom_surface = services.objects.surfaces.xy_plane();
let sweep_path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]);
let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]);
sketch
.sweep_sketch(surface, path, services)
Sketch::empty()
.add_region(
Region::polygon(
[
[-x / 2., -y / 2.],
[x / 2., -y / 2.],
[x / 2., y / 2.],
[-x / 2., y / 2.],
],
services,
)
.insert(services),
)
.sweep_sketch(bottom_surface, sweep_path, services)
.insert(services)
}

View File

@ -22,7 +22,7 @@ pub fn model(
let cuboid = cuboid::model([size * 2., size, size], services);
cuboid
.update_shell(cuboid.shells().first(), |shell| {
.update_shell(cuboid.shells().only(), |shell| {
let bottom_face = shell.faces().first();
let offset = size / 2.;
let depth = size / 2.;

View File

@ -20,17 +20,21 @@ pub fn model(
height: f64,
services: &mut Services,
) -> Handle<Solid> {
let sketch = Sketch::empty().add_region(
Region::circle(Point::origin(), outer, services)
.add_interiors([Cycle::circle(Point::origin(), inner, services)
let bottom_surface = services.objects.surfaces.xy_plane();
let sweep_path = Vector::from([0., 0., height]);
Sketch::empty()
.add_region(
Region::circle(Point::origin(), outer, services)
.add_interiors([Cycle::circle(
Point::origin(),
inner,
services,
)
.reverse(services)
.insert(services)])
.insert(services),
);
let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., height]);
sketch
.sweep_sketch(surface, path, services)
.insert(services),
)
.sweep_sketch(bottom_surface, sweep_path, services)
.insert(services)
}

View File

@ -3,5 +3,9 @@ name = "split"
version = "0.1.0"
edition = "2021"
[dependencies.fj]
path = "../../crates/fj"
[dependencies.cuboid]
path = "../cuboid"

View File

@ -1,17 +1,11 @@
use fj::{
core::{
objects::{Region, Sketch, Solid},
operations::{
build::{BuildRegion, BuildSketch},
insert::Insert,
split::SplitFace,
sweep::{SweepFaceOfShell, SweepSketch},
update::{UpdateSketch, UpdateSolid},
},
services::Services,
storage::Handle,
use fj::core::{
objects::Solid,
operations::{
insert::Insert, split::SplitFace, sweep::SweepFaceOfShell,
update::UpdateSolid,
},
math::Vector,
services::Services,
storage::Handle,
};
pub fn model(
@ -19,25 +13,10 @@ pub fn model(
split_pos: f64,
services: &mut Services,
) -> Handle<Solid> {
let sketch = Sketch::empty().add_region(
Region::polygon(
[
[-size / 2., -size / 2.],
[size / 2., -size / 2.],
[size / 2., size / 2.],
[-size / 2., size / 2.],
],
services,
)
.insert(services),
);
let cuboid = cuboid::model([size, size, size], services);
let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., size]);
let solid = sketch.sweep_sketch(surface, path, services);
solid
.update_shell(solid.shells().only(), |shell| {
cuboid
.update_shell(cuboid.shells().only(), |shell| {
let face = shell.faces().first();
let cycle = face.region().exterior();

View File

@ -43,17 +43,17 @@ pub fn model(
inner_points.push([x / 2., y / 2.]);
}
let sketch = Sketch::empty().add_region(
Region::polygon(outer_points, services)
.add_interiors([Cycle::polygon(inner_points, services)
.reverse(services)
.insert(services)])
.insert(services),
);
let bottom_surface = services.objects.surfaces.xy_plane();
let sweep_path = Vector::from([0., 0., h]);
let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., h]);
sketch
.sweep_sketch(surface, path, services)
Sketch::empty()
.add_region(
Region::polygon(outer_points, services)
.add_interiors([Cycle::polygon(inner_points, services)
.reverse(services)
.insert(services)])
.insert(services),
)
.sweep_sketch(bottom_surface, sweep_path, services)
.insert(services)
}