double xMax = -Double.MAX_VALUE;
double yMin = Double.MAX_VALUE;
double yMax = -Double.MAX_VALUE;
for(int i = 0; i < 4; i++) {
Point2D destPt = warp.mapSourcePoint(srcPts[i]);
if(destPt == null) {
verticesMapped = false;
break;
}
double x = destPt.getX();
double y = destPt.getY();
if(x < xMin) {
xMin = x;
}
if(x > xMax) {
xMax = x;
}
if(y < yMin) {
yMin = y;
}
if(y > yMax) {
yMax = y;
}
}
// If all vertices mapped, compute the bounds.
if(verticesMapped) {
destBounds = new Rectangle();
destBounds.x = (int)Math.floor(xMin);
destBounds.y = (int)Math.floor(yMin);
destBounds.width = (int)Math.ceil(xMax - destBounds.x);
destBounds.height = (int)Math.ceil(yMax - destBounds.y);
}
}
// If bounds still not computed, approximate the destination bounds
// by the source bounds, compute an approximate forward mapping,
// and use it to compute the destination bounds. If the warp is
// a WarpAffine then skip it as mapSourceRect() already failed.
if(destBounds == null && !(warp instanceof WarpAffine)) {
Point[] destPts = new Point[] {
new Point(sourceBounds.x,
sourceBounds.y),
new Point(sourceBounds.x + sourceBounds.width,
sourceBounds.y),
new Point(sourceBounds.x,
sourceBounds.y + sourceBounds.height),
new Point(sourceBounds.x + sourceBounds.width,
sourceBounds.y + sourceBounds.height)};
float[] sourceCoords = new float[8];
float[] destCoords = new float[8];
int offset = 0;
for(int i = 0; i < 4; i++) {
Point2D dstPt = destPts[i];
Point2D srcPt = warp.mapDestPoint(destPts[i]);
destCoords[offset] = (float)dstPt.getX();
destCoords[offset+1] = (float)dstPt.getY();
sourceCoords[offset] = (float)srcPt.getX();
sourceCoords[offset+1] = (float)srcPt.getY();
offset += 2;
}
// Guaranteed to be a WarpAffine as the degree is 1.
WarpAffine wa =