Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Example: csg_primitives_demo

Figure 12.2 — Example: CSG Primitives Demo

Crate: cfd-suite (workspace root)
Run: cargo run --example csg_primitives_demo --features csg
Source: examples/csg_primitives_demo.rs

What This Example Demonstrates

Tessellates all supported CSG primitives (Cube, UV sphere, Cylinder, Cone) and validates each for volume accuracy, watertightness, Euler characteristic, and outward-normal orientation — no boolean operations, pure primitive baseline.

PrimitiveExpected volumeValidation
Cube (side=2)8 m³Signed-volume check
UV sphere (r=1)4π/3 ≈ 4.189 m³Signed-volume check
Cylinder (r, h)π r² hWatertight + Euler χ = 2
Cone (r, h)π r² h / 3Normal orientation

Key Code Snippet

use cfd_mesh::{Cube, IndexedMesh, analyze_normals};
use cfd_mesh::application::watertight::check::check_watertight;
use cfd_mesh::domain::geometry::primitives::{Cone, Cylinder, PrimitiveMesh, UvSphere};

let mut mesh = Cube { origin: Point3r::new(-1.0,-1.0,-1.0),
                      width: 2.0, height: 2.0, depth: 2.0 }.build()?;
// Euler characteristic: V - E + F = 2 for any closed orientable surface
check_watertight(&mesh)?;

Architecture

cfd-mesh (backed by the gaia Atlas crate) provides the topological substrate. The IndexedMesh type owns vertices and cells; check_watertight and analyze_normals operate through the AdjacencyGraph interface without duplicating topology storage.

Book Chapter

← Geometry Construction and CFD Coupling