package de._82grfl1bif.KPI_Visualizer.helpers; import java.awt.*; import java.util.ArrayList; public class Rectangle extends Shape { private final int zEdgeLength; public Rectangle(int zEdgeLength, int xEdgeLength, Point bottomLeftCorner) { this.zEdgeLength = zEdgeLength; this.xEdgeLength = xEdgeLength; this.bottomLeftCorner = bottomLeftCorner; this.topRightCorner = new Point(bottomLeftCorner.x + xEdgeLength, bottomLeftCorner.y + zEdgeLength); } public ArrayList splitToQuads(Rectangle r) { ArrayList result = new ArrayList<>(); if (r.xEdgeLength >= 3 && r.zEdgeLength >= 3) { if ((r.xEdgeLength - r.zEdgeLength) < 0) {//standing Rectangle if ((r.zEdgeLength % r.xEdgeLength) == 0) {//completely degradable for (int c = 0; c < r.zEdgeLength / r.xEdgeLength; c++) { result.add(new Quadrat(new Point(r.bottomLeftCorner.x, r.bottomLeftCorner.y + (r.xEdgeLength * c)), r.xEdgeLength)); } } else {//left over Rectangle int scrapLength = r.zEdgeLength; Point scrapPoint = new Point(0, 0); for (int c = 0; c < r.zEdgeLength / r.xEdgeLength; c++) { result.add(new Quadrat(new Point(r.bottomLeftCorner.x, r.bottomLeftCorner.y + (r.xEdgeLength * c)), r.xEdgeLength)); scrapLength -= r.xEdgeLength; scrapPoint.x = r.bottomLeftCorner.x; scrapPoint.y = (r.bottomLeftCorner.y + (r.xEdgeLength * (c + 1))); } if (scrapLength >= 3 && r.xEdgeLength >= 3) { result.addAll(splitToQuads(new Rectangle(scrapLength, r.xEdgeLength, scrapPoint))); } } } else {//laying Rectangles if ((r.xEdgeLength % r.zEdgeLength) == 0) {//completely degradable for (int c = 0; c < r.xEdgeLength / r.zEdgeLength; c++) { result.add(new Quadrat(new Point(r.bottomLeftCorner.x + (r.zEdgeLength * c), r.bottomLeftCorner.y), r.zEdgeLength)); } } else {//left over Rectangle int scrapLength = r.xEdgeLength; Point scrapPoint = new Point(0, 0); for (int c = 0; c < r.xEdgeLength / r.zEdgeLength; c++) { result.add(new Quadrat(new Point(r.bottomLeftCorner.x + (r.zEdgeLength * c), r.bottomLeftCorner.y), r.zEdgeLength)); scrapLength -= r.zEdgeLength; scrapPoint.x = (r.bottomLeftCorner.x + (r.zEdgeLength * (c + 1))); scrapPoint.y = r.bottomLeftCorner.y; } if (scrapLength >= 3) { result.addAll(splitToQuads(new Rectangle(r.zEdgeLength, scrapLength, scrapPoint))); } } } } return result; } }