pub struct Interpreter {
pub max_depth: usize,
pub max_terminals: usize,
pub seed: u64,
/* private fields */
}Expand description
The CGA Shape Grammar derivation engine.
Rules are registered by name, then derive is called with a root scope and
root rule name. The engine expands rules breadth-first until every branch
terminates with an I(mesh) terminal.
Stochastic rules with multiple weighted variants use the engine’s seed for
reproducible randomness — the same seed always yields the same building.
Fields§
§max_depth: usizeHard cap on rule-derivation recursion depth. Defaults to MAX_DEPTH
(64). Exceeding it returns ShapeError::DepthLimitExceeded.
max_terminals: usizeHard cap on the number of terminals a single derivation may emit.
Defaults to MAX_TERMINALS (100 000). Exceeding it returns
ShapeError::CapacityOverflow.
seed: u64Seed for stochastic rule selection. Each call to Interpreter::derive
constructs a fresh Pcg64 from this seed, so re-running with the same
seed produces a bit-identical ShapeModel. Default 0.
Implementations§
Source§impl Interpreter
impl Interpreter
pub fn new() -> Self
Sourcepub fn rules(&self) -> &HashMap<String, Vec<WeightedVariant>>
pub fn rules(&self) -> &HashMap<String, Vec<WeightedVariant>>
Returns a reference to the full rule table (rule name → weighted variants).
Sourcepub fn set_variants(
&mut self,
name: impl Into<String>,
variants: Vec<WeightedVariant>,
)
pub fn set_variants( &mut self, name: impl Into<String>, variants: Vec<WeightedVariant>, )
Directly inserts a pre-built variant list for name, bypassing weight validation.
Intended for restoring snapshots produced by
crate::genetics::ShapeGenotype::to_interpreter.
Sourcepub fn add_rule(&mut self, name: impl Into<String>, ops: Vec<ShapeOp>)
pub fn add_rule(&mut self, name: impl Into<String>, ops: Vec<ShapeOp>)
Registers a deterministic production rule.
Sourcepub fn add_weighted_rules(
&mut self,
name: impl Into<String>,
variants: Vec<(f64, Vec<ShapeOp>)>,
) -> Result<(), ShapeError>
pub fn add_weighted_rules( &mut self, name: impl Into<String>, variants: Vec<(f64, Vec<ShapeOp>)>, ) -> Result<(), ShapeError>
Registers a stochastic rule with multiple weighted alternatives.
variants is a list of (relative_weight, ops) pairs. Weights need not
sum to 1.0 — they are normalised internally during selection.
Returns Err(InvalidNumericValue) if any weight is non-finite or negative.
Sourcepub fn derive(
&self,
root_scope: Scope,
root_rule: impl Into<String>,
) -> Result<ShapeModel, ShapeError>
pub fn derive( &self, root_scope: Scope, root_rule: impl Into<String>, ) -> Result<ShapeModel, ShapeError>
Derives the shape model starting from root_scope and root_rule.
Uses a breadth-first work queue to expand rules until all branches
terminate via I(mesh_id) or an unknown rule name (implicit terminal).
A fresh RNG seeded from self.seed is created for each call, making
derivations reproducible for the same seed value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interpreter
impl RefUnwindSafe for Interpreter
impl Send for Interpreter
impl Sync for Interpreter
impl Unpin for Interpreter
impl UnsafeUnpin for Interpreter
impl UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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