pxt-arcade icon indicating copy to clipboard operation
pxt-arcade copied to clipboard

Image.rotated(0) returns null.

Open dblloyd opened this issue 1 year ago • 0 comments

The help for Image.rotated() says "Returns an image rotated by -90, 0, 90, 180, 270 deg clockwise". However, passing 0 to the function returns null. The corresponding code for imageRotated() in image.ts is:

    /**
     * Returns an image rotated by 90, 180, 270 deg clockwise
     */
    export function imageRotated(img: Image, deg: number) {
        if (deg == -90 || deg == 270) {
            let r = img.transposed();
            r.flipY();
            return r;
        } else if (deg == 180 || deg == -180) {
            let r = img.clone();
            r.flipX();
            r.flipY();
            return r;
        } else if (deg == 90) {
            let r = img.transposed();
            r.flipX();
            return r;
        } else {
            return null;
        }
    }

Note that the function actually handles -90, 270, 180, -180, and 90, contrary to the comment on the function or the comment on Image.rotated() which provides the help string. So either the comments should be updated, or the code should be updated to support a rotation of 0 degrees.

dblloyd avatar Jan 30 '24 04:01 dblloyd