BoxStyle

Struct BoxStyle 

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

Set of blocks used to draw 3D boxes of any size, allowing corners and edges to have different blocks than faces and the interior.

Boxes have walls exactly 1 cube thick. Thus, a BoxStyle has 64 parts (blocks), identified by the BoxPart type:

  • interior volume,
  • 6 faces,
  • 12 edges,
  • 8 corners, and
  • 38 more parts for the case where the box to be drawn is only one block thick, thus requiring a block to be both faces simultaneously on one or more axes.

Each part of the box can be absent (None), which means that when drawn, the existing block in that place is unchanged.

This can be considered a 3-dimensional analogue of the “9-patch image” concept, or as a voxel “tile set” (but one with no “inside corner” pieces).

BoxStyle’s data is kept behind a reference-counted pointer, so BoxStyle is small and cheap to clone.

Implementations§

Source§

impl BoxStyle

Source

pub fn from_fn<F>(f: F) -> BoxStyle
where F: FnMut(BoxPart) -> Option<Block>,

Construct a BoxStyle by asking a function for each part.

The order of calls to the function is unspecified and subject to change.

Source

pub fn from_nine_and_thin(multiblock: &Block) -> BoxStyle

Construct a BoxStyle from a 2D 4×4×1 multiblock whose components on each axis are in the order [lower, middle, upper, lower & upper]; that is, this layout of blocks:

┊ ┏━━━━━━━━━━━━━┓┏━━━┓
3 ┃             ┃┃   ┃
┊ ┗━━━━━━━━━━━━━┛┗━━━┛
┃ ┏━━━━━━━━━━━━━┓┏━━━┓
2 ┃             ┃┃   ┃
┃ ┃             ┃┃   ┃
┊ ┃             ┃┃   ┃
1 ┃             ┃┃   ┃
┊ ┃             ┃┃   ┃
┃ ┃             ┃┃   ┃
0 ┃             ┃┃   ┃
┃ ┗━━━━━━━━━━━━━┛┗━━━┛
  ━━0━━┈┈1┈┈━━2━━┈┈3┈┈

The resolution is one quarter of the input. The Z axis is filled with all the same blocks. TODO: Make it sensitive to the input dimensions as defined by multiblock metadata instead.

Source

pub fn from_composited_corner_and_edge( corner_block: Block, line_section_block: Block, ) -> BoxStyle

Construct a BoxStyle made up of one type of corner block and one type of edge block.

  • corner_block will be composited with the line sections at all eight corners of the box. It should be oriented as the lower_bounds corner of the box; the other seven corners will be mirrored across the relevant axis.
  • line_section_block should be a block which is a line segment at the origin and extending in the +Z direction. It should be symmetric about the X-Y=0 plane, and will be rotated and mirrored to make the other forms.
Source

pub fn with(self, part: BoxPart, block: Option<Block>) -> BoxStyle

Replace a single part of this and return the modified style.

Source

pub fn map(self, block_fn: impl FnMut(BoxPart, Block) -> Block) -> BoxStyle

Applies the given function to every block present in this. Does not affect absent blocks.

Source

pub fn create_box(&self, bounds: GridAab) -> SpaceTransaction

Returns a transaction that places an axis-aligned box of blocks from this BoxStyle, within and up to the bounds of the given GridAab.

  • The lines will lie just inside of bounds.
Source

pub fn cube_at(&self, bounds: GridAab, cube: Cube) -> Option<&Block>

Returns the block that is the part of this box at the specified cube when the box bounds are bounds.

Trait Implementations§

Source§

impl Clone for BoxStyle

Source§

fn clone(&self) -> BoxStyle

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BoxStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Index<BoxPart> for BoxStyle

Source§

type Output = Option<Block>

The returned type after indexing.
Source§

fn index(&self, index: BoxPart) -> &<BoxStyle as Index<BoxPart>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<BoxPart> for BoxStyle

Source§

fn index_mut( &mut self, index: BoxPart, ) -> &mut <BoxStyle as Index<BoxPart>>::Output

Performs the mutable indexing (container[index]) operation. Read more

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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
Source§

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

Source§

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

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

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

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

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

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

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

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.