Package net.regsirius06.engine.point
Class Point
java.lang.Object
net.regsirius06.engine.point.Point
- Direct Known Subclasses:
ColoredPoint,Player
The
Point class represents a point in a 2D Cartesian coordinate system with x and y coordinates.
This class provides various methods for geometric operations such as calculating the Euclidean distance, angle between
two points, moving a point by certain offsets, and comparing points for equality.
It is particularly useful for applications like pathfinding, maze generation, or any other tasks that require 2D point manipulation.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleangleTo(double x, double y) Calculates the angle in radians between thisPointand another point specified by thexandycoordinates.<P extends Point>
doubleangleTo(P p) Calculates the angle in radians between thisPointand another point.doubledistanceTo(double x, double y) Calculates the Euclidean distance from thisPointto another point specified by thexandycoordinates.<P extends Point>
doubledistanceTo(P p) Calculates the Euclidean distance from thisPointto another point.booleanChecks if thisPointis equal to another object.getPoint()Returns a newPointobject that has the samexandycoordinates as this point.doublegetX()Returns thexcoordinate of thisPoint.doublegetY()Returns theycoordinate of thisPoint.inthashCode()Returns a hash code for thisPoint.booleanisPointInside(double x, double y) Checks if the given coordinatesxandyare equal to thisPoint's coordinates.<P extends Point>
booleanisPointInside(P p) Checks if the given pointphas the same coordinates as thisPoint.movePoint(double x, double y) Moves thisPointby the givenxandyoffsets.Moves thisPointby the given coordinates of anotherPoint.
-
Field Details
-
x
protected double xRepresents the x-coordinate of this point in a 2D Cartesian coordinate system. This value is immutable once the point is created. -
y
protected double yRepresents the y-coordinate of this point in a 2D Cartesian coordinate system. This value is immutable once the point is created.
-
-
Constructor Details
-
Point
public Point(double x, double y) Constructs a newPointwith the specifiedxandycoordinates.- Parameters:
x- thexcoordinate of the pointy- theycoordinate of the point
-
Point
Constructs a newPointby copying the coordinates of anotherPoint.- Parameters:
point- thePointto copy coordinates from
-
-
Method Details
-
getX
public double getX()Returns thexcoordinate of thisPoint.- Returns:
- the
xcoordinate
-
getY
public double getY()Returns theycoordinate of thisPoint.- Returns:
- the
ycoordinate
-
getPoint
Returns a newPointobject that has the samexandycoordinates as this point.- Returns:
- a new
Pointwith identical coordinates to this point
-
isPointInside
Checks if the given pointphas the same coordinates as thisPoint. This method compares thexandycoordinates of both points.- Type Parameters:
P- the type of the point, which must extendPoint- Parameters:
p- the point to compare with- Returns:
trueif the coordinates ofpare the same as this point's coordinates,falseotherwise
-
isPointInside
public boolean isPointInside(double x, double y) Checks if the given coordinatesxandyare equal to thisPoint's coordinates.- Parameters:
x- thexcoordinate of the point to comparey- theycoordinate of the point to compare- Returns:
trueif the coordinates match,falseotherwise
-
distanceTo
public double distanceTo(double x, double y) Calculates the Euclidean distance from thisPointto another point specified by thexandycoordinates. The distance is calculated as the square root of the sum of the squared differences between the respective coordinates.- Parameters:
x- thexcoordinate of the other pointy- theycoordinate of the other point- Returns:
- the Euclidean distance between this point and the given coordinates
-
distanceTo
Calculates the Euclidean distance from thisPointto another point. The distance is calculated as the square root of the sum of the squared differences between the respective coordinates.- Type Parameters:
P- the type of the point, which must extendPoint- Parameters:
p- the other point to compare with- Returns:
- the Euclidean distance between this point and the given
Point
-
angleTo
public double angleTo(double x, double y) Calculates the angle in radians between thisPointand another point specified by thexandycoordinates. The angle is measured from the positivex-axis. Positive angles indicate counterclockwise rotation, while negative angles indicate clockwise rotation.- Parameters:
x- thexcoordinate of the target pointy- theycoordinate of the target point- Returns:
- the angle in radians from this point to the specified point
-
angleTo
Calculates the angle in radians between thisPointand another point. The angle is measured from the positivex-axis. Positive angles indicate counterclockwise rotation, while negative angles indicate clockwise rotation.- Type Parameters:
P- the type of the point, which must extendPoint- Parameters:
p- the target point- Returns:
- the angle in radians from this point to the specified point
-
movePoint
Moves thisPointby the given coordinates of anotherPoint. This method returns a newPointobject with the new location.- Parameters:
point- the point whose coordinates will be used to move this point- Returns:
- a new
Pointlocated at the new position after the move
-
movePoint
Moves thisPointby the givenxandyoffsets. This method returns a newPointobject with the new location.- Parameters:
x- thexoffset to move byy- theyoffset to move by- Returns:
- a new
Pointlocated at the new position after the move
-
equals
Checks if thisPointis equal to another object. Two points are considered equal if both theirxandycoordinates are the same. -
hashCode
public int hashCode()Returns a hash code for thisPoint. The hash code is based on thexandycoordinates of the point.
-