Skip to main content

ManifoldSolid

Struct ManifoldSolid 

Source
pub struct ManifoldSolid { /* private fields */ }
Expand description

A Manifold solid together with metadata keyed by Manifold OriginalID.

Implementations§

Source§

impl ManifoldSolid

Source

pub fn manifold(&self) -> &Manifold

Source

pub fn into_manifold(self) -> Manifold

Source

pub fn metadata(&self) -> &HashMap<u32, SurfaceMetadata>

Source

pub fn surface_metadata(&self, id: TriangleSourceId) -> Option<&SurfaceMetadata>

Source

pub fn triangle_source_ids( &self, ) -> Result<Vec<TriangleSourceId>, ProvenanceError>

Expand Manifold’s triangle runs into one provenance ID per triangle.

Methods from Deref<Target = Manifold>§

pub fn to_meshgl64(&self) -> MeshGL64

Extract mesh data as f64 vertex properties and u64 triangle indices.

Returns the full [MeshGL64] container, including run metadata, face IDs, merge vectors, and tangents when present.

pub fn to_meshgl64_with_normals(&self, normal_idx: i32) -> MeshGL64

Extract mesh data as f64 with normals baked into vertex properties.

Returns the full [MeshGL64] container. See to_mesh_f64_with_normals for the normal_idx semantics.

pub fn to_mesh_f64(&self) -> (Vec<f64>, usize, Vec<u64>)

Extract mesh data as f64 vertex properties and u64 triangle indices.

Returns (vert_props, n_props, tri_indices).

pub fn to_mesh_f64_with_normals( &self, normal_idx: i32, ) -> (Vec<f64>, usize, Vec<u64>)

Extract mesh data as f64 with normals baked into vertex properties.

The normals are stored starting at property index normal_idx (3 consecutive f64 values per vertex: nx, ny, nz). If the mesh doesn’t already have properties at that index, they are added.

Returns (vert_props, n_props, tri_indices).

pub fn to_mesh_f32_with_normals( &self, normal_idx: i32, ) -> (Vec<f32>, usize, Vec<u32>)

Extract mesh data as f32 with normals baked into vertex properties.

See to_mesh_f64_with_normals for details.

pub fn to_meshgl(&self) -> MeshGL

Extract mesh data as f32 vertex properties and u32 triangle indices.

Returns the full [MeshGL] container, including run metadata, face IDs, merge vectors, and tangents when present.

pub fn to_meshgl_with_normals(&self, normal_idx: i32) -> MeshGL

Extract mesh data as f32 with normals baked into vertex properties.

Returns the full [MeshGL] container. See to_mesh_f64_with_normals for the normal_idx semantics.

pub fn to_mesh_f32(&self) -> (Vec<f32>, usize, Vec<u32>)

Extract mesh data as f32 vertex properties and u32 triangle indices.

Returns (vert_props, n_props, tri_indices).

pub fn translate(&self, x: f64, y: f64, z: f64) -> Manifold

Translate by (x, y, z). Returns a new Manifold.

pub fn scale(&self, x: f64, y: f64, z: f64) -> Manifold

Scale by (x, y, z). Returns a new Manifold.

pub fn rotate(&self, x_deg: f64, y_deg: f64, z_deg: f64) -> Manifold

Rotate by Euler angles (degrees), applied in z-y’-x“ order. Multiples of 90deg use exact arithmetic internally.

pub fn transform(&self, m: &[f64; 12]) -> Manifold

Apply a 4x3 affine transformation (column-major).

The 12 values represent:

| m[0] m[3] m[6] m[9]  |     col1 = X basis
| m[1] m[4] m[7] m[10] |     col2 = Y basis
| m[2] m[5] m[8] m[11] |     col3 = Z basis
                              col4 = translation

pub fn split_by_plane( &self, normal: [f64; 3], offset: f64, ) -> (Manifold, Manifold)

Split into two halves along a plane.

The plane is normal · point = offset. Returns (positive_half, negative_half).

pub fn trim_by_plane(&self, normal: [f64; 3], offset: f64) -> Manifold

Trim to one side of a plane, keeping the positive half.

Note: Upstream issue #1516: trimmed halves may not reassemble via boolean union due to coincident faces.

