From d67471eea7777938ffe9fb82ac2e060133b655d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Thu, 11 Mar 2021 19:36:45 +0100 Subject: [PATCH] Fixed wall region indexing bug --- src/core/level/lvlgen.rs | 2 +- src/core/level/mod.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/core/level/lvlgen.rs b/src/core/level/lvlgen.rs index af6ab76..2e4d2f6 100644 --- a/src/core/level/lvlgen.rs +++ b/src/core/level/lvlgen.rs @@ -227,7 +227,7 @@ impl LevelGenerator { let outline = r.outline(&grid.scale); let mut floats = outline.iter().map(|p| point!(p.x as f64, p.y as f64)).collect(); self.smooth_wall(&mut floats, self.wall_smooth_radius as isize); - let wall = WallRegion::new(floats); + let wall = WallRegion::new(walls.len(), floats); walls.push(wall); } } diff --git a/src/core/level/mod.rs b/src/core/level/mod.rs index e422042..47a4703 100644 --- a/src/core/level/mod.rs +++ b/src/core/level/mod.rs @@ -204,8 +204,7 @@ pub struct WallRegion { } impl WallRegion { - pub fn new(points: Vec>) -> Self { - let index: RegionIndex = 0; // use as param + pub fn new(index: RegionIndex, points: Vec>) -> Self { let mut edges = Vec::with_capacity(points.len()); for i in 0..points.len() { @@ -223,12 +222,12 @@ impl WallRegion { fn next(&self, index: EdgeIndex) -> Rc { let index = (index + 1) % self.edges.len(); - Rc::clone(&self.edges[index]) + self.edges[index].clone() } fn previous(&self, index: EdgeIndex) -> Rc { - let index = (index + self.edges.len() + 1) % self.edges.len(); - Rc::clone(&self.edges[index]) + let index = (index + self.edges.len() - 1) % self.edges.len(); + self.edges[index].clone() } } @@ -270,18 +269,18 @@ pub struct Wall { impl Wall { #[allow(dead_code)] - pub fn next(self) -> Wall { + pub fn next(&self) -> Wall { Wall { edge: self.region.next(self.edge.id), - region: self.region, + region: self.region.clone(), } } #[allow(dead_code)] - pub fn previous(self) -> Wall { + pub fn previous(&self) -> Wall { Wall { edge: self.region.previous(self.edge.id), - region: self.region, + region: self.region.clone(), } } -- 2.11.0