Skip to main content

geop_ops_fillet/
examples.rs

1//! The examples of rounding and bevelling edges, which an editor offers
2//! to load ([`set`]).
3
4use geop_core_editor::registry::ExampleSet;
5use geop_core_math::primitives::FrameAxis;
6use geop_core_program::program::Program;
7use geop_ops_extrude_revolve::{Extents, ExtrudeArgs, Output};
8use geop_ops_model::Combine;
9use geop_ops_model::datums::origin_plane;
10use geop_ops_model::sketch::{
11    Sketch, SketchPlane,
12    figures::{rectangle, solved},
13    whole_sketch,
14};
15use geop_ops_sketch::AddSketchArgs;
16
17use crate::FilletArgs;
18
19/// The examples of this crate, as an editor offers them.
20pub fn set() -> ExampleSet {
21    ExampleSet {
22        programs: vec![("rounded_box", rounded_box)],
23        workspaces: Vec::new(),
24    }
25}
26
27/// The plane of the origin normal to `normal`, as a plane to sketch on.
28fn on_origin(normal: FrameAxis) -> SketchPlane {
29    SketchPlane::Datum(origin_plane(normal))
30}
31
32/// A 2 x 1.5 x 1 box with every edge rounded by 0.2, at once: where three
33/// fillets meet, at each corner, the ball touching its three faces rounds
34/// it — the solid `fillet(round)`.
35pub fn rounded_box() -> Program {
36    let mut program = Program::new();
37    let mut outline = Sketch::new();
38    let lines = rectangle(&mut outline, [0.0, 0.0], 2.0, 1.5);
39    program.push(
40        "outline",
41        AddSketchArgs::on(on_origin(FrameAxis::Z), solved(outline)),
42    );
43    program.push(
44        "box",
45        ExtrudeArgs {
46            sketch: whole_sketch("outline"),
47            extent: Extents::blind(1.0),
48            output: Output::Solid(Combine::NewBody),
49            draft: 0.0,
50        },
51    );
52    let mut edges = Vec::new();
53    for line in &lines {
54        for cap in ["start", "end"] {
55            edges.push(format!("extrude(box,outline,{line},{cap})"));
56        }
57    }
58    for corner in 0..4 {
59        edges.push(format!("extrude(box,outline,p{corner})"));
60    }
61    program.push("round", FilletArgs::constant(edges, 0.2));
62    program
63}