pub fn slice_at_z(&self, height: f64) -> Vec<Vec<[f64; 2]>>

Slice at a given Z height, returning 2D polygon contours.

Returns a list of polygon rings (each ring is a list of [x, y] points).

pub fn slice_to_cross_section(&self, height: f64) -> CrossSection

Slice at a given Z height, returning a [CrossSection] object.

The cross-section can be offset, extruded, and boolean’d in 2D.

Uses the upstream default [FillRule::Positive], which treats positively oriented contours as filled regions and negatively oriented contours as holes. For other winding semantics (e.g. slices whose contour orientation you don’t control), use slice_to_cross_section_with_fill_rule.

pub fn slice_to_cross_section_with_fill_rule( &self, height: f64, fill_rule: FillRule, ) -> CrossSection

Slice at a given Z height with a specified fill rule, returning a [CrossSection] object.

The fill rule determines how the sliced contours are interpreted into filled regions. See [FillRule] for details.

pub fn is_empty(&self) -> bool

Whether the manifold is empty (zero volume).

pub fn volume(&self) -> f64

Enclosed volume.

pub fn surface_area(&self) -> f64

Total surface area.

pub fn num_vert(&self) -> usize

Number of vertices.

pub fn num_tri(&self) -> usize

Number of triangles.

pub fn bounding_box(&self) -> Option<BoundingBox>

Axis-aligned bounding box.

Returns a [BoundingBox] with spatial query methods (containment, overlap, union, transforms). Returns None if the manifold is empty.

pub fn difference(&self, other: &Manifold) -> Manifold

Boolean difference: self - other.

pub fn union(&self, other: &Manifold) -> Manifold

Boolean union: self + other.

pub fn intersection(&self, other: &Manifold) -> Manifold

Boolean intersection: self ∩ other.

pub fn boolean(&self, other: &Manifold, op: OpType) -> Manifold

Generic boolean operation with an explicit operation type.

Prefer the specific methods (union, difference, intersection) or operator overloads (+, -, ^) for readability. This method is useful when the operation type is determined at runtime.

pub fn decompose(&self) -> Vec<Manifold>

Decompose into connected components.

pub fn hull(&self) -> Manifold

Convex hull of this manifold.

pub fn mirror(&self, normal: [f64; 3]) -> Manifold

Mirror across a plane through the origin with the given normal.

pub fn refine(&self, n: i32) -> Manifold

Increase the density of the mesh by splitting each edge into n pieces.

pub fn refine_to_length(&self, length: f64) -> Manifold

Refine until no edge is longer than length.

pub fn refine_to_tolerance(&self, tolerance: f64) -> Manifold

Refine until the deviation from the true surface is less than tolerance.

pub fn set_tolerance(&self, tolerance: f64) -> Manifold

Set the tolerance of the manifold, returning a new manifold.

pub fn simplify(&self, tolerance: f64) -> Manifold

Simplify the mesh, removing vertices until the error exceeds tolerance.

pub fn smooth_by_normals(&self, normal_idx: i32) -> Manifold

Smooth the manifold by converting sharp edges to smooth curves, using vertex normals at the given property index.

pub fn smooth_out(&self, min_sharp_angle: f64, min_smoothness: f64) -> Manifold

Smooth out the manifold, making sharp edges smoother.

min_sharp_angle (degrees): edges sharper than this are candidates. min_smoothness: minimum smoothness applied (0-1).

pub fn split(&self, cutter: &Manifold) -> (Manifold, Manifold)

Split by another manifold (instead of a plane).

pub fn minkowski_sum(&self, other: &Manifold) -> Manifold

Minkowski sum of two manifolds.

pub fn minkowski_difference(&self, other: &Manifold) -> Manifold

Minkowski difference of two manifolds.

pub fn project(&self) -> Vec<Vec<[f64; 2]>>

Project the manifold onto the XY plane, returning 2D polygons.

pub fn num_edge(&self) -> usize

Number of edges.

pub fn num_prop(&self) -> usize

Number of properties per vertex.

pub fn epsilon(&self) -> f64

Precision (epsilon) of the manifold.

pub fn get_tolerance(&self) -> f64

Tolerance of the manifold (public API, distinct from the epsilon testing hook).

pub fn num_prop_vert(&self) -> usize

