public class Polygon extends Object implements Shape, Serializable
Polygon
类封装了一个描述一个封闭区域内,二维坐标空间。这个区域是有界的任意数量的线段,其中每一个是一个边的多边形。在内部,一个多边形组成的一系列
(x,y)
坐标对,每对顶点定义一个空的多边形,并连续两对一线,多边形的一条边的端点。
(x,y)
点的第一和最后对通过线段闭合多边形加入。这是一个
Polygon
奇偶缠绕规则定义。看到一个奇偶缠绕规则定义
WIND_EVEN_ODD
。这类的命中测试方法,包括
contains
,
intersects
和
inside
方法,使用在
Shape
类注释描述的nullinsideness定义。
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 测试的内部完全包含指定的矩形区域。
|
boolean |
contains(int x, int y)
确定指定的坐标,这里面
Polygon 。
|
boolean |
contains(Point p)
确定指定的
Point 是这里面
Polygon 。
|
boolean |
contains(Point2D p)
|
boolean |
contains(Rectangle2D r)
如果
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轴和Y轴
deltaY 沿。
|
public int npoints
addPoint(int, int)
public int[] xpoints
addPoint(int, int)
public int[] ypoints
Polygon
Y坐标。额外的元素,让新的点被添加到这个
Polygon
没有重新创建这个数组。对
npoints
值等于该
Polygon
有效点数。
addPoint(int, int)
protected Rectangle bounds
Polygon
界限。此值可以为空。
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
阵列等方法
getBounds
或
contains
可能缓存数据从先前的计算涉及的顶点坐标。
getBounds()
public void translate(int deltaX, int deltaY)
Polygon
顶点的
deltaX
沿X轴和Y轴
deltaY
沿。
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()
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坐标进行测试
Polygon
true
包含指定的坐标
(x,y)
;
false
否则。
contains(double, double)
@Deprecated public boolean inside(int x, int y)
contains(int, int)
。
Polygon
。
x
-指定的x坐标进行测试
y
-指定的y坐标进行测试
Polygon
true
包含指定的坐标
(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
界根据的bounds
contains(point)
方法的具体对象:
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)
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
相交,但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.contains()
方法允许Shape
实施保守的回报false
时:
true
和intersect
Shape
完全包含矩形区域是昂贵的计算。Shapes
这个方法可能返回
false
即使
Shape
包含矩形区域。的
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
测试的内部完全包含指定的
Rectangle2D
。的
Shape.contains()
方法允许
Shape
实施保守的回报
false
时:
true
和intersect
Shape
完全包含Rectangle2D
是昂贵的计算。Shapes
这个方法可能返回
false
即使
Shape
包含
Rectangle2D
,
Area
类执行更精确的几何计算比大多数
Shape
对象,因此可以更准确的答案是需要用。
contains
接口
Shape
r
-指定
Rectangle2D
true
如果的
Shape
内部完全包含
false
Rectangle2D
;否则,如果
Shape
包含
Rectangle2D
和
intersects
方法返回
true
和遏制的计算是执行太贵。
Shape.contains(double, double, double, double)
public PathIterator getPathIterator(AffineTransform at)
getPathIterator
接口
Shape
at
可选
AffineTransform
被应用到坐标作为他们在迭代返回,或
null
如果需要转化的坐标
PathIterator
对象提供了访问该
Polygon
几何。
public PathIterator getPathIterator(AffineTransform at, double flatness)
Shape
沿边界和提供的
Shape
轮廓的几何。只有seg_moveto,seg_lineto,和seg_close点类型通过返回的迭代器。由于多边形已经持平,这
flatness
参数被忽略。一个可选的
AffineTransform
可规定在这种情况下,返回的坐标在迭代进行相应的转换。
getPathIterator
接口
Shape
at
可选
AffineTransform
被应用到坐标作为他们在迭代返回,或
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.