1 /****************************************************************************
2 **  Copyright (c) 2016, Adel Kara Slimane <adel.ks@zegrapher.com>
3 **
4 **  This file is part of ZeGrapher's source code.
5 **
6 **  ZeGrapher is free software: you may copy, redistribute and/or modify it
7 **  under the terms of the GNU General Public License as published by the
8 **  Free Software Foundation, either version 3 of the License, or (at your
9 **  option) any later version.
10 **
11 **  This file is distributed in the hope that it will be useful, but
12 **  WITHOUT ANY WARRANTY; without even the implied warranty of
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 **  General Public License for more details.
15 **
16 **  You should have received a copy of the GNU General Public License
17 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 **
19 ****************************************************************************/
20 
21 
22 #ifndef REGRESSIONVALUESSAVER_H
23 #define REGRESSIONVALUESSAVER_H
24 
25 #include <algorithm>
26 
27 #include "regression.h"
28 #include "structures.h"
29 #include "GraphDraw/viewmapper.h"
30 
31 class RegressionValuesSaver : public QObject
32 {
33     Q_OBJECT
34 
35 public:
36     RegressionValuesSaver(double pixStep, Regression *reg = nullptr);
37     RegressionValuesSaver(const RegressionValuesSaver &other);
38     ~RegressionValuesSaver();
39 
40     RegressionValuesSaver& operator=(const RegressionValuesSaver &other);
41 
42     void setPixelStep(double distBetweenPts);
43 
44     Regression* getRegression();
45     void setRegression(Regression *reg);
46     void move(ZeViewMapper newRange);
47 
48     QList<QPolygonF> &getCurves();
49 
50 public slots:
51      void recalculate();
52      void recalculate(Point graphUnits, const ZeViewMapper &graphView);
53 
54 protected:
55     void calculatePolarRegressionCurve();
56     void calculateCartesianRegressionCurve();
57     inline double squareLength(QPointF pt);
58     inline double length(QPointF pt);
59     QPointF orthogonalVector(const QPointF &pt);
60     void cartesianMove();
61     void polarMove();
62     Range getGraphAngleRange();
63     QList<Range> getDrawableSet();
64     double arg(QPointF pt);
65 
66     double pixelMove;
67     Regression *regression;
68     double xUnit, yUnit, pixelStep, xUnitStep;
69     ZeViewMapper viewMapper;
70     Range drawRange, graphAngleRange;
71 
72     QList<QPolygonF> curves;
73 };
74 
75 #endif // REGRESSIONVALUESSAVER_H
76