kopia lustrzana https://github.com/jameshball/osci-render
Changed shape to abstract class to reduce code duplication
rodzic
dd24a19447
commit
a55f57163c
|
@ -1,10 +1,8 @@
|
|||
package shapes;
|
||||
|
||||
public class Ellipse implements Shape {
|
||||
public class Ellipse extends Shape {
|
||||
private final double a;
|
||||
private final double b;
|
||||
private final double weight;
|
||||
private final double length;
|
||||
private final double rotation;
|
||||
private final Vector position;
|
||||
|
||||
|
@ -15,7 +13,7 @@ public class Ellipse implements Shape {
|
|||
this.rotation = rotation;
|
||||
this.position = position;
|
||||
// Approximation of length.
|
||||
this.length = 2 * Math.PI * Math.sqrt((this.a * this.a + this.b * this.b) / 2);
|
||||
this.length = 2 * Math.PI * Math.sqrt((a * a + b * b) / 2);
|
||||
}
|
||||
|
||||
public Ellipse(double a, double b, Vector position) {
|
||||
|
@ -58,14 +56,4 @@ public class Ellipse implements Shape {
|
|||
public Shape translate(Vector vector) {
|
||||
return new Ellipse(a, b, weight, rotation, position.add(vector));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package shapes;
|
||||
|
||||
public class Line implements Shape {
|
||||
public class Line extends Shape {
|
||||
private final Vector a;
|
||||
private final Vector b;
|
||||
private final double weight;
|
||||
|
||||
// Storing the length to save on repeat calculations.
|
||||
private final double length;
|
||||
|
||||
public static final double DEFAULT_WEIGHT = 100;
|
||||
|
||||
|
@ -102,16 +98,6 @@ public class Line implements Shape {
|
|||
return new Line(getX1(), getY1(), getX2(), y2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public Line setWeight(double weight) {
|
||||
return new Line(getX1(), getY1(), getX2(), getY2(), weight);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
package shapes;
|
||||
|
||||
public interface Shape {
|
||||
float nextX(double drawingProgress);
|
||||
float nextY(double drawingProgress);
|
||||
Shape rotate(double theta);
|
||||
Shape scale(double factor);
|
||||
Shape translate(Vector vector);
|
||||
double getWeight();
|
||||
double getLength();
|
||||
public abstract class Shape {
|
||||
protected double weight;
|
||||
protected double length;
|
||||
|
||||
public abstract float nextX(double drawingProgress);
|
||||
public abstract float nextY(double drawingProgress);
|
||||
public abstract Shape rotate(double theta);
|
||||
public abstract Shape scale(double factor);
|
||||
public abstract Shape translate(Vector vector);
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public double getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue