if (underlayContains(oldCrop, underlay)) {
return oldCrop;
}
Point2D sw = oldCrop.getLowerLeft();
Point2D ne = oldCrop.getUpperRight();
Line2D diagonal = new Line2D.Double(sw, ne);
double oldDiag = sw.distance(ne);
double newDiag = getMinimumDistance(
sw, Collections.singleton(diagonal), underlay
);
double diagScale = newDiag / oldDiag;
Point2D se = oldCrop.getLowerRight();
Line2D south = getSouthCropLine(oldCrop);
double oldSouth = sw.distance(se);
double newSouth = getMinimumDistance(
sw, Collections.singleton(south), underlay
);
double southScale = newSouth / oldSouth;
Point2D nw = oldCrop.getUpperLeft();
Line2D west = getWestCropLine(oldCrop);
double oldWest = sw.distance(nw);
double newWest = getMinimumDistance(
sw, Collections.singleton(west), underlay
);