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" name = "split"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cuboid",
"fj", "fj",
] ]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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