Skip to main content

Csg

Struct Csg 

Source
pub struct Csg<T: Number> { /* private fields */ }

Implementations§

Source§

impl<T: Number> Csg<T>

Source

pub fn new(polygons: Vec<Polygon<T, 3>>) -> Self

Source

pub fn from_polygons(polygons: impl IntoIterator<Item = Polygon<T, 3>>) -> Self

Source

pub fn factory(&self) -> &CsgFactory<T>

Source

pub fn factory_mut(&mut self) -> &mut CsgFactory<T>

Source

pub fn with_factory(self, factory: CsgFactory<T>) -> Self

Replace the embedded factory (e.g. after building via an external CsgFactory).

Source

pub fn union(self, other: Csg<T>) -> Self

Source

pub fn intersection(self, other: Csg<T>) -> Self

Source

pub fn polygons(&self) -> &[Polygon<T, 3>]

Source

pub fn cleanup(self) -> Self

Run a cleanup pass: remove degenerate polygons, collapse collinear vertices, and merge coplanar adjacent polygons. Call once before mesh generation rather than after every CSG operation.

Source

pub fn mapv_inplace<F>(&mut self, f: F)
where F: Fn(Polygon<T, 3>) -> Polygon<T, 3>,

Apply a function to every polygon in place.

Source

pub fn par_mapv_inplace<F>(&mut self, f: F)
where F: Fn(Polygon<T, 3>) -> Polygon<T, 3> + Send + Sync,

Apply a function to every polygon in place, in parallel.

Source

pub fn mapv_inplace_points<F>(&mut self, f: F)
where F: Fn(Point3<T>) -> Point3<T>,

Apply a function to every vertex of every polygon in place.

Source

pub fn par_mapv_inplace_points<F>(&mut self, f: F)
where F: Fn(Point3<T>) -> Point3<T> + Send + Sync,

Apply a function to every vertex of every polygon in place, in parallel.

Source

pub fn translate(self, offset: Vector3<T>) -> Self

Translate all polygons by an offset.

Source

pub fn scale(self, factors: Vector3<T>) -> Self

Scale all polygon vertices by per-axis factors.

Planes are recomputed from the scaled vertices: a non-uniform scale changes plane normals (inverse-transpose transform), so the cached plane can’t just be carried over.

Source

pub fn rotate_euler(self, angles_deg: Vector3<T>) -> Self

Rotate all polygons by Euler angles (degrees), applied as Z × Y × X.

Source

pub fn mirror(self, axes: Vector3<T>) -> Self

Mirror across axes where the corresponding component is non-zero.

Reverses polygon winding to maintain correct normals.

Source

pub fn xor(self, other: Csg<T>) -> Self

Symmetric difference: (a - b) ∪ (b - a).

Source

pub fn difference(self, other: Csg<T>) -> Self

Different (a - (a ^ b))

Source

pub fn extrude( self, along: Vector3<T>, transform: Affine3<T>, slices: usize, ) -> Result<Self, Error>

Extrudes a planar shape along a vector.

The extrusion is subdivided into slices levels. At each level the rotation angle and scale factor are linearly interpolated from identity (at the bottom) to the full transform (at the top).

The transform is decomposed into a rotation (axis-angle) and uniform scale. Non-uniform scale is not supported.

Side walls are triangulated to guarantee planarity when twist is used.

Source

pub fn lathe(self, angle_degrees: T, segments: usize) -> Result<Self, Error>

Revolves a planar XZ-plane profile about the +Y axis (lathe).

Profile vertices (x, 0, z) sweep to (x·cosθ, z, x·sinθ); profile-x is the radius (x ≥ 0 expected), profile-z the height along the axis. Full revolutions weld the seam; partial sweeps are closed with start and end caps. Side walls are triangulated (swept quads are non-planar), and triangles degenerated by on-axis vertices are dropped.

Source

pub fn coplanar(&self) -> bool

Source

pub fn cast<T2: Number>(self) -> Csg<T2>
where T: AsPrimitive<T2>,

Cast the CSG solid’s numeric type from T to T2, e.g. f64f32.

Face keys are preserved unchanged; only vertex coordinates and plane equations are converted via num_traits::cast::AsPrimitive.

Source§

impl Csg<f32>

Source

pub fn to_bevy_mesh(&self) -> Mesh

Trait Implementations§

Source§

impl<T: Clone + Number> Clone for Csg<T>

Source§

fn clone(&self) -> Csg<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for Csg<T>

§

impl<T> RefUnwindSafe for Csg<T>
where T: RefUnwindSafe,

§

impl<T> Send for Csg<T>

§

impl<T> Sync for Csg<T>

§

impl<T> Unpin for Csg<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Csg<T>

§

impl<T> UnwindSafe for Csg<T>

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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,