public class Polygon extends Object implements Shape, Serializable
Polygon类封装了坐标空间内封闭的二维区域的描述。
该区域由任意数量的线段限定,每个线段是多边形的一侧。
在内部,多边形包括的列表的(x,y)坐标对,其中每对限定所述多边形的一个顶点 ,以及两个连续的对是一条线,是多边形的边的端点。
(x,y)点的第一个和最后一对由一个关闭多边形的线段连接起来。
这个Polygon被定义为偶数绕组规则。
关于偶数绕组规则的定义,请参见WIND_EVEN_ODD 。
这个类的命中测试方法,其中包括contains , intersects和inside方法,用在描述的内部性定义Shape类评论。
Shape , Serialized Form
| Modifier and Type | Field and Description |
|---|---|
protected Rectangle |
bounds
这个
Polygon的界限。
|
int |
npoints
总分数。
|
int[] |
xpoints
X坐标数组。
|
int[] |
ypoints
Y坐标数组。
|
| Constructor and Description |
|---|
Polygon()
创建一个空多边形。
|
Polygon(int[] xpoints, int[] ypoints, int npoints)
构造并初始化一个
Polygon从指定的参数。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPoint(int x, int y)
将指定的坐标附加到此
Polygon 。
|
boolean |
contains(double x, double y)
测试指定坐标的对象的边界内
Shape ,如所描述的
definition of insideness 。
|
boolean |
contains(double x, double y, double w, double h)
测试
Shape的内部
Shape完全包含指定的矩形区域。
|
boolean |
contains(int x, int y)
确定指定的坐标是否在这个
Polygon 。
|
boolean |
contains(Point p)
确定指定是否 Point是这里面Polygon 。
|
boolean |
contains(Point2D p)
测试指定 Point2D是的边界内Shape ,如所描述的definition of insideness 。
|
boolean |
contains(Rectangle2D r)
测试
Shape的内部
Shape全部包含指定的
Rectangle2D 。
|
Rectangle |
getBoundingBox()
已弃用
从JDK 1.1版开始,替换为
getBounds() 。
|
Rectangle |
getBounds()
获取这个
Polygon的边框。
|
Rectangle2D |
getBounds2D()
Shape比
getBounds方法返回一个高精度和更精确的边界框。
|
PathIterator |
getPathIterator(AffineTransform at)
返回一个迭代器对象,它沿着这个
Polygon的边界进行迭代,并提供对这个
Polygon的轮廓几何的访问。
|
PathIterator |
getPathIterator(AffineTransform at, double flatness)
返回迭代器对象沿的边界进行迭代
Shape ,并提供访问的轮廓的几何
Shape 。
|
boolean |
inside(int x, int y)
已弃用
从JDK 1.1版开始,由
contains(int, int) 。
|
boolean |
intersects(double x, double y, double w, double h)
测试,如果内部
Shape相交的指定矩形区域的内部。
|
boolean |
intersects(Rectangle2D r)
如果测试的内部
Shape相交指定的内部
Rectangle2D 。
|
void |
invalidate()
无效或刷新任何取决于此
Polygon的顶点坐标的内部缓存数据。
|
void |
reset()
将此
Polygon对象重置为空多边形。
|
void |
translate(int deltaX, int deltaY)
平移的顶点
Polygon由
deltaX沿x轴和由
deltaY沿y轴。
|
public int npoints
addPoint(int, int)
public int[] xpoints
Polygon中的X坐标数。
额外的元素允许将新点添加到此Polygon而不重新创建此数组。
npoints的值等于此Polygon中有效点的Polygon 。
addPoint(int, int)
public int[] ypoints
Polygon中的Y坐标数。
额外的元素允许将新点添加到此Polygon而不重新创建此数组。
npoints的值等npoints中有效点的Polygon 。
addPoint(int, int)
protected Rectangle bounds
Polygon的界限。
该值可以为null。
getBoundingBox() ,
getBounds()
public Polygon()
public Polygon(int[] xpoints,
int[] ypoints,
int npoints)
Polygon从指定的参数。
xpoints - X坐标数组
ypoints - 一个Y坐标数组
npoints -点的总数
Polygon
NegativeArraySizeException - 如果
npoints值为负数。
IndexOutOfBoundsException -如果
npoints比的长度大
xpoints或长度
ypoints 。
NullPointerException - 如果
xpoints或
ypoints是
null 。
public void reset()
Polygon对象重置为空多边形。
坐标数组及其中的数据保持不变,但将点数重置为零,以将旧顶点数据标记为无效,并开始在开始时累积新的顶点数据。
与旧顶点相关的所有内部缓存数据都将被丢弃。
请注意,由于复位之前的坐标数组被重新使用,如果新的多边形数据中的顶点数量明显小于数据中的顶点数量,则创建新的空Polygon可能会比重置当前的多个数据时更高的内存效率复位前。
invalidate()
public void invalidate()
Polygon的顶点坐标的任何内部缓存的数据。
在任何直接操纵xpoints或ypoints阵列中的xpoints之后,应该调用此方法,以避免诸如getBounds或contains之类的方法的不一致结果,这些方法可能会从与顶点坐标相关的较早计算中缓存数据。
getBounds()
public void translate(int deltaX,
int deltaY)
Polygon由
deltaX沿x轴和由
deltaY沿y轴。
deltaX - 沿X轴平移的数量
deltaY - 沿Y轴平移的量
public void addPoint(int x,
int y)
Polygon 。
如果这个计算的边界框的操作Polygon已经执行,如getBounds或contains ,则此方法更新边界框。
x - 指定的X坐标
y - 指定的Y坐标
getBounds() ,
contains(java.awt.Point)
public Rectangle getBounds()
Polygon的边框。
边框是最小的Rectangle ,它们的边平行于坐标空间的x和y轴,并且可以完全包含Polygon 。
getBounds在界面
Shape
Rectangle定义了这个
Polygon的界限。
Shape.getBounds2D()
@Deprecated public Rectangle getBoundingBox()
getBounds() 。
Polygon的范围。
Polygon的界限。
public boolean contains(Point p)
Point是这里面Polygon 。
p - 要测试的指定的
Point
true如果Polygon包含Point ;
false否则。
contains(double, double)
public boolean contains(int x,
int y)
Polygon 。
x - 要测试的指定X坐标
y - 要测试的指定Y坐标
true如果这个Polygon包含指定的坐标(x,y) ;
false否则。
contains(double, double)
@Deprecated public boolean inside(int x, int y)
contains(int, int) 。
Polygon 。
x - 要测试的指定X坐标
y - 要测试的指定Y坐标
true如果这个Polygon包含指定的坐标(x,y) ;
false否则。
contains(double, double)
public Rectangle2D getBounds2D()
Shape比getBounds方法。
需要注意的是没有保证返回Rectangle2D是最小的边框包围Shape ,只表示Shape完全在指定的范围内Rectangle2D 。
通过此方法返回的边界框通常比通过返回的更紧密getBounds方法,而且永远不会因为溢出问题,因为返回值可以是实例Rectangle2D一个使用双精度值存储尺寸。
需要注意的是definition of insideness可能会导致出现对的定义轮廓点的情况下shape可能不被认为包含在返回bounds对象,但只有在这些点也未审议了原有的情况下shape 。
如果point是内部shape根据contains(point)方法,那么它必须是内部返回Rectangle2D界限根据对象contains(point)所述的方法bounds 。 特别:
shape.contains(p)要求bounds.contains(p)
如果point不在shape ,那么它可能仍然包含在bounds对象中:
bounds.contains(p)并不表示shape.contains(p)
getBounds2D在界面
Shape
Rectangle2D那是一个高精度边界框
Shape 。
Shape.getBounds()
public boolean contains(double x,
double y)
Shape ,如所描述的
definition of insideness 。
public boolean contains(Point2D p)
Point2D是的边界内Shape ,如所描述的definition of insideness 。
public boolean intersects(double x,
double y,
double w,
double h)
Shape相交的指定矩形区域的内部。
矩形区域被认为是交叉的Shape如果任何点被包含在双方的内部Shape和指定的矩形区域。
该Shape.intersects()方法允许Shape实现谨慎地返回true时:
Shape相交,但是 Shapes这种方法也可能返回true即使矩形区域没有相交Shape 。
所述Area类执行几何相交的更精确的计算比大多数Shape可以,如果需要更精确的答案被使用的对象,因此。
intersects在界面
Shape
x - 指定矩形区域左上角的X坐标
y - 指定矩形区域左上角的Y坐标
w - 指定矩形区域的宽度
h - 指定矩形区域的高度
true如果Shape的内部和矩形区域的内部相交,或者很可能相交,并且交叉点计算将太昂贵执行;
false否则。
Area
public boolean intersects(Rectangle2D r)
Shape相交指定的内部Rectangle2D 。
该Shape.intersects()方法允许Shape实现谨慎地返回true时:
Rectangle2D和Shape相交的Shape很高,但是 Shapes这种方法也可能返回true即使Rectangle2D不相交Shape 。
所述Area类执行几何相交的更精确的计算比大多数Shape可以,如果需要更精确的答案被使用的对象,因此。
intersects在接口
Shape
r - 指定的
Rectangle2D
true如果内部Shape和指定的内部Rectangle2D相交,或两者均是高度可能相交及交叉点计算。将执行太贵;
false否则。
Shape.intersects(double, double, double, double)
public boolean contains(double x,
double y,
double w,
double h)
Shape的内部Shape完全包含指定的矩形区域。
位于矩形区域内的所有坐标必须位于Shape内,整个矩形区域将被视为包含在Shape 。
该Shape.contains()方法允许Shape实现谨慎地返回false时:
intersect方法返回true和 Shape完全包含矩形区域的代价太高。 Shapes即使Shape包含矩形区域,此方法也可能返回false 。
所述Area类比大多数执行更精确的几何计算Shape对象,因此可以在需要更精确的答案一起使用。
contains在接口
Shape
x - 指定矩形区域左上角的X坐标
y - 指定矩形区域左上角的Y坐标
w - 指定矩形区域的宽度
h - 指定矩形区域的高度
true如果内部Shape完全包含指定矩形区域;
false否则或如果Shape包含矩形区域,并且intersects方法返回true ,并且包含计算将太昂贵执行。
Area , Shape.intersects(double, double, double, double)
public boolean contains(Rectangle2D r)
Shape的内部Shape全部包含指定的Rectangle2D 。
该Shape.contains()方法允许Shape实现谨慎地返回false时:
intersect方法返回true和 Shape完全包含Rectangle2D的代价太高。 Shapes这个方法可能会返回false即使Shape包含Rectangle2D 。
所述Area类比大多数执行更精确的几何计算Shape对象,因此可以在需要更精确的答案一起使用。
contains在界面
Shape
r - 指定的
Rectangle2D
true如果内部的Shape完全包含Rectangle2D ;
false否则或如果Shape包含Rectangle2D和intersects方法返回true ,并且遏制计算将太昂贵执行。
Shape.contains(double, double, double, double)
public PathIterator getPathIterator(AffineTransform at)
Polygon的边界进行迭代,并提供对这个Polygon的轮廓几何的访问。
可以指定可选的AffineTransform ,以便相应地转换迭代中返回的坐标。
getPathIterator在界面
Shape
at - 要在迭代中返回的应用于
at的可选
AffineTransform ,如果需要未转换的
null ,则为null
PathIterator对象,提供对这个Polygon几何的Polygon 。
public PathIterator getPathIterator(AffineTransform at, double flatness)
Shape ,并提供访问的轮廓的几何Shape 。
只有SEG_MOVETO,SEG_LINETO和SEG_CLOSE点类型由迭代器返回。
由于多边形已经平坦,因此flatness参数将被忽略。
可以AffineTransform可选的AffineTransform ,在这种情况下,相应地转换迭代中返回的坐标。
getPathIterator在界面
Shape
at - 在迭代中返回时应用于
at的可选
AffineTransform ,如果需要未转换的
null ,则为null
flatness - 给定曲线的控制点的最大量可以在一条细分曲线被连接端点的直线代替之前从共线线变化。
由于多边形已经平坦, flatness参数被忽略。
PathIterator对象,可以访问
Shape对象的几何。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.