Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1c3d940
Refactor BSP module with dependency inversion and iterators
ryancinsight Jul 10, 2025
a91324a
Refactor BSP module with dependency inversion and iterators +fmt/clippy
ryancinsight Jul 10, 2025
f1c79ee
Refactor BSP module with dependency inversion and iterators +fmt/clippy
ryancinsight Jul 10, 2025
ce36a29
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
4054ea7
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
f8b3bea
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
68b6275
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
d607e70
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
8fd57da
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
f6c932f
Merge branch 'refactor/bsp-dependency-inversion' of https://github.co…
ryancinsight Jul 10, 2025
fff8770
Refactor SDF module into organized submodules
ryancinsight Jul 10, 2025
3951641
Refactor SDF module into organized submodules
ryancinsight Jul 10, 2025
22fac1f
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
163c05e
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
b1a6a11
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
297811e
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
10dfa4d
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
9436619
Merge branch 'refactor-sdf' of https://github.com/ryancinsight/csgrs …
ryancinsight Jul 10, 2025
efcdfa4
Merge branches 'refactor-sdf' and 'refactor-sdf' of https://github.co…
ryancinsight Jul 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/adjacency_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,24 @@ fn main() {
// Demonstrate adaptive refinement
println!("\n7. Adaptive mesh refinement:");
let refined = tessellated.adaptive_refine(0.5, 2.0, 15.0);
let (refined_vertex_map, refined_adjacency_map) = refined.build_connectivity();
println!(" Original triangles: {}", tessellated.polygons.len());
println!(" After refinement: {}", refined.polygons.len());

// Re-analyze connectivity to show changes
let (refined_vertex_map, refined_adjacency_map) = refined.build_connectivity();
let refined_avg_valence = if !refined_adjacency_map.is_empty() {
refined_adjacency_map.values().map(|v| v.len()).sum::<usize>() as Real
/ refined_adjacency_map.len() as Real
} else {
0.0
};

println!(
" Refined unique vertices: {}",
refined_vertex_map.vertex_count()
);
println!(" Refined average valence: {:.2}", refined_avg_valence);

if refined.polygons.len() > tessellated.polygons.len() {
println!(" ✓ Mesh was refined based on quality criteria");
} else {
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ and memory usage:
- allocations should be kept to a minimum. Memory should be read-only if
possible, clone if necessary, and offer the choice of transmut in place or
create new copy via appropriate functions
- For performance-critical operations like BSP and SDF, we use a modular backend
system with dependency inversion. This allows switching between serial and parallel
implementations at compile time via the "parallel" feature flag, ensuring both
flexibility and high performance.

## Todo
- when triangulating, detect T junctions with other polygons with shared edges,
Expand Down
1 change: 0 additions & 1 deletion src/io/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ impl<S: Clone + Debug + Send + Sync> Sketch<S> {
}
}

//
// (C) Encode into a binary STL buffer
//
let mut cursor = Cursor::new(Vec::new());
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//!
//! ![Example CSG output][Example CSG output]
#![cfg_attr(doc, doc = doc_image_embed::embed_image!("Example CSG output", "docs/csg.png"))]
//!
//! # Features
//! #### Default
//! - **f64**: use f64 as Real
Expand Down
52 changes: 26 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn main() {
let ray_origin = Point3::new(0.0, 0.0, -5.0);
let ray_dir = Vector3::new(0.0, 0.0, 1.0); // pointing along +Z
let hits = cube.ray_intersections(&ray_origin, &ray_dir);
println!("Ray hits on the cube: {:?}", hits);
println!("Ray hits on the cube: {hits:?}");
}

// 12) Polyhedron example (simple tetrahedron):
Expand Down Expand Up @@ -297,9 +297,9 @@ fn main() {

// 14) Mass properties (just printing them)
let (mass, com, principal_frame) = cube.mass_properties(1.0);
println!("Cube mass = {}", mass);
println!("Cube center of mass = {:?}", com);
println!("Cube principal inertia local frame = {:?}", principal_frame);
println!("Cube mass = {mass}");
println!("Cube center of mass = {com:?}");
println!("Cube principal inertia local frame = {principal_frame:?}");

// 1) Create a cube from (-1,-1,-1) to (+1,+1,+1)
// (By default, CSG::cube(None) is from -1..+1 if the "radius" is [1,1,1].)
Expand Down Expand Up @@ -349,11 +349,11 @@ fn main() {
);
}

//let poor_geometry_shape = moved_cube.difference(&sphere);
// let poor_geometry_shape = moved_cube.difference(&sphere);
//#[cfg(feature = "earclip-io")]
//let retriangulated_shape = poor_geometry_shape.triangulate_earclip();
// let retriangulated_shape = poor_geometry_shape.triangulate_earclip();
//#[cfg(all(feature = "earclip-io", feature = "stl-io"))]
//let _ = fs::write("stl/retriangulated.stl", retriangulated_shape.to_stl_binary("retriangulated").unwrap());
// let _ = fs::write("stl/retriangulated.stl", retriangulated_shape.to_stl_binary("retriangulated").unwrap());

let sphere_test = Mesh::sphere(1.0, 16, 8, None);
let cube_test = Mesh::cube(1.0, None);
Expand Down Expand Up @@ -724,8 +724,8 @@ fn main() {
let _ = fs::write("stl/octahedron.stl", oct.to_stl_ascii("octahedron"));
}

//let dodec = CSG::dodecahedron(15.0, None);
//let _ = fs::write("stl/dodecahedron.stl", dodec.to_stl_ascii(""));
// let dodec = CSG::dodecahedron(15.0, None);
// let _ = fs::write("stl/dodecahedron.stl", dodec.to_stl_ascii(""));

#[cfg(feature = "stl-io")]
{
Expand Down Expand Up @@ -1041,19 +1041,17 @@ fn main() {
);
}

/*
let helical = CSG::helical_involute_gear(
2.0, // module
20, // z
20.0, // pressure angle
0.05, 0.02, 14,
25.0, // face-width
15.0, // helix angle β [deg]
40, // axial slices (resolution of the twist)
None,
);
let _ = fs::write("stl/helical.stl", helical.to_stl_ascii("helical"));
*/
// let helical = CSG::helical_involute_gear(
// 2.0, // module
// 20, // z
// 20.0, // pressure angle
// 0.05, 0.02, 14,
// 25.0, // face-width
// 15.0, // helix angle β [deg]
// 40, // axial slices (resolution of the twist)
// None,
// );
// let _ = fs::write("stl/helical.stl", helical.to_stl_ascii("helical"));

// Bézier curve demo
#[cfg(feature = "stl-io")]
Expand Down Expand Up @@ -1081,8 +1079,10 @@ fn main() {
let bspline_ctrl = &[[0.0, 0.0], [1.0, 2.5], [3.0, 3.0], [5.0, 0.0], [6.0, -1.5]];
let bspline_2d = Sketch::bspline(
bspline_ctrl,
/* degree p = */ 3,
/* seg/span */ 32,
// degree p =
3,
// seg/span
32,
None,
);
let _ = fs::write("stl/bspline_2d.stl", bspline_2d.to_stl_ascii("bspline_2d"));
Expand All @@ -1092,8 +1092,8 @@ fn main() {
println!("{:#?}", bezier_3d.to_bevy_mesh());

// a quick thickening just like the Bézier
//let bspline_3d = bspline_2d.extrude(0.25);
//let _ = fs::write(
// let bspline_3d = bspline_2d.extrude(0.25);
// let _ = fs::write(
// "stl/bspline_extruded.stl",
// bspline_3d.to_stl_ascii("bspline_extruded"),
//);
Expand Down
Loading