diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-31 00:03:32 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-31 00:03:32 -0700 |
| commit | d68cf09f7b8e5cb783dc495097c17eaf2a4d5427 (patch) | |
| tree | 59216cae8c466ad63fa6ff47dc5c7f35c64c23d2 /src/sim/lib/marching_squares.rs | |
| parent | 8e128d3ca24fa10dc7d871f7daf6c43eaddc385c (diff) | |
cleanupkai/herringbone
Diffstat (limited to 'src/sim/lib/marching_squares.rs')
| -rw-r--r-- | src/sim/lib/marching_squares.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/sim/lib/marching_squares.rs b/src/sim/lib/marching_squares.rs index ff48fd5..438b16c 100644 --- a/src/sim/lib/marching_squares.rs +++ b/src/sim/lib/marching_squares.rs @@ -43,15 +43,15 @@ fn derive_type(tl: bool, tr: bool, br: bool, bl: bool) -> usize { pub trait Marchable { fn occupied(&self, pos: IVec2) -> bool; - fn size(&self) -> IVec2; + fn marchable_size(&self) -> IVec2; } -pub fn compute_types(marchable: &impl Marchable, w: i32, h: i32) -> Vec<u8> { +pub fn compute_types(marchable: &impl Marchable) -> Vec<u8> { // TODO could pre-allocate size let mut types = Vec::new(); - for y in -1..h { + for y in -1..marchable.marchable_size().y { // TODO precompute per column - for x in -1..w { + for x in -1..marchable.marchable_size().x { let tl = marchable.occupied(IVec2::new(x, y)); let tr = marchable.occupied(IVec2::new(x + 1, y)); let br = marchable.occupied(IVec2::new(x + 1, y + 1)); @@ -133,11 +133,11 @@ fn toward_side(x: i32, y: i32, exit: Side) -> (i32, i32, Side) { // outer is cw, inner ccw pub fn marching_squares_vertex_trace(marchable: &impl Marchable) -> Vec<Vec<Vec2>> { - let [w, h] = marchable.size().to_array(); + let [w, h] = marchable.marchable_size().to_array(); let mut visited = vec![0u8; ((w + 1) * (h + 1)) as usize]; let idx = |cx: i32, cy: i32| (((cy + 1) * (w + 1)) + (cx + 1)) as usize; - let types = compute_types(marchable, w, h); + let types = compute_types(marchable); let mut polys = Vec::new(); for y in -1..h { |
