Class JavaRectangle2D

    • Constructor Detail

      • JavaRectangle2D

        public JavaRectangle2D​(JavaPoint2D topLeft,
                               JavaPoint2D bottomRight)
        Parameters:
        topLeft - top left point of the rectangle
        bottomRight - bottom right point of the rectangle
      • JavaRectangle2D

        public JavaRectangle2D​(JavaPoint2D topLeft,
                               double width,
                               double height)
        this(topLeft, new JavaPoint(topLeft.getX() + width, topLeft.getY() + height))
        Parameters:
        topLeft - top left point of the rectangle
        width - width of the rectangle
        height - height of the rectangle
      • JavaRectangle2D

        public JavaRectangle2D​(int x1,
                               int y1,
                               int x2,
                               int y2)
        Parameters:
        x1 - x-coordinate top left point of the rectangle
        y1 - y-coordinate top left point of the rectangle
        x2 - x-coordinate bottom right point of the rectangle
        y2 - y-coordinate bottom right point of the rectangle
      • JavaRectangle2D

        public JavaRectangle2D​(double x1,
                               double y1,
                               double x2,
                               double y2)
        Parameters:
        x1 - x-coordinate top left point of the rectangle
        y1 - y-coordinate top left point of the rectangle
        x2 - x-coordinate bottom right point of the rectangle
        y2 - y-coordinate bottom right point of the rectangle
      • JavaRectangle2D

        protected JavaRectangle2D()
        Empty constructor for deriving classes
    • Method Detail

      • getIntersection

        public static Optional<JavaRectangle2D> getIntersection​(JavaRectangle2D rect1,
                                                                JavaRectangle2D rect2)
        Method that calculates the intersection rectangle of two rectangles.
        Parameters:
        rect1 - the first rectangle
        rect2 - the second rectangle
        Returns:
        the intersection rectangle if there is an intersection else Optional.empty
      • touchingSide

        public static Optional<Side> touchingSide​(JavaRectangle2D rect1,
                                                  JavaRectangle2D rect2)
        Method which checks if two rectangles which are not equal or overlapping are touching each other
        Parameters:
        rect1 - rect 1
        rect2 - rect 2
        Returns:
        The side of rect 1 where rect2 is touching or an empty optional iff not touching/equal/overlapping
      • createRectangle

        public static JavaRectangle2D createRectangle​(double x1,
                                                      double y1,
                                                      double x2,
                                                      double y2)
        Comfort method for creating an rectangle from any x and y points. The correct coordinates are determined for JavaRectangleRotated2D.getTopLeft() and JavaRectangleRotated2D.getBottomRight()
        Parameters:
        x1 - any first x coordinate
        y1 - any first y coordinate
        x2 - any second x coordinate
        y2 - any second y coordinate
        Returns:
        a JavaRectangle
      • createBoundingBox

        public static JavaRectangle2D createBoundingBox​(Collection<JavaPoint2D> jps)
        Creates a bounding box for a given set of java points
        Parameters:
        jps - the list of points
        Returns:
        the bounding box of the java points
        Throws:
        IllegalArgumentException - if the collection is empty
      • setTopLeft

        public void setTopLeft​(JavaPoint2D topLeft)
        Sets the top left point of the rectangle. This mutates the current rectangle!
        Parameters:
        topLeft - the new top left point of the rectangle
      • setBottomRight

        public void setBottomRight​(JavaPoint2D bottomRight)
        Sets the bottom right point of the rectangle. This mutates the current rectangle!
        Parameters:
        bottomRight - the new bottom right point of the rectangle
      • containsJavaPoint

        public boolean containsJavaPoint​(JavaPoint2D javaPoint2D)
        Checks if a point in contained in the rectangle. so if it is inside or on the boundaries.
        Overrides:
        containsJavaPoint in class JavaRectangleRotated2D
        Parameters:
        javaPoint2D - the point to be checked
        Returns:
        true if contained, else false
      • getNormalvector

        public JavaPoint2D getNormalvector()