Skip to content

Instantly share code, notes, and snippets.

@Cranc
Created April 30, 2016 15:27
Show Gist options
  • Save Cranc/51c153df964a0cd22058af389791fbad to your computer and use it in GitHub Desktop.
Save Cranc/51c153df964a0cd22058af389791fbad to your computer and use it in GitHub Desktop.
/**
* cuts the Cube into two cubes by red value.
* @return List containing the new Cubes (left and right | up and down | front and back).
*/
public ArrayList<Cube3D> r_cut() {
Comparator<MyPoint> sort = new Comparator<MyPoint>() {
@Override
public int compare(MyPoint o1, MyPoint o2) {
return o1.cords[0] - o2.cords[0];
}
};
System.out.println(points);
Collections.sort(points,sort);
System.out.println(points);
int value = 0;
int boarder = getValue()/2;
ArrayList<MyPoint> left, right;
left = new ArrayList<>();
right = new ArrayList<>();
for(MyPoint p : points) {
value += p.value;
if(value >= boarder)
right.add(p);
else
left.add(p);
}
ArrayList<Cube3D> newCubes = new ArrayList<>();
newCubes.add(new Cube3D(left,
left.get(0).cords[0],
green_min, blue_min,
left.get(left.size()-1).cords[0],
green_max,
blue_max)
);
newCubes.add(new Cube3D(right,
right.get(0).cords[0],
green_min, blue_min,
right.get(right.size()-1).cords[0],
green_max,
blue_max));
return newCubes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment