public static Transform createViewportTransform(double x, double y, final double width, final double height, final double viewportWidth, final double viewportHeight)
    {
        if ((width <= 0) || (height <= 0))
        {
            return null;
        }
        final double scaleX = viewportWidth / width;

        final double scaleY = viewportHeight / height;

        double scale;

        if (scaleX > scaleY)
        {
            // use scaleY

            scale = scaleY;

            final double dw = (viewportWidth / scale) - width;

            x -= dw / 2;
        }
        else
        {
            scale = scaleX;

            final double dh = (viewportHeight / scale) - height;

            y -= dh / 2;
        }
        // x' = m[0] + x*m[1] y' = m[2] + y*m[3]

        final double m02 = -x * scale;

        final double m12 = -y * scale;

        return new Transform(scale, 0, 0, scale, m02, m12);
    }
public static Transform createViewportTransform ( double x , double y , final double width , final double height , final double viewportWidth , final double viewportHeight ) { if ( ( width <= 0 ) || ( height <= 0 ) ) { return null ; } final double scaleX = viewportWidth / width ; final double scaleY = viewportHeight / height ; double scale ; if ( scaleX > scaleY ) { scale = scaleY ; final double dw = ( viewportWidth / scale ) - width ; x -= dw / 2 ; } else { scale = scaleX ; final double dh = ( viewportHeight / scale ) - height ; y -= dh / 2 ; } final double m02 = - x * scale ; final double m12 = - y * scale ; return new Transform ( scale , 0 , 0 , scale , m02 , m12 ) ; }
Creates a Transform for a viewport. The visible area is defined by the rectangle
[x, y, width, height] and the viewport's width and height.

@param x X coordinate of the top-left corner of the new view area.
@param y Y coordinate of the top-left corner of the new view area.
@param width Width of the new view area.
@param height Height of the new View area.
@param viewportWidth Width of the Viewport.
@param viewportHeight Height of the Viewport.
@return Transform