1use cadrum::{BSplineEnd, DVec3, Edge, Error, Solid};
9
10fn build_box() -> Result<Solid, Error> {
12 let profile = Edge::polygon(&[
13 DVec3::new(0.0, 0.0, 0.0),
14 DVec3::new(5.0, 0.0, 0.0),
15 DVec3::new(5.0, 5.0, 0.0),
16 DVec3::new(0.0, 5.0, 0.0),
17 ])?;
18 Solid::extrude(&profile, DVec3::Z * 8.0)
19}
20
21fn build_oblique_cylinder() -> Result<Solid, Error> {
23 let profile = [Edge::circle(3.0, DVec3::Z)?];
24 Solid::extrude(&profile, DVec3::new(-4.0, -6.0, 8.0))
25}
26
27fn build_l_beam() -> Result<Solid, Error> {
29 let profile = Edge::polygon(&[
30 DVec3::new(0.0, 0.0, 0.0),
31 DVec3::new(4.0, 0.0, 0.0),
32 DVec3::new(4.0, 1.0, 0.0),
33 DVec3::new(1.0, 1.0, 0.0),
34 DVec3::new(1.0, 3.0, 0.0),
35 DVec3::new(0.0, 3.0, 0.0),
36 ])?;
37 Solid::extrude(&profile, DVec3::Z * 12.0)
38}
39
40fn build_heart() -> Result<Solid, Error> {
42 let profile = [Edge::bspline(
43 &[
44 DVec3::new(0.0, -4.0, 0.0), DVec3::new(2.0, -1.5, 0.0),
46 DVec3::new(4.0, 1.5, 0.0),
47 DVec3::new(2.5, 3.5, 0.0), DVec3::new(0.0, 2.0, 0.0), DVec3::new(-2.5, 3.5, 0.0), DVec3::new(-4.0, 1.5, 0.0),
51 DVec3::new(-2.0, -1.5, 0.0),
52 ],
53 BSplineEnd::Periodic,
54 )?];
55 Solid::extrude(&profile, DVec3::Z * 7.0)
56}
57
58fn main() -> Result<(), Error> {
59 let example_name = std::path::Path::new(file!()).file_stem().unwrap().to_str().unwrap();
60
61 let box_solid = build_box()?.color("#b0d4f1");
62 let oblique = build_oblique_cylinder()?.color("#f1c8b0").translate(DVec3::X * 10.0);
63 let l_beam = build_l_beam()?.color("#b0f1c8").translate(DVec3::X * 20.0);
64 let heart = build_heart()?.color("#f1b0b0").translate(DVec3::X * 30.0);
65
66 let result = [box_solid, oblique, l_beam, heart];
67
68 let mut f = std::fs::File::create(format!("{example_name}.step")).expect("failed to create STEP file");
69 cadrum::write_step(&result, &mut f).expect("failed to write STEP");
70
71 let mut f = std::fs::File::create(format!("{example_name}.svg")).expect("failed to create SVG file");
72 cadrum::mesh(&result, 0.5).and_then(|m| m.write_svg(DVec3::ONE, DVec3::Z, true, false, &mut f)).expect("failed to write SVG");
73
74 println!("wrote {example_name}.step / {example_name}.svg");
75 Ok(())
76}