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 code of models #2143

Merged
merged 15 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion models/holes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand Down
24 changes: 14 additions & 10 deletions models/spacer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions models/split/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ name = "split"
version = "0.1.0"
edition = "2021"


[dependencies.fj]
path = "../../crates/fj"

[dependencies.cuboid]
path = "../cuboid"
41 changes: 10 additions & 31 deletions models/split/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
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(
size: f64,
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();

Expand Down
24 changes: 12 additions & 12 deletions models/star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., h]);
sketch
.sweep_sketch(surface, path, services)
let bottom_surface = services.objects.surfaces.xy_plane();
let sweep_path = Vector::from([0., 0., h]);

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)
}