EOS 2  1.1.0
Einfache Objektbasierte Sprache
BoundingBox.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.base.layout;
2 
3 import de.lathanda.eos.base.math.Point;
4 
14 public class BoundingBox {
15  private double left;
16  private double right;
17  private double top;
18  private double bottom;
19  private boolean valid;
20  public BoundingBox() {
21  left = Double.POSITIVE_INFINITY;
22  right = Double.NEGATIVE_INFINITY;
23  bottom = Double.POSITIVE_INFINITY;
24  top = Double.NEGATIVE_INFINITY;
25  valid = false;
26  }
27  public BoundingBox(double left, double right, double bottom, double top) {
28  this.left = left;
29  this.right = right;
30  this.top = top;
31  this.bottom = bottom;
32  valid = true;
33  }
34  public void add(Point p) {
35  add(p.getX(), p.getY());
36  }
37  public void add(double x, double y) {
38  if (left > x) {
39  left = x;
40  }
41  if (right < x) {
42  right = x;
43  }
44  if (bottom > y) {
45  bottom = y;
46  }
47  if (top < y) {
48  top = y;
49  }
50  valid = true;
51  }
52  public void add(BoundingBox b) {
53  if (left > b.left) {
54  left = b.left;
55  }
56  if (right < b.right) {
57  right = b.right;
58  }
59  if (bottom > b.bottom) {
60  bottom = b.bottom;
61  }
62  if (top < b.top) {
63  top = b.top;
64  }
65  valid = true;
66  }
67  public double getArea() {
68  if (valid) {
69  return (right - left) *(top-bottom);
70  } else {
71  return 0;
72  }
73  }
74  public double getArea(double drawWidth) {
75  if (valid) {
76  return (right - left + drawWidth) *(top - bottom + drawWidth);
77  } else {
78  return 0;
79  }
80  }
81  public double getLeft() {
82  return left;
83  }
84 
85  public double getRight() {
86  return right;
87  }
88 
89  public double getTop() {
90  return top;
91  }
92 
93  public double getBottom() {
94  return bottom;
95  }
96  public boolean isValid() {
97  return valid;
98  }
99  public Point getCenter() {
100  return new Point((left + right) / 2, (top + bottom) / 2);
101  }
102  @Override
103  public String toString() {
104  return "BoundingBox("+left+","+top+","+right+","+bottom+")";
105  }
106 
107 }
BoundingBox(double left, double right, double bottom, double top)
double getArea(double drawWidth)
Impressum