Skip to content

Commit

Permalink
Start fixing some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <dzervas@dzervas.gr>
  • Loading branch information
dzervas committed May 28, 2024
1 parent b76d30b commit 404aabe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
10 changes: 5 additions & 5 deletions packages/cadmium/src/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mod tests {

// now get solids? save as obj or stl or step?
let workbench = p.workbenches.get_mut(0).unwrap();
let realization = workbench.realize(100);
let realization = workbench.realize(100).unwrap();
let solids = realization.solids;
println!("solids: {:?}", solids);
}
Expand Down Expand Up @@ -358,7 +358,7 @@ mod tests {

// get a realization
let workbench = p.workbenches.get_mut(0).unwrap();
let realization = workbench.realize(100);
let realization = workbench.realize(100).unwrap();
let solids = realization.solids;
println!("[{}] solids: {:?}", file, solids.len());

Expand All @@ -370,11 +370,11 @@ mod tests {
fn step_export() {
let p = create_test_project();
let workbench = &p.workbenches[0 as usize];
let realization = workbench.realize(1000);
let realization = workbench.realize(1000).unwrap();
let keys = Vec::from_iter(realization.solids.keys());

realization.save_solid_as_step_file(keys[0], "pkg/test.step");
realization.save_solid_as_obj_file(keys[0], "pkg/test.obj", 0.001);
realization.save_solid_as_step_file(*keys[0], "pkg/test.step");
realization.save_solid_as_obj_file(*keys[0], "pkg/test.obj", 0.001);
}

}
27 changes: 15 additions & 12 deletions packages/cadmium/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct Assembly {
pub mod tests {
use truck_polymesh::obj;

use crate::archetypes::PlaneDescription;
use crate::archetypes::Point2;
use crate::extrusion::Direction;
use crate::extrusion::Extrusion;
use crate::extrusion::ExtrusionMode;
Expand All @@ -100,17 +102,18 @@ pub mod tests {

pub fn create_test_project() -> Project {
let mut p = Project::new("Test Project");
let plane_desc = PlaneDescription::PlaneId(0);
let wb = p.workbenches.get_mut(0).unwrap();
wb.add_sketch_to_plane("Sketch 1", "Plane-0");
let s = wb.get_sketch_mut("Sketch 1").unwrap();
let ll = s.add_point(0.0, 0.0);
let lr = s.add_point(40.0, 0.0);
let ul = s.add_point(0.0, 40.0);
let ur = s.add_point(40.0, 40.0);
s.add_segment(ll, lr);
s.add_segment(lr, ur);
s.add_segment(ur, ul);
s.add_segment(ul, ll);
let sid = p.add_workbench_sketch("Sketch 1".to_string(), 0, plane_desc).unwrap();
let s = wb.get_sketch_by_id(sid).unwrap().borrow_mut();
let ll = s.add_sketch_point(Point2 { x: 0.0, y: 0.0, hidden: false }).unwrap();
let lr = s.add_sketch_point(Point2 { x: 40.0, y: 0.0, hidden: false }).unwrap();
let ul = s.add_sketch_point(Point2 { x: 0.0, y: 40.0, hidden: false }).unwrap();
let ur = s.add_sketch_point(Point2 { x: 40.0, y: 40.0, hidden: false }).unwrap();
s.add_sketch_line(ll, lr);
s.add_sketch_line(lr, ur);
s.add_sketch_line(ur, ul);
s.add_sketch_line(ul, ll);

let extrusion = Extrusion::new(
"Sketch-0".to_owned(),
Expand All @@ -129,10 +132,10 @@ pub mod tests {
fn one_extrusion() {
let p = create_test_project();

let realization = p.get_realization(0, 1000);
let realization = p.get_realization(0, 1000).unwrap();
let solids = realization.solids;

let solid = &solids["Ext1:0"];
let solid = &solids.get(&0).unwrap();

println!("{:?}", solid);
}
Expand Down
14 changes: 3 additions & 11 deletions packages/cadmium/src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,9 @@ impl Workbench {
self.history[index].data = new_step_data;
}

// pub fn add_extrusion(&mut self, name: &str, extrusion: Extrusion) -> u64 {
// // If the extrusion name is empty string, then we need to generate a new name
// // Let's use "Extrusion n" where n is the number of extrusions
// let extrusion_name = if name == "" {
// format!("Extrusion {}", *counter + 1)
// } else {
// name.to_owned()
// };
// self.history
// .push(Step::new_extrusion(&extrusion_name, extrusion, *counter));
// }
pub fn add_extrusion(&mut self, name: &str, extrusion: Extrusion) -> u64 {
self.history.push(Step::new_extrusion(&extrusion_name, extrusion, *counter));
}

pub fn realize(&self, max_steps: u64) -> Result<Realization, anyhow::Error> {
let mut realized = Realization::new();
Expand Down

0 comments on commit 404aabe

Please sign in to comment.