Created
August 27, 2018 21:58
-
-
Save digital-synapse/1d5eaa9607df491e2cb5bc60526db62d to your computer and use it in GitHub Desktop.
Fast 3D arrays in .Net
This file contains 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
public class DataCube<T> { | |
public DataCube(int width, int height, int depth){ | |
this.width = width; | |
this.height = height; | |
this.depth = depth; | |
size3d = width*height*depth; | |
size2d = width*height; | |
data = new T[size3d]; | |
} | |
private T[] data; | |
private int width; | |
private int height; | |
private int depth; | |
private int size3d; | |
private int size2d; | |
public T this[int x, int y, int z]{ | |
get { return data[index(x,y,z)]; } | |
set { data[index(x,y,z)] = value; } | |
} | |
private int index(int x, int y, int z){ | |
return x + y * width + z * size2d; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment