cse1030.drawing

## Class Point2D

• ```public final class Point2D
extends Object```
A class that represents two dimensional points. A `Point2D` has an x and a y coordinate.
Author:
CSE1030
• ### Constructor Summary

Constructors
Constructor and Description
`Point2D()`
Creates a point with coordinates `(0.0, 0.0)`.
```Point2D(double x, double y)```
Creates a point with coordinates `(x, y)`.
`Point2D(Point2D other)`
Creates a point that has the same coordinates as another point.
• ### Method Summary

Methods
Modifier and Type Method and Description
`static Point2D` ```add(Point2D p, Vector2D v)```
Returns a new point equal to `p + v`.
`Point2D` `add(Vector2D v)`
Add a vector to this point changing the coordinates of this point.
`boolean` `equals(Object obj)`
Compare this point to another object for equality.
`double` `getX()`
Get the x coordinate point.
`double` `getY()`
Get the y coordinate of the point.
`int` `hashCode()`
Computes a hash code for this point.
`void` `setX(double x)`
Set the x coordinate of the point.
`void` `setY(double y)`
Set the y coordinate of the point.
`boolean` ```similarTo(Point2D other, double tol)```
Checks if another point is similar to this point.
`String` `toString()`
Returns a string representation of the point.
• ### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Point2D

`public Point2D()`
Creates a point with coordinates `(0.0, 0.0)`.
• #### Point2D

`public Point2D(Point2D other)`
Creates a point that has the same coordinates as another point.
Parameters:
`other` - the `Point2D` object to copy
• #### Point2D

```public Point2D(double x,
double y)```
Creates a point with coordinates `(x, y)`.
• ### Method Detail

• #### getX

`public double getX()`
Get the x coordinate point.
Returns:
the x coordinate of the point
• #### setX

`public void setX(double x)`
Set the x coordinate of the point.
Parameters:
`x` - the new value for the x coordinate
• #### getY

`public double getY()`
Get the y coordinate of the point.
Returns:
the y coordinate of the point
• #### setY

`public void setY(double y)`
Set the y coordinate of the point.
Parameters:
`y` - the new value for the y coordinate
• #### hashCode

`public int hashCode()`
Computes a hash code for this point.
Overrides:
`hashCode` in class `Object`
Returns:
a hash code for this point
• #### equals

`public boolean equals(Object obj)`
Compare this point to another object for equality. The result is `true` if and only if the argument is not `null` and is a `Point2D` object having the same coordinates as this point.
Overrides:
`equals` in class `Object`
Parameters:
`obj` - the object to compare this point against
Returns:
`true` if the given object represents a `Point2D` equivalent to this point, `false` otherwise

`public Point2D add(Vector2D v)`
Add a vector to this point changing the coordinates of this point.

Mathematically, if this point is `p` and the vector is `v` then invoking this method is equivalent to computing `p + v` and assigning the value back to `p`.

Parameters:
`v` - the vector to add to this point
Returns:
this `Point2D` object

```public static Point2D add(Point2D p,
Vector2D v)```
Returns a new point equal to `p + v`.
Parameters:
`p` - a point
`v` - a vector
Returns:
a new `Point2D` equal to `p + v`
• #### toString

`public String toString()`
Returns a string representation of the point. The returned string has the form:

`(X, Y)` where `X` is the x coordinate of the point and `Y` is the y coordinate of the point.

Overrides:
`toString` in class `Object`
Returns:
a string representation of the point
• #### similarTo

```public boolean similarTo(Point2D other,
double tol)```
Checks if another point is similar to this point. Two points are considered similar if the distance between the points is less than or equal to a specified tolerance.
Parameters:
`other` - the point to compare for similarity
`tol` - the distance within which the two points are considered to be similar
Returns:
`true` if the distance between the points is less than or equal to `tol`, `false` otherwise.