Skip to content

Instantly share code, notes, and snippets.

@Cranc
Created April 30, 2016 14:52
Show Gist options
  • Save Cranc/fde79ea1142ac5f87ddda5eb0a3ddaac to your computer and use it in GitHub Desktop.
Save Cranc/fde79ea1142ac5f87ddda5eb0a3ddaac to your computer and use it in GitHub Desktop.
public class Cube3D {
private int red_min;
private int green_min;
private int blue_min;
private int red_max;
private int green_max;
private int blue_max;
//private Map<Integer,Integer> color;
private ArrayList<MyPoint> points;
public Cube3D(Map<Integer,Integer> map, int rmin, int gmin, int bmin, int rmax, int gmax, int bmax){
red_min = rmin; green_min = gmin; blue_min = bmin;
red_max = rmax; green_max = gmax; blue_max = bmax;
points = new ArrayList<>();
for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
int red = (entry.getKey() & 0x00ff0000) >> 16;
int green = (entry.getKey() & 0x0000ff00) >> 8;
int blue = entry.getKey() & 0x000000ff;
if(insideCube(red,green,blue))
points.add(new MyPoint(red,green,blue,entry.getValue()));
}
}
/**
* checks if point is inside cube.
* @param r red value
* @param g green value
* @param b blue value
* @return true if inside else false
*/
private boolean insideCube(int r, int g, int b) {
if((r > red_min && r <= red_max) &&
(g > green_min && g <= green_max) &&
(b > blue_min && b <= blue_max))
return true;
return false;
}
/**
* cuts the Cube into two cubes by red value.
* @return List containing the new Cubes (left and right | up and down | front and back).
*/
private ArrayList<Cube3D> r_cut() {
return null;
}
/**
* cuts the Cube into two cubes by green value.
* @return List containing the new Cubes (left and right | up and down | front and back).
*/
private ArrayList<Cube3D> g_cut() {
return null;
}
/**
* cuts the Cube into two cubes by blue value.
* @return List containing the new Cubes (left and right | up and down | front and back).
*/
private ArrayList<Cube3D> b_cut() {
return null;
}
public int getValue() {
int val = 0;
for(MyPoint p : points) {
val += p.value;
}
return val;
}
/**
* my point class to safe cords of point and value
*/
public class MyPoint {
public int[] cords;
public int value;
public MyPoint(int x, int y, int z, Integer val) {
cords = new int[3];
cords[0] = x; cords[1] = y; cords[2] = z;
value = val;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment