this.things.add(new Barrier(this.sheet.createRectangle(new PointRW(500,
100), new DimensionRW(600, 50), false, this)));
this.things.add(new Barrier(this.sheet.createRectangle(new PointRW(500,
- 400), new DimensionRW(600, 50), false, this)));
+ 400), new DimensionRW(600, 270), false, this)));
this.things.add(new Barrier(this.sheet.createRectangle(new PointRW(500,
700), new DimensionRW(600, 50), false, this)));
this.firstIndexMovables = this.things.size();
PointRW destination = new PointRW(0, 0);
- for (int ix = 0; ix < 20; ix++) {
+ for (int ix = 0; ix < 2; ix++) {
Movable movable = new Movable(this.sheet.createRectangle(
new PointRW(500, 500), new DimensionRW(10, 10), true, this));
movable.getWidget().setCenter(openPosition());
|| this.widget.getWidgetType() == WidgetType.XCROSS)
rc = rectangle.intersects(this.widget.getContour());
else
- assert false;
+ throw new RuntimeException(
+ "Barrier.clashes(RectangleRW): not implemented yet");
return rc;
}
if (this.widget instanceof RectangleRW)
rc = thing.clashes((RectangleRW) this.widget);
else
- assert false;
+ throw new RuntimeException(
+ "Barrier.clashes(ThingRW): not implemented yet");
return rc;
}
*/
protected void checkCollision(Movable movable, int lastIndex) {
// we use the contour of the assigned widget:
+ if (lastIndex > 3 && movable.getWidget().getCenter().y > 300)
+ lastIndex += 1;
for (int ix = 0; ix < lastIndex; ix++) {
ThingRW thing = this.things.get(ix);
if (movable.clashes(thing)) {
if (current != exclude) {
RectangleRW contour = current.widget.getContour();
if (point.x >= contour.x && point.y >= contour.y
- && point.x < contour.x + contour.width
- && point.y < contour.y + contour.height) {
+ && point.x < contour.x + contour.width
+ && point.y < contour.y + contour.height) {
rc = current;
break;
}
do {
rc.x = this.region.x + this.random.nextDouble() * this.region.width;
rc.y = this.region.x + this.random.nextDouble()
- * this.region.height;
+ * this.region.height;
} while (occupied(rc, null) != null);
return rc;
}
public boolean clashes(RectangleRW rectangle) {
boolean rc = false;
if (this.widget.getWidgetType() == WidgetType.RECTANGLE
- || this.widget.getWidgetType() == WidgetType.XCROSS)
+ || this.widget.getWidgetType() == WidgetType.XCROSS)
rc = this.widget.getContour().intersects(rectangle);
else
- assert false;
+ throw new RuntimeException(
+ "Movable.clashes(RectangleRW): not implemented yet");
+ ;
return rc;
}
public boolean clashes(ThingRW thing) {
boolean rc = false;
if (this.widget.getWidgetType() == WidgetType.RECTANGLE
- || this.widget.getWidgetType() == WidgetType.XCROSS)
+ || this.widget.getWidgetType() == WidgetType.XCROSS)
rc = thing.clashes(this.widget.getContour());
else
- assert false;
+ throw new RuntimeException(
+ "Movable.clashes(ThingRW): not implemented yet");
return rc;
}
* @param point
* OUT: the calculated current position
* @param currentTime
- * < 0: relative to the starttime (negated)<br>
+ * < 0: relative to the start time (negated)<br>
* otherwise: the current time in milliseconds
*/
public void currentPosition(PointRW point, long currentTime) {
- if (this.getVelocity() == 0.0) {
- point.x = this.widget.getCenter().x;
- point.y = this.widget.getCenter().y;
- } else {
+ if (this.getVelocity() == 0.0)
+ point.clone(this.widget.getCenter());
+ else {
+ if (this.startTime == 0)
+ this.startTime = this.model.getNow();
if (currentTime < 0)
currentTime = this.startTime - currentTime;
// v = s / t => s = v * t
/**
* x coordinate (horizontal)
*/
- public double x;
+ public double x = 0;
/**
* y coordinate (vertical)
*/
- public double y;
+ public double y = 0;
/**
* Constructor.
*/
public boolean inside(double x, double y) {
boolean rc = x >= this.x && x < this.x + this.width && y >= this.y
- && y < this.y + this.height;
+ && y < this.y + this.height;
return rc;
}
*/
public boolean inside(PointRW point) {
boolean rc = point.x >= this.x && point.x < this.x + this.width
- && point.y >= this.y && point.y < this.y + this.height;
- return rc;
+ && point.y >= this.y && point.y < this.y + this.height;
+ return rc;
}
/**
// inside of the
// instance:
boolean rc = inside(rectangle.x, rectangle.y)
- || inside(rectangle.x + RectangleRW.NEAR_1 * rectangle.width,
- rectangle.y)
- || inside(rectangle.x, rectangle.y + RectangleRW.NEAR_1
- * rectangle.height)
- || inside(rectangle.x + RectangleRW.NEAR_1 * rectangle.width,
- rectangle.y + RectangleRW.NEAR_1 * rectangle.height);
+ || inside(rectangle.x + RectangleRW.NEAR_1 * rectangle.width,
+ rectangle.y)
+ || inside(rectangle.x, rectangle.y + RectangleRW.NEAR_1
+ * rectangle.height)
+ || inside(rectangle.x + RectangleRW.NEAR_1 * rectangle.width,
+ rectangle.y + RectangleRW.NEAR_1 * rectangle.height);
return rc;
}
/**
* the first point of the line
*/
- private PointRW from;
+ private PointRW from = new PointRW(0, 0);
/**
* the last point of the line
*/
- private PointRW to;
+ private PointRW to = new PointRW(0, 0);;
/**
* Constructor.
*/
public LineSwing(PointRW from, PointRW to, Model model) {
super(from, model);
- this.from = from;
- this.to = to;
+ this.from.clone(from);
+ this.to.clone(to);
}
@Override
@Override
public void paintComponent(Graphics graphics) {
-
super.paintComponent(graphics);
doDrawing(graphics);
}
*
*/
public class RectangleSwing extends WidgetSwing {
- private DimensionRW dimension = null;
+ private DimensionRW dimension = new DimensionRW(0, 0);
private boolean filled = false;
public RectangleSwing(PointRW center, DimensionRW dimension,
boolean filled, Model model) {
super(center, model);
- this.dimension = dimension;
+ this.dimension.clone(dimension);
this.filled = filled;
calculateContour();
}
this.title = title;
this.model = model;
this.timer = new Timer(100, this);
- this.timer.setInitialDelay(2000);
+ this.timer.setInitialDelay(200);
model.setSheet(this);
initUI();
}
* The center of the item in real world coordinates. This simply allows
* calculating distance between 2 items.
*/
- protected PointRW center;
+ protected PointRW center = new PointRW(0, 0);
/**
* The smallest rectangle containing all parts of the item (in real world
* coordinates).
* simulator model
*/
public WidgetSwing(PointRW center, Model model) {
- this.center = center;
+ this.center.clone(center);
this.model = model;
model.getItems().add(this);
}
@Override
public void setCenter(PointRW center) {
- this.center.x = center.x;
- this.center.y = center.y;
+ this.center.clone(center);
calculateContour();
}
}
this.model.transform(this.contour, this.contourSwing);
graphics.drawLine(this.contourSwing.x, this.contourSwing.y,
this.contourSwing.x + this.contourSwing.width, this.contourSwing.y
- + this.contourSwing.height);
+ + this.contourSwing.height);
graphics.drawLine(this.contourSwing.x + this.contourSwing.width,
this.contourSwing.y, this.contourSwing.x, this.contourSwing.y
- + this.contourSwing.height);
+ + this.contourSwing.height);
}
@Override