Quadrat.java 2.76 KB
Newer Older
Florian Grabowski's avatar
Florian Grabowski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
35
        if(xEdgeLength < 3 || topRightCorner.x-bottomLeftCorner.x <3){
Florian Grabowski's avatar
Florian Grabowski committed
36
37
38
39
40
41
42
43
            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<>();
44
45
46
47
48
        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));
Florian Grabowski's avatar
Florian Grabowski committed
49
            if(this.xEdgeLength%scrapLength != 0){
50
                Rectangle temp = new Rectangle(scrapLength,this.xEdgeLength-2*scrapLength,new Point(this.bottomLeftCorner.x+scrapLength,this.bottomLeftCorner.y+structure.getWidth().x));
Florian Grabowski's avatar
Florian Grabowski committed
51
                result.addAll(temp.splittToQuads(temp));
52
                temp = new Rectangle(this.xEdgeLength-2*scrapLength,scrapLength,new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+scrapLength));
Florian Grabowski's avatar
Florian Grabowski committed
53
54
55
56
57
58
59
60
61
62
                result.addAll(temp.splittToQuads(temp));
            }
        }
        return result;
    }

    public Boolean getBelegt() {
        return belegt;
    }

63
64
    public  Point getWidth(){
        return new Point(topRightCorner.x-bottomLeftCorner.x,topRightCorner.y-bottomLeftCorner.y);
Florian Grabowski's avatar
Florian Grabowski committed
65
66
67
68
69
70
    }

    public void applyCoordinates(){

    }
}