CropBounds oldCrop, Rectangle2D underlay
) {
if (underlayContains(oldCrop, underlay)) {
return oldCrop;
}
Line2D top = getTopUnderlayLine(underlay);
Line2D left = getLeftUnderlayLine(underlay);
Line2D bottom = getBottomUnderlayLine(underlay);
Line2D right = getRightUnderlayLine(underlay);
Line2D north = getNorthCropLine(oldCrop);
Line2D south = getSouthCropLine(oldCrop);
Line2D east = getEastCropLine(oldCrop);
Line2D west = getWestCropLine(oldCrop);
Point2D nt = getIntersection(north, top);
Point2D nl = getIntersection(north, left);
Point2D nb = getIntersection(north, bottom);
Point2D nr = getIntersection(north, right);
Point2D st = getIntersection(south, top);
Point2D sl = getIntersection(south, left);
Point2D sb = getIntersection(south, bottom);
Point2D sr = getIntersection(south, right);
double width = oldCrop.getWidth();
if (nt != null) {
width = minIgnoreNegative(width, west.ptLineDist(nt));
}
if (nl != null) {
width = minIgnoreNegative(width, west.ptLineDist(nl));
}
if (nb != null) {
width = minIgnoreNegative(width, west.ptLineDist(nb));
}
if (nr != null) {
width = minIgnoreNegative(width, west.ptLineDist(nr));
}
if (st != null) {
width = minIgnoreNegative(width, west.ptLineDist(st));
}
if (sl != null) {
width = minIgnoreNegative(width, west.ptLineDist(sl));
}
if (sb != null) {
width = minIgnoreNegative(width, west.ptLineDist(sb));
}
if (sr != null) {
width = minIgnoreNegative(width, west.ptLineDist(sr));
}
Point2D oldCenter = oldCrop.getCenter();
double angle = oldCrop.getAngle();
double height = oldCrop.getHeight();
double dw = width - oldCrop.getWidth();