Class ContainerShape


  • @OpenApiAll
    public class ContainerShape
    extends java.lang.Object
    This shape can have rectangles, ellipses and lines. The shape form is the union of all contained shapes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.awt.Rectangle> mEllipses  
      private java.util.List<Line> mLines  
      private java.util.List<java.awt.Polygon> mPolygons  
      private java.util.List<java.awt.Rectangle> mRectangles  
      private java.util.List<java.awt.geom.RoundRectangle2D> mRoundRectangles  
    • Constructor Summary

      Constructors 
      Constructor Description
      ContainerShape()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEllipse​(java.awt.Rectangle el)
      Add ellipse.
      private static java.util.List<java.awt.Point> addLinesIntersectionPoints​(int ax, int ay, int bx, int by, java.util.List<Line> lines, java.util.List<java.awt.Point> points)  
      private static java.util.List<java.awt.Point> addPoint​(java.util.List<java.awt.Point> destination, java.awt.Point pt)  
      private static java.util.List<java.awt.Point> addRectangleIntersectionPoints​(int ax, int ay, int bx, int by, java.util.List<java.awt.Point> points, int x, int y, int width, int height)  
      void addShape​(Line line)
      Add line.
      void addShape​(java.awt.geom.RoundRectangle2D rect)
      Add rectangle shape.
      void addShape​(java.awt.Polygon polygon)
      Add Polygon.
      void addShape​(java.awt.Rectangle rect)
      Add rectangle shape.
      static ContainerShape createPolygonContainerShape​(int[] x, int[] y)
      Creates container shape from polygon points.
      static ContainerShape createPolygonContainerShape​(ContainerShape shape, int[] x, int[] y)
      Creates container shape from polygon points.
      private static java.awt.Point findNearest​(int ax, int ay, java.util.List<java.awt.Point> points)  
      java.util.List<java.awt.Rectangle> getEllipses()
      Returns contained ellipses
      java.util.List<Line> getLines()
      Returns contained lines.
      java.util.List<java.awt.Polygon> getPolygons()
      Returns polygons
      java.util.List<java.awt.Rectangle> getRectangles()
      Returns contained rectangles.
      java.util.List<java.awt.geom.RoundRectangle2D> getRoundRectangles()
      Returns round rectangles
      java.awt.Point intersection​(int ax, int ay, int bx, int by)
      Computes the intersection of this shape (intersection with any of contained shapes) with the specified line.
      java.awt.Point intersection​(java.awt.Point a, java.awt.Point b)  
      private java.util.List<java.awt.Point> intersectionWithCompositeShape​(int ax, int ay, int bx, int by)  
      private java.util.List<java.awt.Point> intersectionWithSingleShape​(int ax, int ay, int bx, int by)  
      boolean intersects​(java.awt.Rectangle bounds)
      Indicates if container shape intersects with specified bounds.
      private static boolean intersects​(java.awt.Rectangle bounds, java.util.List<Line> lines)  
      private boolean isCompositeShape()  
      private static java.util.List<Line> toLines​(java.awt.Polygon polygon)  
      private static java.awt.Polygon toPolygon​(java.awt.Shape shape)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mRectangles

        private java.util.List<java.awt.Rectangle> mRectangles
      • mPolygons

        private java.util.List<java.awt.Polygon> mPolygons
      • mRoundRectangles

        private java.util.List<java.awt.geom.RoundRectangle2D> mRoundRectangles
      • mLines

        private java.util.List<Line> mLines
      • mEllipses

        private java.util.List<java.awt.Rectangle> mEllipses
    • Constructor Detail

      • ContainerShape

        public ContainerShape()
    • Method Detail

      • intersection

        @CheckForNull
        public java.awt.Point intersection​(java.awt.Point a,
                                           java.awt.Point b)
      • intersection

        @CheckForNull
        public java.awt.Point intersection​(int ax,
                                           int ay,
                                           int bx,
                                           int by)
        Computes the intersection of this shape (intersection with any of contained shapes) with the specified line. Returns a new point that represents the intersection of two shapes.
        Parameters:
        ax - first point of line
        ay - first point of line
        bx - second point of line
        by - second point of line
        Returns:
        the shapes intersection point
      • isCompositeShape

        private boolean isCompositeShape()
      • intersectionWithSingleShape

        @CheckForNull
        private java.util.List<java.awt.Point> intersectionWithSingleShape​(int ax,
                                                                           int ay,
                                                                           int bx,
                                                                           int by)
      • intersectionWithCompositeShape

        @CheckForNull
        private java.util.List<java.awt.Point> intersectionWithCompositeShape​(int ax,
                                                                              int ay,
                                                                              int bx,
                                                                              int by)
      • findNearest

        @CheckForNull
        private static java.awt.Point findNearest​(int ax,
                                                  int ay,
                                                  @CheckForNull
                                                  java.util.List<java.awt.Point> points)
      • addLinesIntersectionPoints

        @CheckForNull
        private static java.util.List<java.awt.Point> addLinesIntersectionPoints​(int ax,
                                                                                 int ay,
                                                                                 int bx,
                                                                                 int by,
                                                                                 @CheckForNull
                                                                                 java.util.List<Line> lines,
                                                                                 @CheckForNull
                                                                                 java.util.List<java.awt.Point> points)
      • addRectangleIntersectionPoints

        @CheckForNull
        private static java.util.List<java.awt.Point> addRectangleIntersectionPoints​(int ax,
                                                                                     int ay,
                                                                                     int bx,
                                                                                     int by,
                                                                                     @CheckForNull
                                                                                     java.util.List<java.awt.Point> points,
                                                                                     int x,
                                                                                     int y,
                                                                                     int width,
                                                                                     int height)
      • addPoint

        @CheckForNull
        private static java.util.List<java.awt.Point> addPoint​(@CheckForNull
                                                               java.util.List<java.awt.Point> destination,
                                                               @CheckForNull
                                                               java.awt.Point pt)
      • addShape

        public void addShape​(java.awt.Rectangle rect)
        Add rectangle shape.
      • addShape

        public void addShape​(java.awt.geom.RoundRectangle2D rect)
        Add rectangle shape.
      • addShape

        public void addShape​(Line line)
        Add line.
      • addEllipse

        public void addEllipse​(java.awt.Rectangle el)
        Add ellipse.
      • addShape

        public void addShape​(java.awt.Polygon polygon)
        Add Polygon.
      • getEllipses

        public java.util.List<java.awt.Rectangle> getEllipses()
        Returns contained ellipses
        Returns:
        ellipses
      • getRectangles

        public java.util.List<java.awt.Rectangle> getRectangles()
        Returns contained rectangles.
        Returns:
        rectangle
      • getLines

        public java.util.List<Line> getLines()
        Returns contained lines.
        Returns:
        lines
      • getRoundRectangles

        public java.util.List<java.awt.geom.RoundRectangle2D> getRoundRectangles()
        Returns round rectangles
        Returns:
        round rectangles
      • getPolygons

        public java.util.List<java.awt.Polygon> getPolygons()
        Returns polygons
        Returns:
        polygons
      • createPolygonContainerShape

        public static ContainerShape createPolygonContainerShape​(int[] x,
                                                                 int[] y)
        Creates container shape from polygon points.
        Parameters:
        x - array of x coordinates.
        y - array of y coordinates.
        Returns:
        created container shape.
      • createPolygonContainerShape

        public static ContainerShape createPolygonContainerShape​(ContainerShape shape,
                                                                 int[] x,
                                                                 int[] y)
        Creates container shape from polygon points.
        Parameters:
        shape - container shape to modify.
        x - array of x coordinates.
        y - array of y coordinates.
        Returns:
        created container shape.
      • intersects

        public boolean intersects​(java.awt.Rectangle bounds)
        Indicates if container shape intersects with specified bounds.
        Parameters:
        bounds - bounds to check.
        Returns:
        true if container shape intersects with specified bounds, false otherwise.
      • toLines

        private static java.util.List<Line> toLines​(java.awt.Polygon polygon)
      • toPolygon

        private static java.awt.Polygon toPolygon​(java.awt.Shape shape)
      • intersects

        private static boolean intersects​(java.awt.Rectangle bounds,
                                          @CheckForNull
                                          java.util.List<Line> lines)