Skip to main content

Region

Struct Region 

Source
pub struct Region {
    pub id: u32,
    pub kind: String,
    pub cells: Vec<(u32, u32)>,
    pub tags: Vec<String>,
}
Expand description

A distinct region within the generated map

Fields§

§id: u32§kind: String§cells: Vec<(u32, u32)>§tags: Vec<String>

Implementations§

Source§

impl Region

Source

pub fn new(id: u32, kind: impl Into<String>) -> Self

Source

pub fn add_cell(&mut self, x: u32, y: u32)

Source

pub fn add_tag(&mut self, tag: impl Into<String>)

Source

pub fn area(&self) -> usize

Examples found in repository?
examples/requirements_demo.rs (line 39)
3fn main() {
4    println!("=== Generate with Requirements Demo ===\n");
5
6    // Create simple requirements that match BSP output
7    let mut requirements = SemanticRequirements::none();
8    requirements.min_regions.insert("Hall".to_string(), 1); // BSP produces "Hall" regions
9    requirements
10        .required_markers
11        .insert(MarkerType::Custom("PlayerStart".to_string()), 1); // BSP produces "PlayerStart"
12
13    println!("Requirements:");
14    println!("  - Minimum 1 Hall region");
15    println!("  - At least 1 PlayerStart marker");
16    println!();
17
18    match generate_with_requirements("bsp", 40, 30, requirements, Some(10), 12345) {
19        Ok((grid, semantic)) => {
20            println!("✅ Successfully generated map meeting requirements!");
21            println!("  Grid size: {}x{}", grid.width(), grid.height());
22            println!("  Floor tiles: {}", grid.count(|t| t.is_floor()));
23            println!("  Total regions: {}", semantic.regions.len());
24
25            // Count Hall regions
26            let hall_count = semantic.regions.iter().filter(|r| r.kind == "Hall").count();
27            println!("  Hall regions: {}", hall_count);
28
29            // Count PlayerStart markers
30            let start_count = semantic
31                .markers
32                .iter()
33                .filter(|m| m.tag() == "PlayerStart")
34                .count();
35            println!("  PlayerStart markers: {}", start_count);
36
37            println!("\nFirst few regions:");
38            for (i, region) in semantic.regions.iter().take(3).enumerate() {
39                println!("  {}: {} ({} cells)", i + 1, region.kind, region.area());
40            }
41        }
42        Err(msg) => {
43            println!("❌ Failed to generate: {}", msg);
44        }
45    }
46}

Trait Implementations§

Source§

impl Clone for Region

Source§

fn clone(&self) -> Region

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 Region

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Region

§

impl RefUnwindSafe for Region

§

impl Send for Region

§

impl Sync for Region

§

impl Unpin for Region

§

impl UnwindSafe for Region

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V