/** * Finds an axis-aligned bounding box which would contain a image after it has been transformed. * The returned bounding box can be larger then the original image. * * @param srcWidth Width of the source image * @param srcHeight Height of the source image * @param transform Transform being applied to the image * @return Bounding box */ public static RectangleLength2D_F32 boundBox_F32( int srcWidth , int srcHeight , PixelTransform2_F32 transform ) { ImageRectangle_F32 r=new ImageRectangle_F32(); r.x0=r.y0=Float.MAX_VALUE; r.x1=r.y1=-Float.MAX_VALUE; for( int y = 0; y < srcHeight; y++ ) { transform.compute(0, y); updateBoundBox(transform, r); transform.compute(srcWidth, y); updateBoundBox(transform, r); } for( int x = 0; x < srcWidth; x++ ) { transform.compute(x, 0); updateBoundBox(transform, r); transform.compute(x, srcHeight); updateBoundBox(transform, r); } return new RectangleLength2D_F32(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0); }
/** * Finds an axis-aligned bounding box which would contain a image after it has been transformed. * The returned bounding box can be larger then the original image. * * @param srcWidth Width of the source image * @param srcHeight Height of the source image * @param transform Transform being applied to the image * @return Bounding box */ public static RectangleLength2D_F64 boundBox_F64( int srcWidth , int srcHeight , PixelTransform2_F64 transform ) { ImageRectangle_F64 r = new ImageRectangle_F64(); r.x0=r.y0=Double.MAX_VALUE; r.x1=r.y1=-Double.MAX_VALUE; for( int y = 0; y < srcHeight; y++ ) { transform.compute(0, y); updateBoundBox(transform, r); transform.compute(srcWidth, y); updateBoundBox(transform, r); } for( int x = 0; x < srcWidth; x++ ) { transform.compute(x, 0); updateBoundBox(transform, r); transform.compute(x, srcHeight); updateBoundBox(transform, r); } return new RectangleLength2D_F64(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0); }