Thu, 04 Jan 2018 22:42:01 +0200
simplified RoundToDecimals
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
1 | /* |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1222 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
4 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
8 | * (at your option) any later version. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
9 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
13 | * GNU General Public License for more details. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
14 | * |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
17 | */ |
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1005
diff
changeset
|
18 | |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #pragma once |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "ldObject.h" |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "ldDocument.h" |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | template<typename T> |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | class LDObjectIterator |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | public: |
1217 | 27 | LDObjectIterator(LDDocument* doc) : |
28 | m_list(doc->objects()), | |
29 | m_i(-1) | |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
1217 | 34 | LDObjectIterator(const LDObjectList& objs) : |
35 | m_list(objs), | |
36 | m_i(-1) | |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | bool outOfBounds() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | return m_i < 0 or m_i >= m_list.size(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | T* get() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | { |
1217 | 48 | return static_cast<T*>(m_list[m_i]); |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | bool isValid() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | return not outOfBounds() and get()->type() == T::SubclassType; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
1217 | 56 | void seek(int i) |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | m_i = i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | void seekTillValid() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | do ++m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | while (not outOfBounds() and not isValid()); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | void rewindTillValid() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | do --m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | while (m_i >= 0 and not isValid()); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | int tell() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | return m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | T* operator*() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | return get(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | T* operator->() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | return get(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | void operator++() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
1217 | 93 | void operator++(int) |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | void operator--() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | rewindTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
1217 | 103 | void operator--(int) |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | rewindTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
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:
956
diff
changeset
|
108 | operator T*() |
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:
956
diff
changeset
|
109 | { |
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:
956
diff
changeset
|
110 | return get(); |
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:
956
diff
changeset
|
111 | } |
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:
956
diff
changeset
|
112 | |
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | private: |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | const LDObjectList& m_list; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | int m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | }; |
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:
956
diff
changeset
|
117 | |
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:
956
diff
changeset
|
118 | template<typename T, typename R> |
1217 | 119 | QVector<T*> filterByType(const R& stuff) |
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:
956
diff
changeset
|
120 | { |
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:
956
diff
changeset
|
121 | QVector<T*> result; |
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:
956
diff
changeset
|
122 | |
1217 | 123 | for (LDObjectIterator<T> it(stuff); it.isValid(); ++it) |
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:
956
diff
changeset
|
124 | result << it; |
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:
956
diff
changeset
|
125 | |
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:
956
diff
changeset
|
126 | return result; |
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:
956
diff
changeset
|
127 | } |