// Shape.java // Abstract class for geometric shapes. // Provides a number of non-abstract methods // Written by THC for CS 5 HW 3. Modified by Scot Drysdale to // use for VoronoiTool import java.awt.*; import java.awt.geom.Point2D; public abstract class Shape implements Drawable { private Color color; // Shape's color public Shape(Color initColor) { color = initColor; } public Shape() { color = Color.black; } // Get the Shape's color. public Color getColor() { return color; } // Set the Shape's color. public void setColor(Color newColor) { color = newColor; } // Draw this shape on page public abstract void draw(Graphics page); // returns the distance squared from Point p to this segment public double euclideanSq(Point2D p) { return euclideanSq(p.getX(), p.getY()); } // Compute the Euclidean distance between this shape and point (x, y) public abstract double euclideanSq(double x, double y); // returns the L_1 distance from Point p to this segment public double lOne(Point2D p) { return lOne(p.getX(), p.getY()); } // Compute the L_1 distance between this shape and point (x, y) public abstract double lOne(double x, double y); // Computes the reciprocal of the aspect-ratio distance to the point p2. // (This avoids problems with infinity, but reverses normal tests) public double aspectRatioRecip(Point2D p) { return aspectRatioRecip(p.getX(), p.getY()); } // Computes the reciprocal of the aspect-ratio distance to point (x, y). // (This avoids problems with infinity, but reverses normal tests) public abstract double aspectRatioRecip(double x, double y); // Computes the cosine of the angle between the point (x,y) and the // endpoints of this shape public abstract double findCosOfAngle(double x, double y); // Translate the shape by (deltaX, deltaY) public abstract void move(double deltaX, double deltaY, Point2D clickPoint); // Rotate the shape 45 degrees around the origin and scale by sqrt(2) public abstract Shape rotate(); // Returns true if the shape is entirely contained in the rectangle public abstract boolean isContained(Rect r); }