public static RectL getBounds(final RectL pIn,
                                  final long pCenterX, final long pCenterY, final double pDegrees,
                                  final RectL pReuse) {
        final RectL out = pReuse != null ? pReuse : new RectL();
        if (pDegrees == 0) { // optimization
            out.top = pIn.top;
            out.left = pIn.left;
            out.bottom = pIn.bottom;
            out.right = pIn.right;
            return out;
        }
        final double radians = pDegrees * Math.PI / 180.;
        final double cos = Math.cos(radians);
        final double sin = Math.sin(radians);
        long inputX;
        long inputY;
        long outputX;
        long outputY;
        inputX = pIn.left; // corner 1
        inputY = pIn.top;
        outputX = getRotatedX(inputX, inputY, pCenterX, pCenterY, cos, sin);
        outputY = getRotatedY(inputX, inputY, pCenterX, pCenterY, cos, sin);
        out.top = out.bottom = outputY;
        out.left = out.right = outputX;
        inputX = pIn.right; // corner 2
        inputY = pIn.top;
        outputX = getRotatedX(inputX, inputY, pCenterX, pCenterY, cos, sin);
        outputY = getRotatedY(inputX, inputY, pCenterX, pCenterY, cos, sin);
        if (out.top > outputY) {
            out.top = outputY;
        }
        if (out.bottom < outputY) {
            out.bottom = outputY;
        }
        if (out.left > outputX) {
            out.left = outputX;
        }
        if (out.right < outputX) {
            out.right = outputX;
        }
        inputX = pIn.right; // corner 3
        inputY = pIn.bottom;
        outputX = getRotatedX(inputX, inputY, pCenterX, pCenterY, cos, sin);
        outputY = getRotatedY(inputX, inputY, pCenterX, pCenterY, cos, sin);
        if (out.top > outputY) {
            out.top = outputY;
        }
        if (out.bottom < outputY) {
            out.bottom = outputY;
        }
        if (out.left > outputX) {
            out.left = outputX;
        }
        if (out.right < outputX) {
            out.right = outputX;
        }
        inputX = pIn.left; // corner 4
        inputY = pIn.bottom;
        outputX = getRotatedX(inputX, inputY, pCenterX, pCenterY, cos, sin);
        outputY = getRotatedY(inputX, inputY, pCenterX, pCenterY, cos, sin);
        if (out.top > outputY) {
            out.top = outputY;
        }
        if (out.bottom < outputY) {
            out.bottom = outputY;
        }
        if (out.left > outputX) {
            out.left = outputX;
        }
        if (out.right < outputX) {
            out.right = outputX;
        }
        return out;
    }
@Test
    public void testGetBoundsSamplesRect() {
        final Rect in = new Rect();
        final Rect out = new Rect();
        in.top = 0; // lousy member setting for Rect - see javadoc comments on class
        in.left = 0;

        in.bottom = 6;
        in.right = 4;
        RectL.getBounds(in, 0, 0, 180, out);
        Assert.assertEquals(-6, out.top);
        Assert.assertEquals(0, out.bottom);
        Assert.assertEquals(-4, out.left);
        Assert.assertEquals(0, out.right);

        in.bottom = 7;
        in.right = 5;
        RectL.getBounds(in, 0, 0, 90, out);
        Assert.assertEquals(0, out.top);
        Assert.assertEquals(-7, out.left);
        Assert.assertEquals(5, out.bottom);
        Assert.assertEquals(0, out.right);

        in.bottom = 8;
        in.right = 8;
        RectL.getBounds(in, 0, 0, 45, out);
        Assert.assertEquals(0, out.top);
        Assert.assertEquals(-Math.round(8 * Math.sqrt(2) / 2.), out.left);
        Assert.assertEquals(Math.round(8 * Math.sqrt(2)), out.bottom);
        Assert.assertEquals(Math.round(8 * Math.sqrt(2) / 2.), out.right);
    }