package de._82grfl1bif.KPI_Visualizer.helpers; import de._82grfl1bif.KPI_Visualizer.structures.Structure; import java.awt.*; import java.util.ArrayList; public class Quadrat extends Shape{ private Boolean belegt; public Structure getStructure() { return structure; } private Structure structure; public Quadrat(Point bottomLeftCorner, Point topRightCorner){ this.bottomLeftCorner = bottomLeftCorner; this.topRightCorner = topRightCorner; this.xEdgeLength = topRightCorner.x-bottomLeftCorner.x; this.belegt=false; if(topRightCorner.y-bottomLeftCorner.y < 3 || topRightCorner.x-bottomLeftCorner.x <3){ throw new IllegalArgumentException("keine Quadrate < 3 erlaubt"); } } public Quadrat(Point bottomLeftCorner, int xEdgeLength){ this.xEdgeLength = xEdgeLength; this.bottomLeftCorner = bottomLeftCorner; this.topRightCorner = new Point(bottomLeftCorner.x+xEdgeLength,bottomLeftCorner.y+xEdgeLength); this.belegt = false; if(xEdgeLength < 3 || topRightCorner.x-bottomLeftCorner.x <3){ throw new IllegalArgumentException("keine Quadrate < 3 erlaubt " + xEdgeLength); } } public ArrayList setBelegt(Structure structure) { this.belegt = true; this.structure = structure; ArrayList result = new ArrayList<>(); if(this.xEdgeLength > structure.getWidth().x+3){//if you can splitt rest into more quads int scrapLength = this.xEdgeLength-structure.getWidth().x; result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y),scrapLength)); result.add(new Quadrat(new Point(this.bottomLeftCorner.x,this.bottomLeftCorner.y+structure.getWidth().x),scrapLength)); result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+structure.getWidth().x),scrapLength)); if(this.xEdgeLength%scrapLength != 0){ Rectangle temp = new Rectangle(scrapLength,this.xEdgeLength-2*scrapLength,new Point(this.bottomLeftCorner.x+scrapLength,this.bottomLeftCorner.y+structure.getWidth().x)); result.addAll(temp.splittToQuads(temp)); temp = new Rectangle(this.xEdgeLength-2*scrapLength,scrapLength,new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+scrapLength)); result.addAll(temp.splittToQuads(temp)); } } return result; } public Boolean getBelegt() { return belegt; } public Point getWidth(){ return new Point(topRightCorner.x-bottomLeftCorner.x,topRightCorner.y-bottomLeftCorner.y); } public void applyCoordinates(){ } }