Number of property vertices (may differ from num_vert when vertices are split to accommodate different property values).

pub fn genus(&self) -> i32

Genus of the manifold (topological measure: 0 for sphere, 1 for torus, etc).

pub fn original_id(&self) -> i32

Original ID of this manifold (for tracking through operations).

pub fn as_original(&self) -> Manifold

Mark this manifold as an original, assigning it a unique ID for tracking through boolean operations.

Use original_id to retrieve the assigned ID, and [reserve_ids] to pre-allocate ID ranges.

pub fn min_gap(&self, other: &Manifold, search_length: f64) -> f64

Minimum gap between this manifold and another, searching up to search_length.

pub fn status(&self) -> Result<(), CsgError>

Force evaluation of this manifold’s lazy CSG tree.

Manifold operations are lazy: building a CSG tree is cheap and synchronous; the actual evaluation happens when something queries the result. Most queries (num_tri, mesh extraction, volume, etc.) also force evaluation as a side effect, but not all of them observe an attached ExecutionContext. This method is the primary way to force evaluation under a context without consuming a property.

To run the evaluation under a cancellable ExecutionContext, use [Manifold::with_context] first:

let ctx = ExecutionContext::new();
manifold.with_context(&ctx).status()?;

pub fn raw_status(&self) -> ManifoldError

Force evaluation of this manifold’s lazy CSG tree and return the raw manifold3d status code.

Prefer status when you only need success/failure.

pub fn with_context(&self, ctx: &ExecutionContext) -> Manifold

Return a copy of this manifold with ctx attached. The next eager op that consumes an execution context (such as status or refine*) on the returned value observes ctx. Deferred ops (booleans, transforms, batch ops) ignore the attached context and produce results with no attached context.

See the execution module docs for the full pattern. Equivalent to upstream’s manifold_with_context.

The returned Manifold internally holds a shared_ptr to the context’s state (managed on the C++ side via std::atomic_store), so it remains valid even if ctx is dropped before the eager op runs:

// Build a deferred CSG tree whose eager evaluation will need to
// consult the attached context, then attach + drop ctx + eval.
let tree = &Manifold::cube(1.0, 1.0, 1.0, true)
    - &Manifold::sphere(0.6, 32);
let attached = {
    let ctx = ExecutionContext::new();
    tree.with_context(&ctx)
    // ctx drops here; `attached` still holds the inner state
    // via shared_ptr, so the eager op below is safe.
};
attached.status()?;

pub fn ray_cast(&self, origin: [f64; 3], end: [f64; 3]) -> Vec<RayHit>

Cast a ray against this manifold, returning all intersection hits.

The ray goes from origin to end. Returns a list of RayHit results, each containing the face ID, distance, hit position, and surface normal.

pub fn calculate_normals( &self, normal_idx: i32, min_sharp_angle: f64, ) -> Manifold

Calculate normals and store them as vertex properties at normal_idx.

Edges sharper than min_sharp_angle (degrees) get sharp normals.

pub fn calculate_curvature(&self, gaussian_idx: i32, mean_idx: i32) -> Manifold

Calculate Gaussian and mean curvature and store as vertex properties.

pub fn warp<F>(&self, f: F) -> Manifold
where F: FnMut(f64, f64, f64) -> [f64; 3],

Apply a warp function to deform each vertex.

The closure receives (x, y, z) and returns [x', y', z'].

pub fn set_properties<F>(&self, num_prop: usize, f: F) -> Manifold
where F: FnMut(&mut [f64], [f64; 3], &[f64]),

Set custom vertex properties using a callback.

The closure receives (new_props, position, old_props) where:

  • new_props: mutable slice of num_prop f64s to write
  • position: the vertex position [x, y, z]
  • old_props: the existing properties (length = current self.num_prop())

pub fn to_obj(&self) -> String

Export this Manifold as a Wavefront OBJ string.

Trait Implementations§

Source§

impl AsRef<Manifold> for ManifoldSolid

Source§

fn as_ref(&self) -> &Manifold

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for ManifoldSolid

Source§

fn clone(&self) -> ManifoldSolid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for ManifoldSolid

Source§

type Target = Manifold

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ConditionalSend for T
where T: Send,

§

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,