0

为什么下面的示例中没有出现第一个和第三个矩形?

看起来矩形一旦大小为零就被破坏了。

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);


            }



        };

    }

}
4

1 回答 1

1

这看起来像一个错误。PPath内部包裹GeneralPath. PPath.createRectangle(0, 0, 0, 0)初始化GeneralPath为零大小的矩形形状。然后更改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);
}

scaleXscaleY始终为 1。因此路径实际上从未缩放并且保持零大小。

于 2015-02-10T08:05:36.693 回答