Struct EnvironmentPlan

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

A bounded sequence of authored boxes. Ramps use one box; stairs and bridges expose checked piece counts for capacity planning. Bounds include all solids, including ramp thickness and bridge rails/posts.

use ferravex_math::Vec3;
use ferravex_play::environment::{BuildError, EnvironmentPlan};

let count = EnvironmentPlan::stairs_piece_count(4)?
    + EnvironmentPlan::bridge_piece_count(2)? + 1; // One ramp.
let mut plan = EnvironmentPlan::new(count)?;
assert_eq!(plan.capacity(), count);
assert_eq!(plan.remaining_capacity(), count);
assert_eq!(plan.piece_count(), 0);
assert_eq!(plan.bounds(), None);
plan.stairs(Vec3::ZERO, 2.0, 0.25, 0.5, 4, 3)?;
assert_eq!(plan.piece_count(), 4);
assert_eq!(plan.remaining_capacity(), count - 4);
assert_eq!(plan.bounds(), Some((Vec3::new(-1.0, 0.0, 0.0),
                              Vec3::new(1.0, 1.0, 2.0))));

Implementations§

Source§

impl EnvironmentPlan

Source

pub fn new(capacity: usize) -> Result<EnvironmentPlan, BuildError>

Source

pub fn pieces(&self) -> &[BoxPiece]

Source

pub fn piece_count(&self) -> usize

Number of authored boxes, in the order returned by Self::pieces.

Source

pub fn capacity(&self) -> usize

Maximum total piece count for this plan, independent of allocator sizing.

Source

pub fn remaining_capacity(&self) -> usize

Number of additional boxes this plan can accept.

Source

pub fn bounds(&self) -> Option<(Vec3, Vec3)>

Union of every piece’s world-axis-aligned BoxPiece::bounds, or None for an empty plan. Visits each piece once without allocating.

Source

pub fn stairs_piece_count(count: u16) -> Result<usize, BuildError>

Boxes required by Self::stairs. Rejects counts outside 1..=128. This checks the count only; the builder also checks origin and dimensions.

Source

pub fn bridge_piece_count(segments: u16) -> Result<usize, BuildError>

Boxes required by Self::bridge: one deck, two rails and two posts at each of segments + 1 stations. Rejects segment counts outside 1..=128. This checks the count only; the builder also checks origin and dimensions.

Source

pub fn append_atomic( &mut self, build: impl FnOnce(&mut EnvironmentPlan) -> Result<(), BuildError>, ) -> Result<(), BuildError>

Append a group of shapes only if build succeeds and every staged piece fits. An error leaves this plan’s pieces, bounds and capacity unchanged.

The callback receives an empty temporary plan limited to this plan’s remaining capacity, including zero when full. Propagate builder errors with ?: deliberately handled errors do not abort the group. The final count is checked again even if the callback replaces the temporary plan. Existing pieces are not visible in the temporary plan.

This authoring operation allocates temporary storage for at most the remaining capacity (at most 1024 boxes). Individual shape builders still write directly into their plan. The callback’s external side effects are not rolled back; if it unwinds, the destination plan remains unchanged.

use ferravex_math::Vec3;
use ferravex_play::environment::{BuildError, EnvironmentPlan};

let mut plan = EnvironmentPlan::new(12)?;
plan.ramp(Vec3::ZERO, 2.0, 1.0, 3.0, 0.2, 0)?;
let before = plan.pieces().to_vec();
let result = plan.append_atomic(|group| {
    group.stairs(Vec3::ZERO, 2.0, 0.25, 0.5, 4, 1)?;
    group.bridge(Vec3::ZERO, 2.0, 4.0, 1.0, 2, 2) // Needs nine more.
});
assert_eq!(result, Err(BuildError::Capacity));
assert_eq!(plan.pieces(), before);
plan.append_atomic(|group| {
    group.stairs(Vec3::ZERO, 2.0, 0.25, 0.5, 4, 1)?;
    group.bridge(Vec3::ZERO, 2.0, 4.0, 1.0, 1, 2) // Seven fits exactly.
})?;
assert_eq!(plan.remaining_capacity(), 0);
Source

pub fn stairs( &mut self, origin: Vec3, width: f32, rise: f32, run: f32, count: u16, material: u16, ) -> Result<(), BuildError>

Origin is the low edge at floor height. Each solid riser extends to floor.

Source

pub fn ramp( &mut self, origin: Vec3, width: f32, rise: f32, run: f32, thickness: f32, material: u16, ) -> Result<(), BuildError>

A single oriented slab; rise/run specify its centerline endpoints.

Source

pub fn bridge( &mut self, origin: Vec3, width: f32, length: f32, height: f32, segments: u16, material: u16, ) -> Result<(), BuildError>

Straight deck, rail beams and evenly spaced support posts. All parts are actual solids, including rails; no invisible collision approximation.

Trait Implementations§

Source§

impl Clone for EnvironmentPlan

Source§

fn clone(&self) -> EnvironmentPlan

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 EnvironmentPlan

Source§

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

Formats the value using the given formatter. 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> 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
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> 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.