Class Viewport


  • public class Viewport
    extends java.lang.Object
    Rectangular region in a two-dimensional coordinate system expressed as an origin and dimensions extending from the origin.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      The viewport's height.
      int width
      The viewport's width.
      int x
      The X component of the viewport's origin.
      int y
      The Y component of the viewport's origin.
    • Constructor Summary

      Constructors 
      Constructor Description
      Viewport()
      Constructs an empty viewport width X, Y, width and height all zero.
      Viewport​(int x, int y, int width, int height)
      Constructs a viewport with a specified origin and dimensions.
      Viewport​(Viewport viewport)
      Constructs a viewport with the origin and dimensions of a specified viewport.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(int x, int y)
      Indicates whether this viewport contains a specified point.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean intersect​(int x, int y, int width, int height)
      Computes the intersection of this viewport and a specified viewport, storing the result in this viewport and returning whether or not the viewport intersect.
      boolean intersect​(Viewport viewport)
      Computes the intersection of this viewport and a specified viewport, storing the result in this viewport and returning whether or not the viewport intersect.
      boolean intersects​(int x, int y, int width, int height)
      Indicates whether this viewport intersects a specified viewport.
      boolean intersects​(Viewport viewport)
      Indicates whether this viewport intersects a specified viewport.
      boolean isEmpty()
      Indicates whether or not this viewport is empty.
      Viewport set​(int x, int y, int width, int height)
      Sets this viewport to the specified origin and dimensions.
      Viewport set​(Viewport viewport)
      Sets this viewport to the origin and dimensions of a specified viewport.
      Viewport setEmpty()
      Sets this viewport to an empty viewport.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • x

        public int x
        The X component of the viewport's origin.
      • y

        public int y
        The Y component of the viewport's origin.
      • width

        public int width
        The viewport's width.
      • height

        public int height
        The viewport's height.
    • Constructor Detail

      • Viewport

        public Viewport()
        Constructs an empty viewport width X, Y, width and height all zero.
      • Viewport

        public Viewport​(int x,
                        int y,
                        int width,
                        int height)
        Constructs a viewport with a specified origin and dimensions.
        Parameters:
        x - the X component of the viewport's lower left corner
        y - the Y component of the viewport's lower left corner
        width - the viewport's width
        height - the viewport's height
      • Viewport

        public Viewport​(Viewport viewport)
        Constructs a viewport with the origin and dimensions of a specified viewport.
        Parameters:
        viewport - the viewport specifying the values
        Throws:
        java.lang.IllegalArgumentException - If the viewport is null
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • set

        public Viewport set​(int x,
                            int y,
                            int width,
                            int height)
        Sets this viewport to the specified origin and dimensions.
        Parameters:
        x - the new X component of the viewport's lower left corner
        y - the new Y component of the viewport's lower left corner
        width - the viewport's new width
        height - the viewport's new height
        Returns:
        this viewport set to the specified values
      • set

        public Viewport set​(Viewport viewport)
        Sets this viewport to the origin and dimensions of a specified viewport.
        Parameters:
        viewport - the viewport specifying the new values
        Returns:
        this viewport with its origin and dimensions set to that of the specified viewport
        Throws:
        java.lang.IllegalArgumentException - If the viewport is null
      • setEmpty

        public Viewport setEmpty()
        Sets this viewport to an empty viewport.
        Returns:
        this viewport with its width and height both set to zero
      • isEmpty

        public boolean isEmpty()
        Indicates whether or not this viewport is empty. An viewport is empty when either its width or its height are zero (or negative).
        Returns:
        true if this viewport is empty, false otherwise
      • intersects

        public boolean intersects​(int x,
                                  int y,
                                  int width,
                                  int height)
        Indicates whether this viewport intersects a specified viewport. Two viewport intersect when both overlap by a non-zero amount. An empty viewport never intersects another viewport.
        Parameters:
        x - the X component of the viewport to test intersection with
        y - the Y component of the viewport to test intersection with
        width - the viewport width to test intersection with
        height - the viewport height to test intersection with
        Returns:
        true if the specified viewport intersections this viewport, false otherwise
      • intersects

        public boolean intersects​(Viewport viewport)
        Indicates whether this viewport intersects a specified viewport. Two viewport intersect when both overlap by a non-zero amount. An empty viewport never intersects another viewport.
        Parameters:
        viewport - the viewport to test intersection with
        Returns:
        true if the specified viewport intersections this viewport, false otherwise
        Throws:
        java.lang.IllegalArgumentException - If the viewport is null
      • intersect

        public boolean intersect​(int x,
                                 int y,
                                 int width,
                                 int height)
        Computes the intersection of this viewport and a specified viewport, storing the result in this viewport and returning whether or not the viewport intersect. Two viewport intersect when both overlap by a non-zero amount. An empty viewport never intersects another viewport.
        When there is no intersection, this returns false and leaves this viewport unchanged. To test for intersection without modifying this viewport, use intersects(int, int, int, int).
        Parameters:
        x - the X component of the viewport to intersect with
        y - the Y component of the viewport to intersect with
        width - the viewport width to intersect with
        height - the viewport height to intersect with
        Returns:
        this true if this viewport intersects the specified viewport, false otherwise
      • intersect

        public boolean intersect​(Viewport viewport)
        Computes the intersection of this viewport and a specified viewport, storing the result in this viewport and returning whether or not the viewport intersect. Two viewport intersect when both overlap by a non-zero amount. An empty viewport never intersects another viewport.
        When there is no intersection, this returns false and leaves this viewport unchanged. To test for intersection without modifying this viewport, use intersects(int, int, int, int).
        Parameters:
        viewport - the viewport to intersect with
        Returns:
        this true if this viewport intersects the specified viewport, false otherwise
        Throws:
        java.lang.IllegalArgumentException - If the viewport is null
      • contains

        public boolean contains​(int x,
                                int y)
        Indicates whether this viewport contains a specified point. An empty viewport never contains a point.
        Parameters:
        x - the point's X component
        y - the point's Y component
        Returns:
        true if this viewport contains the point, false otherwise