edu.rit.draw.item
Class Point
- java.lang.Object
-
- edu.rit.draw.item.Point
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Point extends java.lang.Object implements java.io.ExternalizableClass Point provides an (x,y) point on a drawing. Operations are provided for doing arithmetic on points.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Point()Construct a new point at location (0,0).Point(double x, double y)Construct a new point at location (x,y).Point(Point thePoint)Construct a new point at the same location as the given point.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description SizeabsDifference(Point thePoint)Returns a Size object representing the absolute difference between this point and the given point.Pointadd(double dx, double dy)Returns a new point at the given offsets from this point.Pointadd(Size theSize)Returns a new point at the given width and height away from this point.Sizedifference(Point thePoint)Returns a Size object representing the difference between this point and the given point.Pointe(double distance)Returns a new point that is the given distance east of this point.Pointe(Size theSize)Returns a new point that is the given distance east of this point.booleanequals(java.lang.Object obj)Determine if this point is equal to the given object.inthashCode()Returns a hash code for this point.Pointmax(Point thePoint)Returns a new point that is the maximum of this point and the given point.Pointmin(Point thePoint)Returns a new point that is the minimum of this point and the given point.Pointn(double distance)Returns a new point that is the given distance north of this point.Pointn(Size theSize)Returns a new point that is the given distance north of this point.voidreadExternal(java.io.ObjectInput in)Read this point from the given object input stream.Points(double distance)Returns a new point that is the given distance south of this point.Points(Size theSize)Returns a new point that is the given distance south of this point.Pointsub(double dx, double dy)Returns a new point at the given offsets from this point.Pointsub(Size theSize)Returns a new point at the given width and height away from this point.java.lang.StringtoString()Returns a string version of this point.Pointw(double distance)Returns a new point that is the given distance west of this point.Pointw(Size theSize)Returns a new point that is the given distance east of this point.voidwriteExternal(java.io.ObjectOutput out)Write this point to the given object output stream.doublex()Returns this point's X coordinate.doubley()Returns this point's Y coordinate.
-
-
-
Constructor Detail
-
Point
public Point()
Construct a new point at location (0,0).
-
Point
public Point(double x, double y)Construct a new point at location (x,y).- Parameters:
x- X coordinate.y- Y coordinate.
-
Point
public Point(Point thePoint)
Construct a new point at the same location as the given point.- Parameters:
thePoint- Point to copy.
-
-
Method Detail
-
x
public double x()
Returns this point's X coordinate.
-
y
public double y()
Returns this point's Y coordinate.
-
add
public Point add(double dx, double dy)
Returns a new point at the given offsets from this point.- Parameters:
dx- X offset; added to this point's X coordinate.dy- Y offset; added to this point's Y coordinate.
-
add
public Point add(Size theSize)
Returns a new point at the given width and height away from this point. theSize's width is added to this point's X coordinate. theSize's height is added to this point's Y coordinate.- Parameters:
theSize- Size object containing width and height.
-
sub
public Point sub(double dx, double dy)
Returns a new point at the given offsets from this point.- Parameters:
dx- X offset; subtracted from this point's X coordinate.dy- Y offset; subtracted from this point's Y coordinate.
-
sub
public Point sub(Size theSize)
Returns a new point at the given width and height away from this point. theSize's width is subtracted from this point's X coordinate. theSize's height is subtracted from this point's Y coordinate.- Parameters:
theSize- Size object containing width and height.
-
difference
public Size difference(Point thePoint)
Returns a Size object representing the difference between this point and the given point. The size object's width is this point's X coordinate minus thePoint's X coordinate. The size object's height is this point's Y coordinate minus thePoint's Y coordinate.- Parameters:
thePoint- Point object.
-
absDifference
public Size absDifference(Point thePoint)
Returns a Size object representing the absolute difference between this point and the given point. The size object's width is the absolute value of this point's X coordinate minus thePoint's X coordinate. The size object's height is the absolute value of this point's Y coordinate minus thePoint's Y coordinate.- Parameters:
thePoint- Point object.
-
max
public Point max(Point thePoint)
Returns a new point that is the maximum of this point and the given point. Each coordinate of the returned point is the maximum of the corresponding coordinates of this point and thePoint.- Parameters:
thePoint- Point object.
-
min
public Point min(Point thePoint)
Returns a new point that is the minimum of this point and the given point. Each coordinate of the returned point is the minimum of the corresponding coordinates of this point and thePoint.- Parameters:
thePoint- Point object.
-
n
public Point n(double distance)
Returns a new point that is the given distance north of this point. The new point's X coordinate is the same as this point's X coordinate. The new point's Y coordinate is this point's Y coordinate minus distance.- Parameters:
distance- Distance of new point from this point.
-
s
public Point s(double distance)
Returns a new point that is the given distance south of this point. The new point's X coordinate is the same as this point's X coordinate. The new point's Y coordinate is this point's Y coordinate plus distance.- Parameters:
distance- Distance of new point from this point.
-
e
public Point e(double distance)
Returns a new point that is the given distance east of this point. The new point's X coordinate is this point's X coordinate plus distance. The new point's Y coordinate is the same as this point's Y coordinate.- Parameters:
distance- Distance of new point from this point.
-
w
public Point w(double distance)
Returns a new point that is the given distance west of this point. The new point's X coordinate is this point's X coordinate minus distance. The new point's Y coordinate is the same as this point's Y coordinate.- Parameters:
distance- Distance of new point from this point.
-
n
public Point n(Size theSize)
Returns a new point that is the given distance north of this point. The new point's X coordinate is the same as this point's X coordinate. The new point's Y coordinate is this point's Y coordinate minus theSize.height().- Parameters:
theSize- Distance of new point from this point = theSize.height().
-
s
public Point s(Size theSize)
Returns a new point that is the given distance south of this point. The new point's X coordinate is the same as this point's X coordinate. The new point's Y coordinate is this point's Y coordinate plus theSize.height().- Parameters:
theSize- Distance of new point from this point = theSize.height().
-
e
public Point e(Size theSize)
Returns a new point that is the given distance east of this point. The new point's X coordinate is this point's X coordinate plus theSize.width(). The new point's Y coordinate is the same as this point's Y coordinate.- Parameters:
theSize- Distance of new point from this point = theSize.width().
-
w
public Point w(Size theSize)
Returns a new point that is the given distance east of this point. The new point's X coordinate is this point's X coordinate minus theSize.width(). The new point's Y coordinate is the same as this point's Y coordinate.- Parameters:
theSize- Distance of new point from this point = theSize.width().
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this point to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOExceptionRead this point from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
equals
public boolean equals(java.lang.Object obj)
Determine if this point is equal to the given object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- Object to test.- Returns:
- True if this point is equal to obj, false otherwise.
-
hashCode
public int hashCode()
Returns a hash code for this point.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string version of this point.- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG