Quadrat.java 2.83 KB
Newer Older
Florian Grabowski's avatar
Florian Grabowski committed
1
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
Florian Grabowski's avatar
Florian Grabowski committed
2
3
4
5
6
7

import de._82grfl1bif.KPI_Visualizer.structures.Structure;

import java.awt.*;
import java.util.ArrayList;

Florian Grabowski's avatar
Florian Grabowski committed
8
public class Quadrat extends Shape {
Florian Grabowski's avatar
Florian Grabowski committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

    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;
33
        if(xEdgeLength < 3 || topRightCorner.x-bottomLeftCorner.x <3){
Florian Grabowski's avatar
Florian Grabowski committed
34
35
36
37
38
39
40
41
            throw new IllegalArgumentException("keine Quadrate < 3 erlaubt " + xEdgeLength);
        }
    }

    public ArrayList<Quadrat> setBelegt(Structure structure) {
        this.belegt = true;
        this.structure = structure;
        ArrayList<Quadrat> result = new ArrayList<>();
42
        if(this.xEdgeLength > structure.getWidth().x+3){//if you can split rest into more quads
43
44
45
46
            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));
Florian Grabowski's avatar
Florian Grabowski committed
47
            if(this.xEdgeLength%scrapLength != 0){
48
                Rectangle temp = new Rectangle(scrapLength,this.xEdgeLength-2*scrapLength,new Point(this.bottomLeftCorner.x+scrapLength,this.bottomLeftCorner.y+structure.getWidth().x));
49
                result.addAll(temp.splitToQuads(temp));
50
                temp = new Rectangle(this.xEdgeLength-2*scrapLength,scrapLength,new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+scrapLength));
51
                result.addAll(temp.splitToQuads(temp));
Florian Grabowski's avatar
Florian Grabowski committed
52
53
54
55
56
57
58
59
60
            }
        }
        return result;
    }

    public Boolean getBelegt() {
        return belegt;
    }

61
62
    public  Point getWidth(){
        return new Point(topRightCorner.x-bottomLeftCorner.x,topRightCorner.y-bottomLeftCorner.y);
Florian Grabowski's avatar
Florian Grabowski committed
63
64
    }

65
66
    public void applyCoordinates(Point coordinates){
        this.bottomLeftCorner = coordinates;
Florian Grabowski's avatar
Florian Grabowski committed
67
68
    }
}