Class Point

java.lang.Object
net.regsirius06.engine.point.Point
Direct Known Subclasses:
ColoredPoint, Player

public class Point extends Object
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
    Modifier and Type
    Field
    Description
    protected double
    Represents the x-coordinate of this point in a 2D Cartesian coordinate system.
    protected double
    Represents the y-coordinate of this point in a 2D Cartesian coordinate system.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Point(double x, double y)
    Constructs a new Point with the specified x and y coordinates.
    Point(@NotNull Point point)
    Constructs a new Point by copying the coordinates of another Point.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    angleTo(double x, double y)
    Calculates the angle in radians between this Point and another point specified by the x and y coordinates.
    <P extends Point>
    double
    angleTo(P p)
    Calculates the angle in radians between this Point and another point.
    double
    distanceTo(double x, double y)
    Calculates the Euclidean distance from this Point to another point specified by the x and y coordinates.
    <P extends Point>
    double
    Calculates the Euclidean distance from this Point to another point.
    boolean
    Checks if this Point is equal to another object.
    Returns a new Point object that has the same x and y coordinates as this point.
    double
    Returns the x coordinate of this Point.
    double
    Returns the y coordinate of this Point.
    int
    Returns a hash code for this Point.
    boolean
    isPointInside(double x, double y)
    Checks if the given coordinates x and y are equal to this Point's coordinates.
    <P extends Point>
    boolean
    Checks if the given point p has the same coordinates as this Point.
    movePoint(double x, double y)
    Moves this Point by the given x and y offsets.
    movePoint(@NotNull Point point)
    Moves this Point by the given coordinates of another Point.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      protected double x
      Represents the x-coordinate of this point in a 2D Cartesian coordinate system. This value is immutable once the point is created.
    • y

      protected double y
      Represents 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 new Point with the specified x and y coordinates.
      Parameters:
      x - the x coordinate of the point
      y - the y coordinate of the point
    • Point

      public Point(@NotNull @NotNull Point point)
      Constructs a new Point by copying the coordinates of another Point.
      Parameters:
      point - the Point to copy coordinates from
  • Method Details

    • getX

      public double getX()
      Returns the x coordinate of this Point.
      Returns:
      the x coordinate
    • getY

      public double getY()
      Returns the y coordinate of this Point.
      Returns:
      the y coordinate
    • getPoint

      public Point getPoint()
      Returns a new Point object that has the same x and y coordinates as this point.
      Returns:
      a new Point with identical coordinates to this point
    • isPointInside

      public <P extends Point> boolean isPointInside(@NotNull P p)
      Checks if the given point p has the same coordinates as this Point. This method compares the x and y coordinates of both points.
      Type Parameters:
      P - the type of the point, which must extend Point
      Parameters:
      p - the point to compare with
      Returns:
      true if the coordinates of p are the same as this point's coordinates, false otherwise
    • isPointInside

      public boolean isPointInside(double x, double y)
      Checks if the given coordinates x and y are equal to this Point's coordinates.
      Parameters:
      x - the x coordinate of the point to compare
      y - the y coordinate of the point to compare
      Returns:
      true if the coordinates match, false otherwise
    • distanceTo

      public double distanceTo(double x, double y)
      Calculates the Euclidean distance from this Point to another point specified by the x and y coordinates. The distance is calculated as the square root of the sum of the squared differences between the respective coordinates.
      Parameters:
      x - the x coordinate of the other point
      y - the y coordinate of the other point
      Returns:
      the Euclidean distance between this point and the given coordinates
    • distanceTo

      public <P extends Point> double distanceTo(@NotNull P p)
      Calculates the Euclidean distance from this Point to 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 extend Point
      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 this Point and another point specified by the x and y coordinates. The angle is measured from the positive x-axis. Positive angles indicate counterclockwise rotation, while negative angles indicate clockwise rotation.
      Parameters:
      x - the x coordinate of the target point
      y - the y coordinate of the target point
      Returns:
      the angle in radians from this point to the specified point
    • angleTo

      public <P extends Point> double angleTo(@NotNull P p)
      Calculates the angle in radians between this Point and another point. The angle is measured from the positive x-axis. Positive angles indicate counterclockwise rotation, while negative angles indicate clockwise rotation.
      Type Parameters:
      P - the type of the point, which must extend Point
      Parameters:
      p - the target point
      Returns:
      the angle in radians from this point to the specified point
    • movePoint

      public Point movePoint(@NotNull @NotNull Point point)
      Moves this Point by the given coordinates of another Point. This method returns a new Point object with the new location.
      Parameters:
      point - the point whose coordinates will be used to move this point
      Returns:
      a new Point located at the new position after the move
    • movePoint

      public Point movePoint(double x, double y)
      Moves this Point by the given x and y offsets. This method returns a new Point object with the new location.
      Parameters:
      x - the x offset to move by
      y - the y offset to move by
      Returns:
      a new Point located at the new position after the move
    • equals

      public boolean equals(Object o)
      Checks if this Point is equal to another object. Two points are considered equal if both their x and y coordinates are the same.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare this point with
      Returns:
      true if the object is a Point with the same coordinates, false otherwise
    • hashCode

      public int hashCode()
      Returns a hash code for this Point. The hash code is based on the x and y coordinates of the point.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code for this point