Class Polygon
- java.lang.Object
-
- com.attivio.sdk.geo.Shape
-
- com.attivio.sdk.geo.AbstractPolygon
-
- com.attivio.sdk.geo.Polygon
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<Shape>
public final class Polygon extends AbstractPolygon
Defines a polygon.Given a list of points, the polygon is the area inside the figure created by joining each pair of adjacent points by a line segment. The first and last points are also joined; you do not need to repeat the first point in order to close the polygon.
A polygon whose edges cross each other may have unpredictable behavior. A point exactly on the edge of a polygon may fall inside or outside the polygon unpredictably. A point very close to an edge may seem to fall in the wrong area because of implications of floating-point arithmetic.
WARNING: this API is experimental and will likely change in the near future.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addArguments(java.lang.StringBuilder buffer)
void
addPoint(double x, double y)
Add a point to this polygon.void
addPoint(Point point)
Add a point to this polygon.void
clear()
Remove all points from this polygon.Polygon
clone()
boolean
contains(double x, double y)
Return true if a point is contained inside this filter's polygon.boolean
equals(java.lang.Object other)
double
fastGetX(int index)
Get the X coordinate of the Point atindex
.double
fastGetY(int index)
Get the Y coordinate of the Point atindex
.boolean
fastIntersects(Rectangle box)
Check if this shape's bounding box intersects withbox
.Rectangle
getBoundingBox()
Get the rectangle that represents the bounding box that fully contains this shape.double
getHeight()
Get the height of this shape's bounding box.java.util.List<Point>
getPoints()
java.lang.String
getTypeName()
double
getWidth()
Get the width of this shape's bounding box.int
hashCode()
boolean
lineIntersects(double x1, double y1, double x2, double y2)
Check if the line (x1, y1), (x2, y2) intersects with this polygon.Polygon
readExternal(java.io.DataInput in)
void
setPoints(java.util.List<Point> points)
int
size()
Return the number of vertices in this polygon.void
toString(java.lang.StringBuilder buffer, int i)
void
writeExternal(java.io.DataOutput out)
-
Methods inherited from class com.attivio.sdk.geo.AbstractPolygon
getPoint, getPointX, getPointY, intersects, intersects
-
Methods inherited from class com.attivio.sdk.geo.Shape
compareTo, contains, intersects, readExternal, toString, toString, toString, valueOf, writeExternal
-
-
-
-
Constructor Detail
-
Polygon
public Polygon()
Constructs a polygon with default vertex capacity.
-
Polygon
public Polygon(Point... points)
-
Polygon
public Polygon(java.util.List<Point> points)
-
Polygon
public Polygon(int capacity)
Constructs a polygon with specified capacity.- Parameters:
capacity
- the vertex capacity
-
-
Method Detail
-
getTypeName
public java.lang.String getTypeName()
- Specified by:
getTypeName
in classShape
-
size
public int size()
Return the number of vertices in this polygon.- Specified by:
size
in classAbstractPolygon
-
clear
public void clear()
Remove all points from this polygon.
-
getPoints
public java.util.List<Point> getPoints()
-
setPoints
public void setPoints(java.util.List<Point> points)
-
fastGetX
public double fastGetX(int index)
Get the X coordinate of the Point atindex
.WARNING: this method assumes that
index
is positive and less thanAbstractPolygon.size()
.- Specified by:
fastGetX
in classAbstractPolygon
-
fastGetY
public double fastGetY(int index)
Get the Y coordinate of the Point atindex
.WARNING: this method assumes that
index
is positive and less thanAbstractPolygon.size()
.- Specified by:
fastGetY
in classAbstractPolygon
-
addPoint
public void addPoint(Point point)
Add a point to this polygon.
-
addPoint
public void addPoint(double x, double y)
Add a point to this polygon.
-
getWidth
public double getWidth()
Get the width of this shape's bounding box.
-
getHeight
public double getHeight()
Get the height of this shape's bounding box.
-
getBoundingBox
public Rectangle getBoundingBox()
Get the rectangle that represents the bounding box that fully contains this shape.- Specified by:
getBoundingBox
in classShape
-
fastIntersects
public boolean fastIntersects(Rectangle box)
Check if this shape's bounding box intersects withbox
.- Specified by:
fastIntersects
in classShape
-
contains
public final boolean contains(double x, double y)
Return true if a point is contained inside this filter's polygon.
-
lineIntersects
public boolean lineIntersects(double x1, double y1, double x2, double y2)
Check if the line (x1, y1), (x2, y2) intersects with this polygon.- Specified by:
lineIntersects
in classAbstractPolygon
-
addArguments
public void addArguments(java.lang.StringBuilder buffer)
- Specified by:
addArguments
in classShape
-
toString
public void toString(java.lang.StringBuilder buffer, int i)
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
writeExternal
public void writeExternal(java.io.DataOutput out) throws java.io.IOException
- Specified by:
writeExternal
in classShape
- Throws:
java.io.IOException
-
readExternal
public Polygon readExternal(java.io.DataInput in) throws java.io.IOException
- Specified by:
readExternal
in classShape
- Throws:
java.io.IOException
-
-