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)>Implementations§
Source§impl Region
impl Region
pub fn new(id: u32, kind: impl Into<String>) -> Self
pub fn add_cell(&mut self, x: u32, y: u32)
pub fn add_tag(&mut self, tag: impl Into<String>)
Sourcepub fn area(&self) -> usize
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§
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> 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
Mutably borrows from an owned value. Read more