【问题标题】:Unable to stretch zero rectange in Piccolo2D?无法在 Piccolo 2D 中拉伸零矩形?
【发布时间】:2015-02-09 13:13:01
【问题描述】:

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

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

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


            }



        };

    }

}

【问题讨论】:

    标签: java piccolo


    【解决方案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);
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多