02run it
$ cargo run
volume 18276.001643 mm³
area 6452.128187 mm²
wrote bracket.step, 8 faces
or
Set up springrep, an exact B-rep CAD kernel in Rust, and run its first example.
1. If this folder is not a Cargo project, run `cargo new springrep-start` and work in that folder.
2. Run `cargo add springrep`.
3. Write the program below exactly as given. In a new project it replaces src/main.rs. If the
project already has its own src/main.rs, save it as examples/bracket.rs instead.
4. Run it with `cargo run`, or `cargo run --example bracket` if you saved it as an example. It
must print:
volume 18276.001643 mm³
area 6452.128187 mm²
wrote bracket.step, 8 faces
If it prints anything else, stop and tell me what it printed. Don't change the part to make
the numbers match.
5. Run `cargo doc -p springrep` and read the module docs before writing any new geometry. Then
ask me what I want to build.
```rust
use springrep::{
blend::fillet,
boolean::difference,
math::{Frame, Vec2, Vec3},
measure,
profile::Profile,
step,
sweep::extrude,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let base = Frame::new(Vec3::ZERO, Vec3::Z, Vec3::X)?;
let below = Frame::new(Vec3::new(0.0, 0.0, -1.0), Vec3::Z, Vec3::X)?;
let plate = extrude(&Profile::rect(Vec2::ZERO, 60.0, 40.0), &base, 8.0, "plate")?;
let bore = extrude(&Profile::circle(Vec2::ZERO, 12.0), &below, 10.0, "bore")?;
let part = difference(&plate, &bore)?;
let part = fillet(&part, &[("plate.end", "bore.side")], 1.5, "round")?;
println!("volume {:.6} mm³", measure::volume(&part));
println!("area {:.6} mm²", measure::area(&part));
std::fs::write("bracket.step", step::write(&part, "bracket")?)?;
println!("wrote bracket.step, {} faces", part.face_count());
Ok(())
}
```
Things to know:
- Every operation returns a Result. Propagate errors with ?; never unwrap a geometry result.
- Faces are named after the feature that made them: plate.end is the top of an extrusion named
plate, bore.side is the wall of one named bore. Fillets and chamfers pick an edge by the names
of the two faces either side of it.
- Run springrep::check::check on each new solid and treat any issue it reports as a bug.
- Units are millimetres.
src/main.rs
use springrep::{
blend::fillet,
boolean::difference,
math::{Frame, Vec2, Vec3},
measure,
profile::Profile,
step,
sweep::extrude,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let base = Frame::new(Vec3::ZERO, Vec3::Z, Vec3::X)?;
let below = Frame::new(Vec3::new(0.0, 0.0, -1.0), Vec3::Z, Vec3::X)?;
let plate = extrude(&Profile::rect(Vec2::ZERO, 60.0, 40.0), &base, 8.0, "plate")?;
let bore = extrude(&Profile::circle(Vec2::ZERO, 12.0), &below, 10.0, "bore")?;
let part = difference(&plate, &bore)?;
let part = fillet(&part, &[("plate.end", "bore.side")], 1.5, "round")?;
println!("volume {:.6} mm³", measure::volume(&part));
println!("area {:.6} mm²", measure::area(&part));
std::fs::write("bracket.step", step::write(&part, "bracket")?)?;
println!("wrote bracket.step, {} faces", part.face_count());
Ok(())
}