Function truck_modeling::builder::try_attach_plane[][src]

pub fn try_attach_plane(wires: &[Wire]) -> Result<Face>
Expand description

Try attatiching a plane whose boundary is wire.

Examples

use truck_modeling::*;

// make a disk by attaching a plane into circle
let vertex = builder::vertex(Point3::new(1.0, 0.0, 0.0));
let circle = builder::rsweep(&vertex, Point3::origin(), Vector3::unit_y(), Rad(7.0));
let disk = builder::try_attach_plane(&vec![circle]).unwrap();

Remarks

If wires are not closed or not in one plane, then return None.

use truck_modeling::{*, errors::Error};
let v0 = builder::vertex(Point3::new(0.0, 0.0, 0.0));
let v1 = builder::vertex(Point3::new(1.0, 0.0, 0.0));
let v2 = builder::vertex(Point3::new(0.0, 1.0, 0.0));
let v3 = builder::vertex(Point3::new(0.0, 0.0, 1.0));
let wire: Wire = vec![
    builder::line(&v0, &v1),
    builder::line(&v1, &v2),
]
.into();
let mut wires = vec![wire];
// failed to attach plane, because wire is not closed.
assert_eq!(
    builder::try_attach_plane(&wires).unwrap_err(),
    Error::FromTopology(truck_topology::errors::Error::NotClosedWire),
);

wires[0].push_back(builder::line(&v2, &v3));
wires[0].push_back(builder::line(&v3, &v0));
// failed to attach plane, because wire is not in the plane.
assert_eq!(
    builder::try_attach_plane(&wires).unwrap_err(),
    Error::WireNotInOnePlane,
);

wires[0].pop_back();
wires[0].pop_back();
wires[0].push_back(builder::line(&v2, &v0));
// sucess in attaching plane!
assert!(builder::try_attach_plane(&wires).is_ok());