com.github.skjolberg.packing.Level Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 3d-bin-container-packing Show documentation
Show all versions of 3d-bin-container-packing Show documentation
Library for 3D rectangular bin packing
package com.github.skjolberg.packing;
import java.util.ArrayList;
/**
* A level within a container
*
*/
public class Level extends ArrayList{
private static final long serialVersionUID = 1L;
public int getHeight() {
int height = 0;
for(Placement placement : this) {
Box box = placement.getBox();
if(box.getHeight() > height) {
height = box.getHeight();
}
}
return height;
}
public int getWeight() {
int weight = 0;
for(Placement placement : this) {
weight += placement.getBox().getWeight();
}
return weight;
}
/**
*
* Check whether placement is valid, i.e. no overlaps.
*
*/
public void validate() {
for(int i = 0; i < size(); i++) {
for(int j = 0; j < size(); j++) {
if(j == i) {
if(!get(i).intersects(get(j))) {
throw new IllegalArgumentException();
}
} else {
if(get(i).intersects(get(j))) {
throw new IllegalArgumentException(i + " vs " + j);
}
}
}
}
}
}