From 55a3ecb8cb7fabeaab4231485ebb43a6689fe2f6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 28 Dec 2018 15:53:18 +0200 Subject: [PATCH] Improvement for option "Save layout length". This option worked only for portrait orientation. In landscape orientation instead of width need save height. Additionally we keep original comaprison for the smallest bounding rect. This creates more humanlike output. --HG-- branch : develop --- src/libs/vlayout/vbestsquare.cpp | 15 +++++++++++---- src/libs/vlayout/vbestsquare.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libs/vlayout/vbestsquare.cpp b/src/libs/vlayout/vbestsquare.cpp index 0711e500e..737d95ea8 100644 --- a/src/libs/vlayout/vbestsquare.cpp +++ b/src/libs/vlayout/vbestsquare.cpp @@ -33,7 +33,7 @@ //--------------------------------------------------------------------------------------------------------------------- VBestSquare::VBestSquare(const QSizeF &sheetSize, bool saveLength) :resI(0), resJ(0), resMatrix(QMatrix()), bestSize(QSizeF(sheetSize.width()+10, sheetSize.height()+10)), - sheetWidth(sheetSize.width()), valideResult(false), resMirror(false), type (BestFrom::Rotation), + sheetSize(sheetSize), valideResult(false), resMirror(false), type (BestFrom::Rotation), saveLength(saveLength) {} @@ -42,10 +42,17 @@ void VBestSquare::NewResult(const QSizeF &candidate, int i, int j, const QTransf { if (saveLength) { - const QSizeF saveLengthSize(sheetWidth, candidate.height()); - if (Square(saveLengthSize) <= Square(bestSize) && Square(saveLengthSize) > 0 && type >= this->type) + const bool isPortrait = sheetSize.height() >= sheetSize.width(); + const QSizeF saveSpaceSize = isPortrait ? QSizeF(sheetSize.width(), candidate.height()) : + QSizeF(candidate.width(), sheetSize.height()); + + const QSizeF saveSpaceBestSize = isPortrait ? QSizeF(sheetSize.width(), bestSize.height()) : + QSizeF(bestSize.width(), sheetSize.height()); + + if (Square(saveSpaceSize) <= Square(saveSpaceBestSize) && Square(candidate) <= Square(bestSize) + && Square(saveSpaceSize) > 0 && Square(saveSpaceBestSize) > 0 && type >= this->type) { - bestSize = saveLengthSize; + bestSize = candidate; } else { diff --git a/src/libs/vlayout/vbestsquare.h b/src/libs/vlayout/vbestsquare.h index cd11317a0..dba2e848f 100644 --- a/src/libs/vlayout/vbestsquare.h +++ b/src/libs/vlayout/vbestsquare.h @@ -59,7 +59,7 @@ private: int resJ; // Edge of detail QTransform resMatrix; // Matrix for rotation and translation detail QSizeF bestSize; - qreal sheetWidth; + QSizeF sheetSize; bool valideResult; bool resMirror; BestFrom type;