Skip to content

Commit

Permalink
add stacked_cubes function
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed May 5, 2024
1 parent e1839a8 commit 7fb2eb0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 16 deletions.
93 changes: 87 additions & 6 deletions packages/cadmium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,88 @@ use truck_shapeops::{and, or, ShapeOpsCurve, ShapeOpsSurface};
use truck_topology::{Shell, Solid};

fn main() {
topological_naming();
// topological_naming();
stacked_cubes();
}

fn stacked_cubes() {
let mut el = EvolutionLog::new();

// Create the Top Plane
let top_plane_id = el.append(Operation::CreatePlane {
nonce: "the top plane".to_string(),
});
el.append(Operation::SetPlaneName {
plane_id: top_plane_id.clone(),
name: "Top".to_string(),
});
let set_plane = el.append(Operation::SetPlane {
plane_id: top_plane_id.clone(),
plane: Plane::top(),
});

// Create the sketch
let sketch_id = el.append(Operation::CreateSketch {
nonce: "top sketch".to_string(),
});
el.append(Operation::SetSketchName {
sketch_id: sketch_id.clone(),
name: "Sketch1".to_string(),
});
el.append(Operation::SetSketchPlane {
sketch_id: sketch_id.clone(),
plane_id: top_plane_id.clone(),
});

// make a square
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (0.0, 0.0),
end: (0.0, 100.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (0.0, 100.0),
end: (100.0, 100.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (100.0, 100.0),
end: (100.0, 0.0),
});
el.append(Operation::AddSketchLine {
sketch_id: sketch_id.clone(),
start: (100.0, 0.0),
end: (0.0, 0.0),
});
// Add a handle to pull the extrusion from
let handle_id = el.append(Operation::AddSketchHandle {
sketch_id: sketch_id.clone(),
position: (20.0, 20.0),
});

// extrude the square
let extrusion_id = el.append(Operation::CreateExtrusion {
nonce: "first extrusion".to_string(),
});
el.append(Operation::SetExtrusionName {
extrusion_id: extrusion_id.clone(),
name: "Extrude1".to_string(),
});
el.append(Operation::SetExtrusionSketch {
extrusion_id: extrusion_id.clone(),
sketch_id: sketch_id.clone(),
});
el.append(Operation::SetExtrusionHandles {
extrusion_id: extrusion_id.clone(),
handles: vec![handle_id.clone()],
});
el.append(Operation::SetExtrusionDepth {
extrusion_id: extrusion_id.clone(),
depth: 100.0,
});

el.git_log();
}

fn topological_naming() {
Expand Down Expand Up @@ -204,10 +285,10 @@ fn main_2() {
extrusion_id: extrusion_id.clone(),
sketch_id: sketch_id.clone(),
});
let set_ext_clicks_commit = el.append(Operation::SetExtrusionClicks {
extrusion_id: extrusion_id.clone(),
clicks: vec![(50.0, 50.0)],
});
// let set_ext_clicks_commit = el.append(Operation::SetExtrusionClicks {
// extrusion_id: extrusion_id.clone(),
// clicks: vec![(50.0, 50.0)],
// });
let finished_rectangle_commit = el.append(Operation::SetExtrusionDepth {
extrusion_id: extrusion_id.clone(),
depth: 10.0,
Expand Down Expand Up @@ -238,7 +319,7 @@ fn main_2() {
el.cherry_pick(extrusion_id);
el.cherry_pick(name_ext_commit);
el.cherry_pick(set_ext_sketch_commit);
el.cherry_pick(set_ext_clicks_commit);
// el.cherry_pick(set_ext_clicks_commit);
let finished_circle_commit = el.cherry_pick(finished_rectangle_commit).unwrap();
let rotated_circle_commit = el.cherry_pick(rotated_rectangle_commit).unwrap();

Expand Down
20 changes: 10 additions & 10 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ pub enum Operation {
extrusion_id: Sha,
sketch_id: Sha,
},
SetExtrusionClicks {
SetExtrusionHandles {
extrusion_id: Sha,
clicks: Vec<(f64, f64)>,
handles: Vec<Sha>,
},
SetExtrusionDepth {
extrusion_id: Sha,
Expand Down Expand Up @@ -417,13 +417,13 @@ impl Operation {
extrusion_id,
sketch_id,
} => hasher.update(format!("{extrusion_id}-{sketch_id}").as_bytes()),
Operation::SetExtrusionClicks {
Operation::SetExtrusionHandles {
extrusion_id,
clicks,
handles,
} => {
hasher.update(format!("{extrusion_id}").as_bytes());
for (x, y) in clicks {
hasher.update(format!("{x}-{y}").as_bytes())
for sha in handles {
hasher.update(format!("{sha}").as_bytes())
}
}
Operation::SetExtrusionDepth {
Expand Down Expand Up @@ -552,13 +552,13 @@ impl Operation {
sketch_id.to_owned()[..num_chars].to_string()
)
}
Operation::SetExtrusionClicks {
Operation::SetExtrusionHandles {
extrusion_id,
clicks,
handles,
} => {
let mut click_str = String::new();
for (x, y) in clicks {
click_str.push_str(&format!("({}, {}) ", x, y));
for sha in handles {
click_str.push_str(&format!("{} ", sha.to_owned()[..num_chars].to_string()));
}
format!(
"SetExtrusionClicks: {} {}",
Expand Down

0 comments on commit 7fb2eb0

Please sign in to comment.