All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.skjolberg.packing.Level Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
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;
	}
	
	/**
	 * 
	 * Check wheter 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).intercets(get(j))) {
						throw new IllegalArgumentException();
					}
				} else {
					if(get(i).intercets(get(j))) {
						throw new IllegalArgumentException(i + " vs " + j);
					}
				}
			}
		}		
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy