EOS 2  1.1.0
Einfache Objektbasierte Sprache
Rectangle.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.geo;
2 
3 import de.lathanda.eos.base.layout.BalancePoint;
4 
5 import de.lathanda.eos.base.Picture;
6 import de.lathanda.eos.base.layout.BoundingBox;
7 import de.lathanda.eos.base.layout.Transform;
8 
14 public class Rectangle extends FilledFigure {
15  protected double width;
16  protected double height;
17  public Rectangle() {
18  super();
19  width = 20;
20  height = 20;
21  }
22 
23  @Override
24  protected void drawObject(Picture p) {
25  p.drawRect(width, height);
26  }
27  @Override
28  protected void scaleInternal(double factor) {
29  width *= factor;
30  height *= factor;
31  }
32 
33  public void setWidth(double width) {
34  this.width = width;
36  }
37  public double getWidth() {
38  return width;
39  }
40  public void setHeight(double height) {
41  this.height = height;
43  }
44  public double getHeight() {
45  return height;
46  }
47  public void setCorners(double left, double top, double right, double bottom) {
48  Box b = this.new Box();
49  b.left = left;
50  b.top = top;
51  b.right = right;
52  b.bottom = bottom;
53  b.writeBack();
55  }
56  public void setLeftTop(double left, double top) {
57  moveTo(left + width / 2, top - height / 2);
59  }
60  public void setRightBottom(double right, double bottom) {
61  moveTo(right - width / 2, bottom + height / 2);
63  }
64 
65  public double getLeft() {
66  return getX() - width / 2;
67  }
68  public double getRight() {
69  return getX() + width / 2;
70  }
71  public double getTop() {
72  return getY() + height / 2;
73  }
74  public double getBottom() {
75  return getY() - height / 2;
76  }
77  public void setLeft(double left) {
78  Box b = this.new Box();
79  b.setLeft(left);
80  b.writeBack();
81  }
82  public void setRight(double right) {
83  Box b = this.new Box();
84  b.setRight(right);
85  b.writeBack();
86  }
87  public void setTop(double top) {
88  Box b = this.new Box();
89  b.setTop(top);
90  b.writeBack();
91  }
92  public void setBottom(double bottom) {
93  Box b = this.new Box();
94  b.setBottom(bottom);
95  b.writeBack();
96  }
97 
98  private class Box {
99  private double left;
100  private double right;
101  private double top;
102  private double bottom;
103  Box() {
104  left = getX() - width / 2;
105  right = getX() + width / 2;
106  top = getY() + height / 2;
107  bottom = getY() - height /2;
108  }
109 
110  public void setLeft(double left) {
111  this.left = left;
112  if (left > right) {
113  right = left + width;
114  }
115  }
116 
117  public void setRight(double right) {
118  this.right = right;
119  if (left > right) {
120  left = right - width;
121  }
122  }
123 
124  public void setTop(double top) {
125  this.top = top;
126  if (bottom > top) {
127  bottom = top - height;
128  }
129  }
130 
131  public void setBottom(double bottom) {
132  this.bottom = bottom;
133  if (bottom > top) {
134  top = bottom + height;
135  }
136  }
137 
138  public void writeBack() {
139  width = Math.abs(right - left);
140  height = Math.abs(top - bottom);
141  Rectangle.this.moveTo((right + left)/2,(top + bottom)/2);
142  }
143  }
144 
145  @Override
147  return new BalancePoint(width*height, getX(), getY());
148  }
149  @Override
151  Transform t = base.transform(own);
152  BoundingBox bound = new BoundingBox();
153  bound.add(t.transform(+ width / 2, + height / 2));
154  bound.add(t.transform(- width / 2, + height / 2));
155  bound.add(t.transform(- width / 2, - height / 2));
156  bound.add(t.transform(+ width / 2, - height / 2));
157  return bound;
158  }
159 }
abstract void drawRect(double x, double y, double width, double height)
Geometrische Transformation.
Definition: Transform.java:13
Transform transform(Transform child)
Definition: Transform.java:83
void moveTo(double x, double y)
Definition: Figure.java:133
void setLeft(double left)
Definition: Rectangle.java:77
BoundingBox calculateBoundingBox(Transform base, Transform own)
Definition: Rectangle.java:150
void setHeight(double height)
Definition: Rectangle.java:40
void setBottom(double bottom)
Definition: Rectangle.java:92
void setRight(double right)
Definition: Rectangle.java:82
void setWidth(double width)
Definition: Rectangle.java:33
void scaleInternal(double factor)
Definition: Rectangle.java:28
void setRightBottom(double right, double bottom)
Definition: Rectangle.java:60
void drawObject(Picture p)
Definition: Rectangle.java:24
void setCorners(double left, double top, double right, double bottom)
Definition: Rectangle.java:47
BalancePoint getBalancePoint()
Definition: Rectangle.java:146
void setLeftTop(double left, double top)
Definition: Rectangle.java:56
Impressum