1package de.ur.mi.oop.graphics;
3import de.ur.mi.oop.app.GraphicsApp;
4import de.ur.mi.oop.colors.Color;
10 private float xEndPoint;
11 private float yEndPoint;
22 public Line(
float startX,
float startY,
float endX,
float endY,
Color color) {
23 super(startX, startY, color);
24 this.xEndPoint = endX;
25 this.yEndPoint = endY;
41 public Line(
float startX,
float startY,
float endX,
float endY,
Color color,
float lineWidth) {
42 this(startX, startY, endX, endY, color);
83 float deltaX = Math.abs(
getXPos() - xEndPoint);
84 float deltaY = Math.abs(
getYPos() - yEndPoint);
85 return (
float) Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
89 return super.getXPos();
93 return super.getYPos();
97 return this.xEndPoint;
101 return this.yEndPoint;
105 super.setPosition(xStartPoint, yStartPoint);
113 this.xEndPoint = xEndPoint;
114 this.yEndPoint = yEndPoint;
122 super.setColor(newColor);
126 public void move(
float dx,
float dy) {
127 this.
setStartPoint(super.getXPos() + dx, super.getXPos() + dy);
128 this.
setEndPoint(this.xEndPoint + dx, this.yEndPoint + dy);
132 if (x < super.getXPos()) {
133 if (super.getXPos() <
this.xEndPoint) {
134 this.xEndPoint = x + (this.xEndPoint - super.getXPos());
137 super.setXPos(x + (super.getXPos() -
this.xEndPoint));
140 }
else if (super.getXPos() < this.xEndPoint) {
141 this.xEndPoint = x + (this.xEndPoint - super.getXPos());
144 super.setXPos(x + (super.getXPos() - this.xEndPoint));
148 if (y < super.getYPos()) {
149 if (super.getYPos() < this.yEndPoint) {
150 this.yEndPoint = y + (this.yEndPoint - super.getYPos());
153 super.setYPos(y + (super.getYPos() - this.yEndPoint));
156 }
else if (super.getYPos() < this.yEndPoint) {
157 this.yEndPoint = y + (this.yEndPoint - super.getYPos());
160 super.setYPos(y + (super.getYPos() - this.yEndPoint));
178 public void setStartAndEndPoint(
float toStartPointX,
float toStartPointY,
float toEndPointX,
float toEndPointY) {
184 return Math.max(super.getXPos(),
this.xEndPoint);
188 return Math.min(super.getXPos(),
this.xEndPoint);
192 return Math.min(super.getYPos(),
this.yEndPoint);
196 return Math.max(super.getYPos(),
this.yEndPoint);
static GraphicsApp getApp()
void setBorderColor(Color color)
Line(float startX, float startY, float endX, float endY, Color color)
void setLineWidth(float lineWidth)
void setStartAndEndPoint(float toStartPointX, float toStartPointY, float toEndPointX, float toEndPointY)
void setStartPoint(Point start)
Line(Point start, Point end, Color color, float lineWidth)
void setColor(Color newColor)
void setStartPoint(float xStartPoint, float yStartPoint)
void move(float dx, float dy)
void setPosition(Point p)
void setEndPoint(float xEndPoint, float yEndPoint)
void setPosition(float x, float y)
Line(float startX, float startY, float endX, float endY, Color color, float lineWidth)
Line(Point start, Point end, Color color)
void setEndPoint(Point end)