EOS 2  1.1.0
Einfache Objektbasierte Sprache
Line.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.math.Point;
8 import de.lathanda.eos.base.math.Vector;
9 import de.lathanda.eos.base.layout.Transform;
10 import static java.lang.Math.*;
16 public class Line extends LineFigure {
17  private double length;
18  public Line() {
19  super();
20  // (-10,10) -> (10, -10)
21  this.length = sqrt(800);
22  transform = transform.setAngle(-PI/4d);
23  line.setDrawWidth(0.5f);
24  }
25 
26  @Override
27  protected void drawObject(Picture p) {
28  p.drawLine(-length/2, 0, length/2, 0);
29  }
30  @Override
31  protected void scaleInternal(double factor) {
32  length *= factor;
33  }
34 
35  public void setX1(double x) {
36  TrueLine t = this.new TrueLine();
37  t.A.setX(x);
38  t.writeBack();
40  }
41 
42  public double getX1() {
43  TrueLine t = this.new TrueLine();
44  return t.A.getX();
45  }
46 
47  public void setX2(double x) {
48  TrueLine t = this.new TrueLine();
49  t.B.setX(x);
50  t.writeBack();
52  }
53 
54  public double getX2() {
55  TrueLine t = this.new TrueLine();
56  return t.B.getX();
57  }
58  public void setY1(double y) {
59  TrueLine t = this.new TrueLine();
60  t.A.setY(y);
61  t.writeBack();
63  }
64 
65  public double getY1() {
66  TrueLine t = this.new TrueLine();
67  return t.A.getY();
68  }
69 
70  public void setY2(double y) {
71  TrueLine t = this.new TrueLine();
72  t.B.setY(y);
73  t.writeBack();
75  }
76 
77  public double getY2() {
78  TrueLine t = this.new TrueLine();
79  return t.B.getY();
80  }
81 
82  public void setPoint1(double x, double y) {
83  TrueLine t = this.new TrueLine();
84  t.A = new Point(x, y);
85  t.writeBack();
87  }
88 
89  public void setPoint2(double x, double y) {
90  TrueLine t = this.new TrueLine();
91  t.B = new Point(x, y);
92  t.writeBack();
94  }
95 
96  public void setPoints(double x1, double y1, double x2, double y2) {
97  TrueLine t = this.new TrueLine();
98  t.A = new Point(x1, y1);
99  t.B = new Point(x2, y2);
100  t.writeBack();
101  fireDataChanged();
102  }
103  @Override
104  public Figure copy() {
105  Line line = (Line)super.copy();
106  return line;
107  }
108  private class TrueLine {
109  Point A;
110  Point B;
111  TrueLine() {
112  A = getTransformedPosition(new Point(-length/2d, 0));
113  B = getTransformedPosition(new Point( length/2d, 0));
114  }
115  void writeBack() {
117  Vector v = new Vector(A, B);
118  length = v.getLength();
119  transform = transform.setTranslation((A.getX()+B.getX())/2,(A.getY()+B.getY())/2);
120  transform = transform.rotate(v.getAngle());
121  }
122  }
123 
124  @Override
126  return new BalancePoint(length*line.getDrawWidth(), getX(), getY());
127  }
128  @Override
130  Transform t = base.transform(own);
131  BoundingBox bound = new BoundingBox();
132  bound.add(t.transform(-length/2d, 0));
133  bound.add(t.transform( length/2d, 0));
134  return bound;
135  }
136  public double getLength() {
137  return length;
138  }
139 }
abstract void drawLine(double x1, double y1, double x2, double y2)
Geometrische Transformation.
Definition: Transform.java:13
Transform rotate(double angle)
Definition: Transform.java:34
Transform setAngle(double angle)
Definition: Transform.java:162
Transform setTranslation(double dx, double dy)
Definition: Transform.java:134
Transform transform(Transform child)
Definition: Transform.java:83
Point getTransformedPosition(Point point)
Definition: Figure.java:220
void setY2(double y)
Definition: Line.java:70
void setPoints(double x1, double y1, double x2, double y2)
Definition: Line.java:96
BoundingBox calculateBoundingBox(Transform base, Transform own)
Definition: Line.java:129
void setX2(double x)
Definition: Line.java:47
void setPoint1(double x, double y)
Definition: Line.java:82
void setY1(double y)
Definition: Line.java:58
void setX1(double x)
Definition: Line.java:35
BalancePoint getBalancePoint()
Definition: Line.java:125
void drawObject(Picture p)
Definition: Line.java:27
void scaleInternal(double factor)
Definition: Line.java:31
void setPoint2(double x, double y)
Definition: Line.java:89
Impressum