Rectangle.java 3.04 KB
Newer Older
Florian Grabowski's avatar
Florian Grabowski committed
1
package de._82grfl1bif.kpiVisualizer.layouts.simpleSquare;
Florian Grabowski's avatar
Florian Grabowski committed
2

Florian Grabowski's avatar
Florian Grabowski committed
3
import java.awt.Point;
Florian Grabowski's avatar
Florian Grabowski committed
4
5
6
7
import java.util.ArrayList;

public class Rectangle extends Shape {

8
    private final int zEdgeLength;
Florian Grabowski's avatar
Florian Grabowski committed
9
10
11
12
13
14
15
16

    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);
    }

17
    public ArrayList<Quadrat> splitToQuads(Rectangle r) {
Florian Grabowski's avatar
Florian Grabowski committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
        ArrayList<Quadrat> 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) {
35
                        result.addAll(splitToQuads(new Rectangle(scrapLength, r.xEdgeLength, scrapPoint)));
Florian Grabowski's avatar
Florian Grabowski committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
                    }
                }
            } 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;
                    }
52
53
                    if (scrapLength >= 3) {
                        result.addAll(splitToQuads(new Rectangle(r.zEdgeLength, scrapLength, scrapPoint)));
Florian Grabowski's avatar
Florian Grabowski committed
54
55
56
57
58
59
60
                    }
                }
            }
        }
        return result;
    }
}