Class Obstacle

All Implemented Interfaces:
Shape, Serializable, Cloneable

public class Obstacle extends Rectangle2D.Double
See Also:
  • Field Details

    • topLeft

      public Translation2d topLeft
    • topRight

      public Translation2d topRight
    • bottomLeft

      public Translation2d bottomLeft
    • bottomRight

      public Translation2d bottomRight
    • topLeftAvailable

      public boolean topLeftAvailable
    • topRightAvailable

      public boolean topRightAvailable
    • bottomLeftAvailable

      public boolean bottomLeftAvailable
    • bottomRightAvailable

      public boolean bottomRightAvailable
    • defaultTopLeft

      public boolean defaultTopLeft
    • defaultTopRight

      public boolean defaultTopRight
    • defaultBottomLeft

      public boolean defaultBottomLeft
    • defaultBottomRight

      public boolean defaultBottomRight
    • name

      public String name
  • Constructor Details

    • Obstacle

      public Obstacle(double x, double y, double width, double height, String name)
      Creates an obstacle, represented by an Axis-Aligned Bounding Box.
      Parameters:
      x - CenterX of the obstacle
      y - CenterY of the obstacle
      width - width (x) of the obstacle
      height - height (y) of the obstacle
      name - name
  • Method Details

    • getName

      public String getName()
    • getCenter

      public Translation2d getCenter()
    • resetCorners

      public void resetCorners()
      Sets the corners back to default availability.
    • getDistanceToCenter

      public double getDistanceToCenter(Translation2d other)
      Gets the distance between the center of this obstacle and a given point.
      Parameters:
      other - The given point
      Returns:
      distance to that point from the center of the obstacle.
    • getIntersectionAveragePoint

      public Translation2d getIntersectionAveragePoint(Translation2d start, Translation2d end)
      Finds the two intersection points of a line that passes through this obstacle, and averages them together.
      Parameters:
      start - Line x1,y1
      end - Line x2,y2
      Returns:
      The average intersection point, or null if there is no intersection point.
    • getLineIntersectionPoint

      public Translation2d getLineIntersectionPoint(Translation2d lineA1, Translation2d lineA2, Translation2d lineB1, Translation2d lineB2)
      Calculates the intersection point of two line segments. Copied from https://stackoverflow.com/questions/40314303/java-find-intersection-of-line-and-rectangle
      Parameters:
      lineA1 - Line A x1,y1
      lineA2 - Line A x2,y2
      lineB1 - Line B x1,y1
      lineB2 - Line B x2,y2
      Returns:
      0,0 if the segments do not intersect.
    • getLineIntersectionPoint

      public Translation2d getLineIntersectionPoint(Line2D.Double lineA, Line2D.Double lineB)
    • doesPointLieAlongMidlines

      public boolean doesPointLieAlongMidlines(Translation2d point)
    • getParallelCrossingType

      public Obstacle.ParallelCrossingType getParallelCrossingType(Translation2d point)
    • getClosestCornerToPoint

      public Translation2d getClosestCornerToPoint(Translation2d other)
      Finds the closest available corner of this obstacle from a given point. Once it returns a point, that point is unavailable until resetCorners() is called.
      Parameters:
      other - The point to measure from
      Returns:
      The closest corner, or 0,0 if no corner is found.
      See Also:
    • restoreCorner

      public void restoreCorner(Translation2d corner)
    • getBonusOffset

      public double getBonusOffset()
    • setBonusOffset

      public void setBonusOffset(double bonusOffset)
    • movePointOutsideOfBounds

      public Translation2d movePointOutsideOfBounds(Translation2d point)
    • getPointProjectionCombination

      public Obstacle.PointProjectionCombination getPointProjectionCombination(Translation2d first, Translation2d second, Obstacle.ParallelCrossingType crossingType)
    • checkXCombination

      public Obstacle.PointProjectionCombination checkXCombination(Translation2d first, Translation2d second)
    • checkYCombination

      public Obstacle.PointProjectionCombination checkYCombination(Translation2d first, Translation2d second)
    • absorbObstacle

      public void absorbObstacle(Obstacle other)
    • findClosestPointOnPerimeterToPoint

      public double findClosestPointOnPerimeterToPoint(Translation2d point)