Package com.nomagic.awt
Class ContainerShape
- java.lang.Object
-
- com.nomagic.awt.ContainerShape
-
@OpenApiAll public class ContainerShape extends java.lang.ObjectThis 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>mEllipsesprivate java.util.List<Line>mLinesprivate java.util.List<java.awt.Polygon>mPolygonsprivate java.util.List<java.awt.Rectangle>mRectanglesprivate 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 voidaddEllipse(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)voidaddShape(Line line)Add line.voidaddShape(java.awt.geom.RoundRectangle2D rect)Add rectangle shape.voidaddShape(java.awt.Polygon polygon)Add Polygon.voidaddShape(java.awt.Rectangle rect)Add rectangle shape.static ContainerShapecreatePolygonContainerShape(int[] x, int[] y)Creates container shape from polygon points.static ContainerShapecreatePolygonContainerShape(ContainerShape shape, int[] x, int[] y)Creates container shape from polygon points.private static java.awt.PointfindNearest(int ax, int ay, java.util.List<java.awt.Point> points)java.util.List<java.awt.Rectangle>getEllipses()Returns contained ellipsesjava.util.List<Line>getLines()Returns contained lines.java.util.List<java.awt.Polygon>getPolygons()Returns polygonsjava.util.List<java.awt.Rectangle>getRectangles()Returns contained rectangles.java.util.List<java.awt.geom.RoundRectangle2D>getRoundRectangles()Returns round rectanglesjava.awt.Pointintersection(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.Pointintersection(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)booleanintersects(java.awt.Rectangle bounds)Indicates if container shape intersects with specified bounds.private static booleanintersects(java.awt.Rectangle bounds, java.util.List<Line> lines)private booleanisCompositeShape()private static java.util.List<Line>toLines(java.awt.Polygon polygon)private static java.awt.PolygontoPolygon(java.awt.Shape shape)
-
-
-
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
-
-
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 lineay- first point of linebx- second point of lineby- 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)
-
-