为什么第一个和第三个矩形没有出现在下面的示例中?
一旦矩形为零,它看起来就被破坏了。
package tests.piccolo;
import org.piccolo2d.extras.PFrame;
import org.piccolo2d.nodes.PPath;
public class Try_EmptyRectangle {
public static void main(String[] args) {
new PFrame() {
@Override
public void initialize() {
PPath rect1 = PPath.createRectangle(0, 0, 0, 0);
PPath rect2 = PPath.createRectangle(0, 100, 1, 1);
PPath rect3 = PPath.createRectangle(0, 200, 1, 1);
getCanvas().getLayer().addChild(rect1);
getCanvas().getLayer().addChild(rect2);
rect1.setWidth(50);
rect1.setHeight(50);
rect2.setWidth(50);
rect2.setHeight(50);
rect3.setWidth(0);
rect3.setHeight(0);
rect3.setWidth(50);
rect3.setHeight(50);
}
};
}
}
这看起来像一个bug。CCD_ 1内部包裹CCD_。CCD_ 3将CCD_ 4初始化为零大小的矩形形状。然后改变PPath
的宽度/高度会触发边界的改变。PPath
覆盖internalUpdateBounds()
,以便缩放路径以适应指定的边界。零大小路径似乎有一个问题:
protected void internalUpdateBounds(final double x, final double y, final double width, final double height) {
final Rectangle2D pathBounds = path.getBounds2D();
...
final double scaleX;
if (adjustedWidth == 0 || pathBounds.getWidth() == 0) {
scaleX = 1;
}
...
final double scaleY;
if (adjustedHeight == 0 || pathBounds.getHeight() == 0) {
scaleY = 1;
}
...
TEMP_TRANSFORM.scale(scaleX, scaleY);
...
path.transform(TEMP_TRANSFORM);
}
scaleX和scaleY总是1。因此路径实际上从未缩放,并且保持零大小。