Class Edge2D


  • public class Edge2D
    extends Object
    The edge of a rectangle, i.e. a vertical or horizontal line segment.
    • Constructor Detail

      • Edge2D

        public Edge2D​(Point2D centerPoint,
                      Orientation orientation,
                      double length)
        Creates a new edge which is specified by its center point, orientation and length.
        Parameters:
        centerPoint - the edge's center point
        orientation - the edge's orientation
        length - the edge's length; must be non-negative.
    • Method Detail

      • getUpperLeft

        public Point2D getUpperLeft()
        Returns the edge's upper left end point. It has (length / 2) distance from the center point and depending on the edge's orientation either the same X (for Orientation.HORIZONTAL) or Y (for Orientation.VERTICAL) coordinate.
        Returns:
        the edge's upper left point
      • getLowerRight

        public Point2D getLowerRight()
        Returns the edge's lower right end point. It has (length / 2) distance from the center point and depending on the edge's orientation either the same X (for Orientation.HORIZONTAL) or Y (for Orientation.VERTICAL) coordinate.
        Returns:
        the edge's lower right point
      • getOrthogonalDifference

        public double getOrthogonalDifference​(Point2D otherPoint)
        Returns the distance of the specified point to the edge in terms of the dimension orthogonal to the edge's orientation. The sign denotes whether on which side of the edge, the point lies.
        So e.g. if the edge is horizontal, only the Y coordinate's difference between the specified point and the edge is considered. If the point lies to the right of the edge, the returned value is positive.
        Parameters:
        otherPoint - the point to where the distance is computed
        Returns:
        the distance
      • getCenterPoint

        public Point2D getCenterPoint()
        Returns:
        the edge's center point
      • getOrientation

        public Orientation getOrientation()
        Returns this edge's orientation. Note that the orientation can also be checked with isHorizontal() and isVertical().
        Returns:
        the edge's orientation
      • getLength

        public double getLength()
        Returns:
        the edge's length
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object