diff --git a/src/shapes/Ellipse.java b/src/shapes/Ellipse.java index f8211e0..87a0d16 100644 --- a/src/shapes/Ellipse.java +++ b/src/shapes/Ellipse.java @@ -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; - } } diff --git a/src/shapes/Line.java b/src/shapes/Line.java index 4d977b8..d001d1a 100644 --- a/src/shapes/Line.java +++ b/src/shapes/Line.java @@ -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); } diff --git a/src/shapes/Shape.java b/src/shapes/Shape.java index e73f352..a8a0577 100644 --- a/src/shapes/Shape.java +++ b/src/shapes/Shape.java @@ -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; + } }