1use cadrum::{DVec3, Error, Solid};
7
8fn rounded_cube(size: f64) -> Result<Solid, Error> {
9 let cube = Solid::cube(size, size, size).translate(-DVec3::ONE * (size / 2.0));
10 let radius = size * 0.2;
11 cube.fillet_edges(radius, cube.iter_edge())
12}
13
14fn soft_top_cube(size: f64) -> Result<Solid, Error> {
15 let cube = Solid::cube(size, size, size).translate(-DVec3::ONE * (size / 2.0));
16 let radius = size * 0.2;
17 let top_edges = cube
19 .iter_edge()
20 .filter(|e| [e.start_point(), e.end_point()].iter().all(|p| (p.z - size / 2.0).abs() < 1e-6));
21 cube.fillet_edges(radius, top_edges)
22}
23
24fn coin(radius: f64, height: f64) -> Result<Solid, Error> {
25 let cyl = Solid::cylinder(radius, DVec3::Z, height);
26 let radius = height * 0.3;
27 let top_circle = cyl
29 .iter_edge()
30 .filter(|e| [e.start_point(), e.end_point()].iter().all(|p| (p.z - height).abs() < 1e-6));
31 cyl.fillet_edges(radius, top_circle)
32}
33
34fn main() -> Result<(), Error> {
35 let example_name = std::path::Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36
37 let result = [
38 rounded_cube(8.0)?.color("#d0a878"),
39 soft_top_cube(8.0)?.color("#6fbf73").translate(DVec3::X * 12.0),
40 coin(4.0, 2.0)?.color("#0052ff").translate(DVec3::X * 24.0),
41 ];
42
43 let mut f = std::fs::File::create(format!("{example_name}.step")).expect("failed to create STEP file");
44 cadrum::write_step(&result, &mut f).expect("failed to write STEP");
45
46 let mut f = std::fs::File::create(format!("{example_name}.svg")).expect("failed to create SVG file");
47 cadrum::mesh(&result, 0.2).and_then(|m| m.write_svg(DVec3::new(1.0, 1.0, 2.0), DVec3::Z, true, true, &mut f)).expect("failed to write SVG");
48
49 println!("wrote {example_name}.step / {example_name}.svg");
50 Ok(())
51}