Created
January 18, 2014 11:05
-
-
Save pzol/8489002 to your computer and use it in GitHub Desktop.
ICE on 3d vector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum TileSet { | |
Empty, | |
Dirt | |
} | |
type XYZ = (uint, uint, uint); | |
static MAXX: uint = 10; | |
static MAXY: uint = 10; | |
static MAXZ: uint = 1; | |
struct Map { | |
tiles: [[[TileSet, ..MAXX], ..MAXY], ..MAXZ] | |
} | |
impl Map { | |
fn new() -> Map { | |
Map { tiles: [[[Empty, ..MAXX], ..MAXY], ..MAXZ] } | |
} | |
fn set(&mut self, index: &XYZ, tile: TileSet) -> Result<TileSet, ~str> { | |
let (x, y, z) = *index; | |
self.tiles[z][y][x] = tile; | |
Ok(tile) | |
} | |
} | |
impl Index<(uint, uint, uint), Option<TileSet>> for Map { | |
fn index(&self, index: &XYZ) -> Option<TileSet> { | |
let (x, y, z) = *index; | |
println!("{}", self.tiles.len()); | |
Some(self.tiles[z][y][x]) | |
} | |
} | |
#[test] | |
fn test_3d_array(){ | |
let mut map = Map::new(); | |
map[(0, 0, 0)] = Some(Dirt); | |
let tile = map[(0, 0, 0)]; | |
println!("{:?}", map); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment