src/types.cpp

changeset 286
7a562bf3d829
parent 270
f5f2353af0d9
child 287
3fcccd8c3357
equal deleted inserted replaced
285:836e77323ab0 286:7a562bf3d829
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QObject>
20 #include <QStringList>
19 #include <assert.h> 21 #include <assert.h>
20 #include "common.h" 22 #include "common.h"
21 #include "types.h" 23 #include "types.h"
22 #include "misc.h" 24 #include "misc.h"
23 25
26 str DoFormat (vector<StringFormatArg> args) {
27 assert (args.size () >= 1);
28 str text = args[0].value ();
29
30 for (uchar i = 1; i < args.size (); ++i)
31 text = text.arg (args[i].value ());
32
33 return text;
34 }
35
24 vertex::vertex (double x, double y, double z) { 36 vertex::vertex (double x, double y, double z) {
25 m_coords[X] = x; 37 m_coords[X] = x;
26 m_coords[Y] = y; 38 m_coords[Y] = y;
27 m_coords[Z] = z; 39 m_coords[Z] = z;
28 } 40 }
43 return mid; 55 return mid;
44 } 56 }
45 57
46 // ============================================================================= 58 // =============================================================================
47 str vertex::stringRep (bool mangled) const { 59 str vertex::stringRep (bool mangled) const {
48 return fmt (mangled ? "(%s, %s, %s)" : "%s %s %s", 60 if (mangled)
49 ftoa (coord (X)).chars(), 61 return (str ("(") +
50 ftoa (coord (Y)).chars(), 62 ftoa (coord (X)) + ", " +
51 ftoa (coord (Z)).chars()); 63 ftoa (coord (Y)) + ", " +
64 ftoa (coord (Z)) + ")");
65
66 return QStringList ({ftoa (coord (X)), ftoa (coord (Y)),
67 ftoa (coord (Z))}).join (" ");
52 } 68 }
53 69
54 // ============================================================================= 70 // =============================================================================
55 void vertex::transform (matrix matr, vertex pos) { 71 void vertex::transform (matrix matr, vertex pos) {
56 double x2 = (matr[0] * x ()) + (matr[1] * y ()) + (matr[2] * z ()) + pos[X]; 72 double x2 = (matr[0] * x ()) + (matr[1] * y ()) + (matr[2] * z ()) + pos[X];
163 str val; 179 str val;
164 for (short i = 0; i < 9; ++i) { 180 for (short i = 0; i < 9; ++i) {
165 if (i > 0) 181 if (i > 0)
166 val += ' '; 182 val += ' ';
167 183
168 val += fmt ("%s", ftoa (m_vals[i]).chars()); 184 val += ftoa (m_vals[i]);
169 } 185 }
170 186
171 return val; 187 return val;
172 } 188 }
173 189
203 (val (2) * val (3) * val (7)) - 219 (val (2) * val (3) * val (7)) -
204 (val (2) * val (4) * val (6)) - 220 (val (2) * val (4) * val (6)) -
205 (val (1) * val (3) * val (8)) - 221 (val (1) * val (3) * val (8)) -
206 (val (0) * val (5) * val (7)); 222 (val (0) * val (5) * val (7));
207 } 223 }
224
225 // =============================================================================
226 StringFormatArg::StringFormatArg (const str& v) {
227 m_val = v;
228 }
229
230 StringFormatArg::StringFormatArg (const char& v) {
231 m_val = v;
232 }
233
234 StringFormatArg::StringFormatArg (const uchar& v) {
235 m_val = v;
236 }
237
238 StringFormatArg::StringFormatArg (const qchar& v) {
239 m_val = v;
240 }
241
242 StringFormatArg::StringFormatArg (const float& v) {
243 m_val = ftoa (v);
244 }
245
246 StringFormatArg::StringFormatArg (const double& v) {
247 m_val = ftoa (v);
248 }
249
250 StringFormatArg::StringFormatArg (const vertex& v) {
251 m_val = v.stringRep (false);
252 }
253
254 StringFormatArg::StringFormatArg (const matrix& v) {
255 m_val = v.stringRep ();
256 }
257
258 StringFormatArg::StringFormatArg (const char* v) {
259 m_val = v;
260 }
261
262 StringFormatArg::StringFormatArg (const strconfig& v) {
263 m_val = v.value;
264 }
265
266 StringFormatArg::StringFormatArg (const intconfig& v) {
267 m_val.number (v.value);
268 }
269
270 StringFormatArg::StringFormatArg (const floatconfig& v) {
271 m_val.number (v.value);
272 }

mercurial