src/misc/ringFinder.h

Tue, 07 Jan 2014 11:56:26 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 07 Jan 2014 11:56:26 +0200
changeset 604
01bdac75994a
parent 603
47e7773c7841
permissions
-rw-r--r--

- some cleanup

596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
600
209e3f1f7b2c - updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 596
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef LDFORGE_MISC_RINGFINDER_H
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define LDFORGE_MISC_RINGFINDER_H
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "../main.h"
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 // =============================================================================
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 // RingFinder
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 //
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 // Provides an algorithm for finding a solution of rings between radii r0 and r1.
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // =============================================================================
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 class RingFinder
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
30 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
31 public:
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 struct Component
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
33 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
34 int num;
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 double scale;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 };
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 class Solution
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
39 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
40 public:
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 // Components of this solution
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 inline const QVector<Component>& getComponents() const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
43 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
44 return m_components;
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 }
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 // Add a component to this solution
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 inline void addComponent (const Component& a)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
49 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
50 m_components.push_back (a);
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 }
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 // Compare solutions
604
01bdac75994a - some cleanup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 603
diff changeset
54 bool isBetterThan (const Solution* other) const;
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 private:
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 QVector<Component> m_components;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 };
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 RingFinder() {}
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 bool findRings (double r0, double r1);
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 inline const Solution* bestSolution()
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
64 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
65 return m_bestSolution;
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 }
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 inline const QVector<Solution>& allSolutions() const
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
69 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
70 return m_solutions;
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 inline bool operator() (double r0, double r1)
603
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
74 {
47e7773c7841 - reformatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 600
diff changeset
75 return findRings (r0, r1);
596
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 private:
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 QVector<Solution> m_solutions;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 const Solution* m_bestSolution;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 int m_stack;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 bool findRingsRecursor (double r0, double r1, Solution& currentSolution);
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 };
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 extern RingFinder g_RingFinder;
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
43c233e91447 - split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 #endif // LDFORGE_MISC_RINGFINDER_H

mercurial