EOS 2  1.1.0
Einfache Objektbasierte Sprache
ShapeGroup.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.game.geom;
2 
3 import de.lathanda.eos.base.Picture;
4 import de.lathanda.eos.base.math.Matrix;
5 import de.lathanda.eos.base.math.Point;
6 import de.lathanda.eos.base.math.Vector;
7 import java.util.ArrayList;
8 
20 public class ShapeGroup extends Shape {
21 
25  private ArrayList<Shape> list;
29  private Point previousLocation;
33  private double previousAngle;
34 
38  public ShapeGroup() {
39  p = new Point(0, 0);
40  previousLocation = new Point(0, 0);
41  angle = 0;
42  previousAngle = 0;
43  list = new ArrayList<>();
44  }
45 
53  public void add(Shape o) {
54  list.add(o);
55  }
56 
62  public void remove(Shape o) {
63  list.remove(o);
64  }
65 
71  public ArrayList<Shape> getOutlines() {
72  return list;
73  }
74 
75  @Override
76  public boolean contains(double x, double y) {
77  for (Shape o : list) {
78  if (o.contains(x, y)) {
79  return true;
80  }
81  }
82  return false;
83  }
84 
85  @Override
86  public double getDistance(double x, double y) {
87  double diff = Double.POSITIVE_INFINITY;
88  for (Shape o : list) {
89  diff = Math.min(o.getDistance(x, y), diff);
90  }
91  return diff;
92  }
93 
94  @Override
95  protected Types getOutlineType() {
96  return Types.GROUP;
97  }
98 
102  @Override
103  protected void positionChanged() {
104  Vector diff = new Vector(previousLocation, p);
105  previousLocation.move(diff);
106  for (Shape o : list) {
107  o.move(diff);
108  }
109  }
110 
114  @Override
115  protected void angleChanged() {
116  rotate(angle - previousAngle);
117  previousAngle = angle;
118  }
119 
125  @Override
126  public void rotate(double diff) {
127  this.angle += diff;
128  Matrix m = new Matrix(diff);
129  for (Shape o : list) {
130  Vector d = new Vector(p, o.p);
131  Point p2 = new Point(p);
132  d = m.transform(d);
133  p2.move(d);
134  o.moveTo(p2);
135  o.setAngle(o.getAngle() + diff);
136  }
137  }
138 
139  @Override
140  public double getLeft() {
141  left = Double.POSITIVE_INFINITY;
142  double actLeft;
143  for (Shape o : list) {
144  actLeft = o.getLeft();
145  if (left > actLeft) {
146  left = actLeft;
147  }
148  }
149  return left;
150  }
151 
152  @Override
153  public double getRight() {
154  right = Double.NEGATIVE_INFINITY;
155  double actRight;
156  for (Shape o : list) {
157  actRight = o.getRight();
158  if (right < actRight) {
159  right = actRight;
160  }
161  }
162  return right;
163  }
164 
165  @Override
166  public double getBottom() {
167  bottom = Double.POSITIVE_INFINITY;
168  double actBottom;
169  for (Shape o : list) {
170  actBottom = o.getBottom();
171  if (bottom > actBottom) {
172  bottom = actBottom;
173  }
174  }
175  return bottom;
176  }
177 
178  @Override
179  public double getTop() {
180  top = Double.NEGATIVE_INFINITY;
181  double actTop;
182  for (Shape o : list) {
183  actTop = o.getTop();
184  if (top < actTop) {
185  top = actTop;
186  }
187  }
188  return top;
189  }
190 
191  @Override
192  public void draw(Picture picture) {
193  for (Shape o : list) {
194  picture.drawShape(o);
195  }
196  }
197 }
void drawShape(Shape shape)
Definition: Picture.java:451
Vector transform(Vector v)
Definition: Matrix.java:143
void move(double dX, double dY)
Definition: Point.java:130
double getDistance(double x, double y)
Definition: ShapeGroup.java:86
ArrayList< Shape > getOutlines()
Definition: ShapeGroup.java:71
boolean contains(double x, double y)
Definition: ShapeGroup.java:76
double angle
Drehwinkel.
Definition: Shape.java:59
double bottom
Untere Grenze.
Definition: Shape.java:47
double top
Obere Grenze.
Definition: Shape.java:55
double left
Linke Grenze.
Definition: Shape.java:43
double right
Rechte Grenze.
Definition: Shape.java:51
Impressum