无法在Piccolo2D中拉伸零矩形?

时间:2015-02-09 13:13:02

标签: java piccolo

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

一旦零尺寸,矩形就会被打破。

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


            }



        };

    }

}

1 个答案:

答案 0 :(得分:1)

这看起来像个错误。 PPath内部包裹GeneralPathPPath.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);
}

scaleX scaleY 始终为1.因此路径实际上从不缩放,并且保持为零大小。