src/miscallenous.h

Wed, 10 Jan 2018 22:54:09 +0200

author
Santeri Piippo
date
Wed, 10 Jan 2018 22:54:09 +0200
changeset 1226
d1199d965235
parent 1223
4f8fa42aed07
permissions
-rw-r--r--

drop Qt4 support

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1221
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #pragma once
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QVector>
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
21 #include <functional>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include "basics.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 class LDDocument;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 class QColor;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 class QAction;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 // Simplifies the given fraction.
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
30 void Simplify(int& numer, int& denom);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
32 using ApplyToMatrixFunction = std::function<void(int, double&)>;
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
33 using ApplyToMatrixConstFunction = std::function<void(int, double)>;
733
cc39df788660 - reimplemented the Vertex class as a derivative of QVector3D
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
34
1223
4f8fa42aed07 simplified RoundToDecimals
Santeri Piippo
parents: 1222
diff changeset
35 double RoundToDecimals(double a, int decimals);
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
36 void ApplyToMatrix(Matrix& a, ApplyToMatrixFunction func);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
37 void ApplyToMatrix(const Matrix& a, ApplyToMatrixConstFunction func);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
39 double GetCoordinateOf(const Vertex& a, Axis ax);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
40 QString MakePrettyFileSize(qint64 size);
859
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
41
1221
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
42 template<typename Arg1, typename... Rest>
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
43 void argumentsToStringsHelper(QStringList& list, Arg1&& arg, Rest&&... rest)
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
44 {
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
45 list << toString(arg);
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
46 argumentsToStringsHelper(list, rest...);
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
47 }
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
48
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
49 inline void argumentsToStringsHelper(QStringList&) {}
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
50
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
51 template<typename... Args>
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
52 QStringList argumentsToStrings(Args&&... args)
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
53 {
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
54 QStringList result;
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
55 argumentsToStringsHelper(args...);
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
56 return result;
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
57 }
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
58
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
59 template<typename... Args>
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
60 QString Join(QString delimeter, Args&&... args)
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
61 {
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
62 return argumentsToStrings(args...).join(delimeter);
7f6715f08faf revamped format.h
Santeri Piippo
parents: 1217
diff changeset
63 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 // Grid stuff
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
66 float gridCoordinateSnap();
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
67 float gridAngleSnap();
1005
a88cf5a32246 Subject Bézier curve fineness to the grid. By default, the coarse grid uses 8 segments, medium 16 and fine 32. Moved rasterization from demoting to inlining, it feels more sensible for it to be there.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
68 float gridBezierCurveSegments();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 // =============================================================================
859
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
71 enum class RotationPoint
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
859
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
73 ObjectOrigin,
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
74 WorldOrigin,
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
75 CustomPoint,
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
76 NumValues
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
79 Vertex GetRotationPoint(const LDObjectList& objs);
859
ebc7a186699c - refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
80 void ConfigureRotationPoint();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 namespace Grid
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 enum Type
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 Coarse,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 Medium,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 Fine
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 enum Config
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 {
754
c37564d59ce1 - grids now have a single coordinate snap value instead of individual X, Y and Z values
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
94 Coordinate,
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 Angle
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1012
diff changeset
98 double Snap(double value, const Grid::Config type);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }

mercurial