Seamly2D
Code documentation
vbestsquare.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vbestsquare.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 21 1, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vbestsquare.h"
53 
54 #include <QMatrix>
55 
56 //---------------------------------------------------------------------------------------------------------------------
57 VBestSquare::VBestSquare(const QSizeF &sheetSize, bool saveLength)
58  : resI(0)
59  , resJ(0)
60  , resTransform(QTransform())
61  , bestSize(QSizeF(sheetSize.width()+10, sheetSize.height()+10))
62  , sheetWidth(sheetSize.width())
63  , valideResult(false)
64  , resMirror(false), type (BestFrom::Rotation)
65  , saveLength(saveLength)
66 {}
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 void VBestSquare::NewResult(const QSizeF &candidate, int i, int j, const QTransform &transform, bool mirror, BestFrom type)
70 {
71  if (saveLength)
72  {
73  const QSizeF saveLengthSize(sheetWidth, candidate.height());
74  if (Square(saveLengthSize) <= Square(bestSize) && Square(saveLengthSize) > 0 && type >= this->type)
75  {
76  bestSize = saveLengthSize;
77  }
78  else
79  {
80  return;
81  }
82  }
83  else
84  {
85  if (Square(candidate) <= Square(bestSize) && Square(candidate) > 0 && type >= this->type)
86  {
87  bestSize = candidate;
88  }
89  else
90  {
91  return;
92  }
93  }
94 
95  resI = i;
96  resJ = j;
97  resTransform = transform;
98  valideResult = true;
99  resMirror = mirror;
100  this->type = type;
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
105 {
106  if (best.ValidResult() && saveLength == best.IsSaveLength())
107  {
108  NewResult(best.BestSize(), best.GContourEdge(), best.pieceEdge(), best.Transform(), best.isMirror(), best.Type());
109  }
110 }
111 
112 //---------------------------------------------------------------------------------------------------------------------
113 QSizeF VBestSquare::BestSize() const
114 {
115  return bestSize;
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
120 {
121  return resI;
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
126 {
127  return resJ;
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
131 QTransform VBestSquare::Transform() const
132 {
133  return resTransform;
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
138 {
139  return valideResult;
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
144 {
145  return resMirror;
146 }
147 
148 //---------------------------------------------------------------------------------------------------------------------
150 {
151  return type;
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
156 {
157  return saveLength;
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
161 qint64 VBestSquare::Square(const QSizeF &size)
162 {
163  return static_cast<qint64>(size.width()*size.height());
164 }
bool ValidResult() const
QSizeF BestSize() const
int GContourEdge() const
QTransform Transform() const
bool saveLength
Definition: vbestsquare.h:89
bool resMirror
Definition: vbestsquare.h:87
bool isMirror() const
BestFrom Type() const
QSizeF bestSize
Definition: vbestsquare.h:84
int pieceEdge() const
void NewResult(const QSizeF &candidate, int i, int j, const QTransform &transform, bool mirror, BestFrom type)
Definition: vbestsquare.cpp:69
static qint64 Square(const QSizeF &size)
qreal sheetWidth
Definition: vbestsquare.h:85
bool IsSaveLength() const
VBestSquare(const QSizeF &sheetSize, bool saveLength)
Definition: vbestsquare.cpp:57
QTransform resTransform
Definition: vbestsquare.h:83
BestFrom type
Definition: vbestsquare.h:88
bool valideResult
Definition: vbestsquare.h:86
BestFrom
Definition: vlayoutdef.h:68