Graphical Elements The goal of this assignment is to build a solid basis for 2-D graphics programming by implementing representations of colors and points. Additionally, you will gain experience implementing larger, more realistic interfaces with detailed—perhaps even fussy—requirements. Before writing code of your own, you will likely want to look over the code that is provided: One unusual thing about points is that multiple implementations of the same interface ( Additionally, you may want to review the documentation for the The first part of your task is to write the two points classes, The coordinates of The coordinates of If If If The goals here are twofold: When computing with We should not mix up In a file Be sure thoroughly test your implementation. In a file Be sure thoroughly test your implementation. Next, we will implement the interface In a file These six methods are closely related, and as such you should be able to avoid redundancy by having them delegate to each other as appropriate. More detailed specifications of these methods appear in the formatted documentation for class Note that because I wrote At this point, the tests in Use the 2 Getting Started
Boundable.java
(Javadoc) contains an interface for querying objects for their bounding boxes. (A bounding box is a rectangle that full encloses something.) You will need to implement this interface for your point classes. The bounding box of a point is the point—or in other words, all four corners of the box are the same as the point.BoundingBox.java
(Javadoc) contains an interface and implementation for working with bounding boxes. It is nearly complete, but for full functionality it depends on a point class that you will implement.Color.java
(Javadoc) contains an interface for working with RGBA colors, which you will implement.Interpolable.java
(Javadoc) contains interface Interpolable
, which supports linear interpolation between values in a space. You will implement this interface for points and for colors.Point.java
(Javadoc) contains an interface for computing with 2-D points. The interface is parametrized by the type of the coordinates, Double
or Integer
, though it is intended that Point<Double>
s be represented using unboxed double
s and Point<Integer>
s be represented using unboxed int
s. This is an unusual situation, since a generic class cannot use primitive value types based on its parameter; instead, we must be careful to construct only Point
values using the correct representations to match the returned type.Point<Integer>
or Point<Double>
) must compare equal if their components are equal, but no Point<Integer>
is equal to any Point<Double>
. When you implement int
and double
point classes, you will need to figure out how to make this work.pixel_buffer
framework.
pixel_buffer.jar
JAR file containing the compiled pixel_buffer framework and add it to your project’s classpath. Make sure that you can import classes from it. (As in Problem Set 5, how to do this will depend on your IDE, and help will be available on Piazza.)3 Your Task
3.1 Points
DoublePoint
(which implements Point<Double>
) and IntegerPoint
(which implements Point<Integer>
), which represent 2-D points or vectors. Both classes should be immutable and final
. These classes have several peculiar requirements:
DoublePoint
must be stored as double
s, so there is no conversion necessary to return them as double
s.IntegerPoint
must be stored as int
s, so there is no conversion necessary to return them as int
s.p1
and p2
are both Point<Double>
s, then p1.equals(p2)
when p1.x() == p2.x()
and p1.y() == p2.y()
, even if p1
and p2
are objects of different classes.p1
and p2
are both Point<Integer>
s, then p1.equals(p2)
when p1.x() == p2.x()
and p1.y() == p2.y()
, even if p1
and p2
are objects of different classes.p1
is a Point<Integer>
and p2
is a Point<Double>
, then it is never the case that p1.equals(p2)
or p2.equals(p1)
.
Point<Integer>
s (resp. Point<Double>
s), we should be able to mix and match concrete implementations of the same interface (with the same parameter) without noticing.Point<Integer>
s with Point<Double>
s, because they can give different results due to rounding.
DoublePoint.java
, write a class DoublePoint
(Javadoc) that implements the interface Point<Double>
. This class must define one public static factory method:
public Point<Double> point(double x, double y)
, which returns a DoublePoint
with the given coordinates.IntegerPoint.java
, write a class IntegerPoint
(Javadoc) that implements the interface Point<Integer>
. This class must define two public static factory methods:
public Point<Integer> point(int x, int y)
, which returns a IntegerPoint
with the given coordinates.public Point<Integer> point(double x, double y)
, which returns a IntegerPoint
with the given coordinates (but rounded with Math.round
).3.2 Colors
Color
(Javadoc). As with the point classes above, our implementation of Color
s will use static factories rather than public constructors, which gives the class more control over object creation and initialization. No public class implementing Color
is required—instead, you are free to define as many (non-public) classes as you like in order for your static factories to return Color
objects.
Colors.java
, write an uninstantiable class Colors
that defines the following public
items.
public static final Color TRANSPARENT
representing the fully transparent RGBA valuepublic static final Color BLACK
representing RGBA blackpublic static final Color WHITE
representing RGBA whiteColor
objects:
public static Color rgb(double, double, double)
constructs an opaque color object from 0.0-to-1.0 RGB componentspublic static Color rgba(double, double, double, double)
constructs a color object from 0.0-to-1.0 RGB components and an alpha componentpublic static Color rgb(int, int, int)
constructs an opaque color object from 0-to-255 RGB componentspublic static Color rgba(int, int, int, int)
constructs a color object from 0-to-255 RGB components and an alpha componentpublic static Color rgb(int)
constructs an opaque color object given a packed 24-bit RGB color valuepublic static Color rgba(int)
constructs a color object given a packed 32-bit RGBA color valueColors
. Don’t forget to test your implementation.Color
is an interface, your implementation of colors needs to interoperate with other classes that might implement Color
. In order to preserve your code’s invariants, you need to be careful not to trust the values returned by methods of Color
objects that your methods are passed, since they may be from an implementation other than yours.3.3 Bounding Boxes
BoundingBox.java
for you, except that several methods of class BoundingBox
currently throw an exception rather than returning the correct result, because the result depends on your implementation of Point<Double>
. Now that your implementation of class DoublePoint
is complete, BoundingBox
should be able to take advantage of it.
topLeft()
(line 99), topRight()
(line 104), bottomLeft()
(line 109), and bottomRight()
(line 114) to return the correct points,BoundingBoxTest.java
should pass using my BoundingBox
and your DoublePoint
. You need not write any additional BoundingBox
tests.3.4 Make a Pretty Picture
pixel_buffer
framework to write a program that renders something interesting to the screen. Can you do more interesting things by factoring out some functionality, and perhaps parameterizing it? If you make something especially neat, post a screen shot to Piazza.