Wed, 08 Jan 2014 13:57:10 +0200
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
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 | 30 | { |
31 | public: | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | struct Component |
603 | 33 | { |
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 | 39 | { |
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 | 43 | { |
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 | 49 | { |
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 | 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 | 64 | { |
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 | 69 | { |
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 | 74 | { |
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 |