snow-math 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8540161113581ca75f88df1235ccb6293daa57ec
4
- data.tar.gz: d93b16b109cb01a2ce9aa287307696f9ff6e8fb3
3
+ metadata.gz: 2abd452bb35eb8e3103d3f7be86ff10caafa41cf
4
+ data.tar.gz: 7bdde81b230eed327872fd2207b720880657b8ed
5
5
  SHA512:
6
- metadata.gz: 318d5a4f427a73d0ae42066e8f8e0796b9e4913931a9ec0235c201de922018a2e473fa1d4cb904516f0107ad7a466c448c3c51bf6e80fc4f35a21e9bf594fc09
7
- data.tar.gz: 91ce1b664a2aa88065f47a8c358202a590df84b391d97f2e232b972ec0ad3517fa9f606cbc24f67f57aaa47fb5f5fa7252655e25247059b93e78a31a38768838
6
+ metadata.gz: 2d03e5ff63f45425ebcdf9078505b760ab847d663c580aecd031769c3cfbb79737957df79f52befbf173f80edb9dbefb134067ac4a4910a3c7dd0b26d0d8b7a7
7
+ data.tar.gz: 4b564b77f26858fb0db2bdd25db32eee51ff20c1237dfefdba7ca8be48805ee2bf2ce62b8c57a3746ce8e9ab6ec0adb9dd11fb9fb347efbc4b518ff3561181cc
data/ext/snow-math/mat3.c CHANGED
@@ -17,9 +17,9 @@ extern "C"
17
17
 
18
18
 
19
19
  const mat3_t g_mat3_identity = {
20
- 1.0, 0.0, 0.0,
21
- 0.0, 1.0, 0.0,
22
- 0.0, 0.0, 1.0
20
+ s_float_lit(1.0), s_float_lit(0.0), s_float_lit(0.0),
21
+ s_float_lit(0.0), s_float_lit(1.0), s_float_lit(0.0),
22
+ s_float_lit(0.0), s_float_lit(0.0), s_float_lit(1.0)
23
23
  };
24
24
 
25
25
 
@@ -57,14 +57,14 @@ void mat3_identity(mat3_t out)
57
57
  {
58
58
  out[0] =
59
59
  out[4] =
60
- out[8] = 1;
60
+ out[8] = s_float_lit(1.0);
61
61
 
62
62
  out[1] =
63
63
  out[2] =
64
64
  out[3] =
65
65
  out[5] =
66
66
  out[6] =
67
- out[7] = 0;
67
+ out[7] = s_float_lit(0.0);
68
68
  }
69
69
 
70
70
 
@@ -74,19 +74,19 @@ void mat3_to_mat4(const mat3_t in, mat4_t out)
74
74
  out[0] = in[0];
75
75
  out[1] = in[1];
76
76
  out[2] = in[2];
77
- out[3] = 0;
77
+ out[3] = s_float_lit(0.0);
78
78
  out[4] = in[3];
79
79
  out[5] = in[4];
80
80
  out[6] = in[5];
81
- out[7] = 0;
81
+ out[7] = s_float_lit(0.0);
82
82
  out[8] = in[6];
83
83
  out[9] = in[7];
84
84
  out[10] = in[8];
85
85
  out[14] =
86
86
  out[13] =
87
87
  out[12] =
88
- out[11] = 0;
89
- out[15] = 1;
88
+ out[11] = s_float_lit(0.0);
89
+ out[15] = s_float_lit(1.0);
90
90
  }
91
91
 
92
92
 
@@ -114,7 +114,7 @@ void mat3_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat3_
114
114
  const s_float_t angle_rad = angle * S_DEG2RAD;
115
115
  const s_float_t c = s_cos(angle_rad);
116
116
  const s_float_t s = s_sin(angle_rad);
117
- const s_float_t ic = 1.0 - c;
117
+ const s_float_t ic = s_float_lit(1.0) - c;
118
118
  const s_float_t xy = x * y * ic;
119
119
  const s_float_t yz = y * z * ic;
120
120
  const s_float_t xz = x * z * ic;
@@ -139,9 +139,9 @@ void mat3_from_quat(const quat_t in, mat3_t out)
139
139
  {
140
140
  s_float_t tx, ty, tz, xx, xy, xz, yy, yz, zz, wx, wy, wz;
141
141
 
142
- tx = 2.0 * in[0];
143
- ty = 2.0 * in[1];
144
- tz = 2.0 * in[2];
142
+ tx = s_float_lit(2.0) * in[0];
143
+ ty = s_float_lit(2.0) * in[1];
144
+ tz = s_float_lit(2.0) * in[2];
145
145
 
146
146
  xx = tx * in[0];
147
147
  xy = tx * in[1];
@@ -156,15 +156,15 @@ void mat3_from_quat(const quat_t in, mat3_t out)
156
156
  wy = ty * in[3];
157
157
  wz = tz * in[3];
158
158
 
159
- out[0] = 1.0 - (yy + zz);
159
+ out[0] = s_float_lit(1.0) - (yy + zz);
160
160
  out[1] = xy - wz;
161
161
  out[2] = xz + wy;
162
162
  out[3] = xy + wz;
163
- out[4] = 1.0 - (xx + zz);
163
+ out[4] = s_float_lit(1.0) - (xx + zz);
164
164
  out[5] = yz - wx;
165
165
  out[6] = xz - wy;
166
166
  out[7] = yz + wx;
167
- out[8] = 1.0 - (xx + yy);
167
+ out[8] = s_float_lit(1.0) - (xx + yy);
168
168
  }
169
169
 
170
170
 
@@ -353,8 +353,8 @@ void mat3_adjoint(const mat3_t in, mat3_t out)
353
353
  int mat3_inverse(const mat3_t in, mat3_t out)
354
354
  {
355
355
  s_float_t determinant = mat3_determinant(in);
356
- if (determinant != 0.0 && determinant != -0.0) {
357
- determinant = 1.0 / determinant;
356
+ if (determinant != s_float_lit(0.0) && determinant != s_float_lit(-0.0)) {
357
+ determinant = s_float_lit(1.0) / determinant;
358
358
  } else {
359
359
  return 0;
360
360
  }
@@ -378,16 +378,25 @@ int mat3_inverse(const mat3_t in, mat3_t out)
378
378
 
379
379
  void mat3_get_row3(const mat3_t in, int row, vec3_t out)
380
380
  {
381
- const s_float_t *p = &in[0];
382
381
  switch (row) {
383
- case 2: { p += 3; }
384
- case 1: { p += 3; }
385
382
  case 0: {
386
383
  out[0] = in[0];
387
384
  out[1] = in[1];
388
385
  out[2] = in[2];
389
386
  break;
390
387
  }
388
+ case 1: {
389
+ out[0] = in[3];
390
+ out[1] = in[4];
391
+ out[2] = in[5];
392
+ break;
393
+ }
394
+ case 2: {
395
+ out[0] = in[6];
396
+ out[1] = in[7];
397
+ out[2] = in[8];
398
+ break;
399
+ }
391
400
  default: { break; }
392
401
  }
393
402
  }
@@ -396,16 +405,25 @@ void mat3_get_row3(const mat3_t in, int row, vec3_t out)
396
405
 
397
406
  void mat3_get_column3(const mat3_t in, int column, vec3_t out)
398
407
  {
399
- const s_float_t *p = &in[0];
400
408
  switch (column) {
401
- case 2: { ++p; }
402
- case 1: { ++p; }
403
409
  case 0: {
404
410
  out[0] = in[0];
405
411
  out[1] = in[3];
406
412
  out[2] = in[6];
407
413
  break;
408
414
  }
415
+ case 1: {
416
+ out[0] = in[1];
417
+ out[1] = in[4];
418
+ out[2] = in[7];
419
+ break;
420
+ }
421
+ case 2: {
422
+ out[0] = in[2];
423
+ out[1] = in[5];
424
+ out[2] = in[8];
425
+ break;
426
+ }
409
427
  default: { break; }
410
428
  }
411
429
  }
@@ -414,16 +432,25 @@ void mat3_get_column3(const mat3_t in, int column, vec3_t out)
414
432
 
415
433
  void mat3_set_row3(int row, const vec3_t in, mat3_t out)
416
434
  {
417
- const s_float_t *p = &out[0];
418
435
  switch (row) {
419
- case 2: { p += 3; }
420
- case 1: { p += 3; }
421
436
  case 0: {
422
437
  out[0] = in[0];
423
438
  out[1] = in[1];
424
439
  out[2] = in[2];
425
440
  break;
426
441
  }
442
+ case 1: {
443
+ out[3] = in[0];
444
+ out[4] = in[1];
445
+ out[5] = in[2];
446
+ break;
447
+ }
448
+ case 2: {
449
+ out[6] = in[0];
450
+ out[7] = in[1];
451
+ out[8] = in[2];
452
+ break;
453
+ }
427
454
  default: { break; }
428
455
  }
429
456
  }
@@ -432,16 +459,25 @@ void mat3_set_row3(int row, const vec3_t in, mat3_t out)
432
459
 
433
460
  void mat3_set_column3(int column, const vec3_t in, mat3_t out)
434
461
  {
435
- const s_float_t *p = &out[0];
436
462
  switch (column) {
437
- case 2: { ++p; }
438
- case 1: { ++p; }
439
463
  case 0: {
440
464
  out[0] = in[0];
441
465
  out[3] = in[1];
442
466
  out[6] = in[2];
443
467
  break;
444
468
  }
469
+ case 1: {
470
+ out[3] = in[0];
471
+ out[4] = in[1];
472
+ out[5] = in[2];
473
+ break;
474
+ }
475
+ case 2: {
476
+ out[6] = in[0];
477
+ out[7] = in[1];
478
+ out[8] = in[2];
479
+ break;
480
+ }
445
481
  default: { break; }
446
482
  }
447
483
  }
data/ext/snow-math/mat4.c CHANGED
@@ -23,21 +23,21 @@ extern "C"
23
23
  */
24
24
 
25
25
  const mat4_t g_mat4_identity = {
26
- 1.0, 0.0, 0.0, 0.0,
27
- 0.0, 1.0, 0.0, 0.0,
28
- 0.0, 0.0, 1.0, 0.0,
29
- 0.0, 0.0, 0.0, 1.0
26
+ s_float_lit(1.0), s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0),
27
+ s_float_lit(0.0), s_float_lit(1.0), s_float_lit(0.0), s_float_lit(0.0),
28
+ s_float_lit(0.0), s_float_lit(0.0), s_float_lit(1.0), s_float_lit(0.0),
29
+ s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0), s_float_lit(1.0)
30
30
  };
31
31
 
32
32
  static s_float_t mat4_cofactor(const mat4_t m, int r0, int r1, int r2, int c0, int c1, int c2);
33
33
 
34
34
  void mat4_identity(mat4_t out)
35
35
  {
36
- out[0] = out[5] = out[10] = out[15] = 1.0;
36
+ out[0] = out[5] = out[10] = out[15] = s_float_lit(1.0);
37
37
  out[1] = out[2] = out[3] =
38
38
  out[4] = out[6] = out[7] =
39
39
  out[8] = out[9] = out[11] =
40
- out[12] = out[13] = out[14] = 0.0;
40
+ out[12] = out[13] = out[14] = s_float_lit(0.0);
41
41
  }
42
42
 
43
43
  void mat4_copy(const mat4_t in, mat4_t out)
@@ -116,8 +116,8 @@ void mat4_set_axes3(const vec3_t x, const vec3_t y, const vec3_t z, const vec3_t
116
116
  out[7] = w[1];
117
117
  out[11] = w[2];
118
118
 
119
- out[12] = out[13] = out[14] = 0.0;
120
- out[15] = 1.0;
119
+ out[12] = out[13] = out[14] = s_float_lit(0.0);
120
+ out[15] = s_float_lit(1.0);
121
121
  }
122
122
 
123
123
  void mat4_get_axes3(const mat4_t m, vec3_t x, vec3_t y, vec3_t z, vec3_t w)
@@ -208,7 +208,7 @@ void mat4_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat4_
208
208
  const s_float_t angle_rad = angle * S_DEG2RAD;
209
209
  const s_float_t c = s_cos(angle_rad);
210
210
  const s_float_t s = s_sin(angle_rad);
211
- const s_float_t ic = 1.0 - c;
211
+ const s_float_t ic = s_float_lit(1.0) - c;
212
212
  const s_float_t xy = x * y * ic;
213
213
  const s_float_t yz = y * z * ic;
214
214
  const s_float_t xz = x * z * ic;
@@ -226,8 +226,8 @@ void mat4_rotation(s_float_t angle, s_float_t x, s_float_t y, s_float_t z, mat4_
226
226
  out[9] = yz - xs;
227
227
  out[10] = ((z * z) * ic) + c;
228
228
  out[3] = out[7] = out[11] =
229
- out[12] = out[13] = out[14] = 0.0;
230
- out[15] = 1.0;
229
+ out[12] = out[13] = out[14] = s_float_lit(0.0);
230
+ out[15] = s_float_lit(1.0);
231
231
  }
232
232
 
233
233
  void mat4_frustum(s_float_t left, s_float_t right, s_float_t bottom, s_float_t top, s_float_t near, s_float_t far, mat4_t out)
@@ -235,18 +235,18 @@ void mat4_frustum(s_float_t left, s_float_t right, s_float_t bottom, s_float_t t
235
235
  const s_float_t xdelta = right - left;
236
236
  const s_float_t ydelta = top - bottom;
237
237
  const s_float_t zdelta = far - near;
238
- const s_float_t neardouble = 2.0 * near;
238
+ const s_float_t neardouble = s_float_lit(2.0) * near;
239
239
 
240
240
  out[0] = neardouble / xdelta;
241
241
  out[2] = (right + left) / xdelta;
242
242
  out[5] = neardouble / ydelta;
243
243
  out[6] = (top + bottom) / ydelta;
244
244
  out[10] = -((far + near) / zdelta);
245
- out[11] = -1.0;
245
+ out[11] = s_float_lit(-1.0);
246
246
  out[14] = -((neardouble * far) / zdelta);
247
247
  out[1] = out[3] = out[4] =
248
248
  out[7] = out[8] = out[9] =
249
- out[12] = out[13] = out[15] = 0.0;
249
+ out[12] = out[13] = out[15] = s_float_lit(0.0);
250
250
  }
251
251
 
252
252
  void mat4_orthographic(s_float_t left, s_float_t right, s_float_t bottom, s_float_t top, s_float_t near, s_float_t far, mat4_t out)
@@ -255,37 +255,37 @@ void mat4_orthographic(s_float_t left, s_float_t right, s_float_t bottom, s_floa
255
255
  const s_float_t ydelta = top - bottom;
256
256
  const s_float_t zdelta = far - near;
257
257
 
258
- out[0] = 2.0 / xdelta;
259
- out[5] = 2.0 / ydelta;
260
- out[10] = -2.0 / zdelta;
258
+ out[0] = s_float_lit(2.0) / xdelta;
259
+ out[5] = s_float_lit(2.0) / ydelta;
260
+ out[10] = s_float_lit(-2.0) / zdelta;
261
261
  out[12] = -((right + left) / xdelta);
262
262
  out[13] = -((top + bottom) / ydelta);
263
263
  out[14] = -((far + near) / zdelta);
264
- out[15] = 1.0;
264
+ out[15] = s_float_lit(1.0);
265
265
  out[1] = out[2] = out[3] =
266
266
  out[4] = out[6] = out[7] =
267
- out[8] = out[9] = out[11] = 0.0;
267
+ out[8] = out[9] = out[11] = s_float_lit(0.0);
268
268
  }
269
269
 
270
270
  void mat4_perspective(s_float_t fov_y, s_float_t aspect, s_float_t near, s_float_t far, mat4_t out)
271
271
  {
272
- const s_float_t r = s_tan(fov_y * 0.5 * S_DEG2RAD);
272
+ const s_float_t r = s_tan(fov_y * s_float_lit(0.5) * S_DEG2RAD);
273
273
  const s_float_t left = -r * aspect;
274
274
  const s_float_t right = r * aspect;
275
275
  const s_float_t bottom = -r;
276
276
  const s_float_t top = r;
277
- const s_float_t two_near = 2 * near;
278
- const s_float_t zdelta = 1.0 / (near - far);
277
+ const s_float_t two_near = s_float_lit(2.0) * near;
278
+ const s_float_t zdelta = s_float_lit(1.0) / (near - far);
279
279
 
280
280
  out[0] = two_near * (right - left);
281
281
  out[5] = two_near / (top - bottom);
282
282
  out[10] = (far + near) * zdelta;
283
- out[11] = -1.0;
283
+ out[11] = s_float_lit(-1.0);
284
284
  out[14] = (two_near * far) * zdelta;
285
285
  out[1] = out[2] = out[3] =
286
286
  out[4] = out[6] = out[7] =
287
287
  out[8] = out[9] = out[12] =
288
- out[13] = out[15] = 0.0;
288
+ out[13] = out[15] = s_float_lit(0.0);
289
289
  }
290
290
 
291
291
  void mat4_look_at(const vec3_t eye, const vec3_t center, const vec3_t up, mat4_t out)
@@ -315,9 +315,9 @@ void mat4_from_quat(const quat_t quat, mat4_t out)
315
315
  {
316
316
  s_float_t tx, ty, tz, xx, xy, xz, yy, yz, zz, wx, wy, wz;
317
317
 
318
- tx = 2.0 * quat[0];
319
- ty = 2.0 * quat[1];
320
- tz = 2.0 * quat[2];
318
+ tx = s_float_lit(2.0) * quat[0];
319
+ ty = s_float_lit(2.0) * quat[1];
320
+ tz = s_float_lit(2.0) * quat[2];
321
321
 
322
322
  xx = tx * quat[0];
323
323
  xy = tx * quat[1];
@@ -332,24 +332,24 @@ void mat4_from_quat(const quat_t quat, mat4_t out)
332
332
  wy = ty * quat[3];
333
333
  wz = tz * quat[3];
334
334
 
335
- out[0 ] = 1.0 - (yy + zz);
335
+ out[0 ] = s_float_lit(1.0) - (yy + zz);
336
336
  out[1 ] = xy - wz;
337
337
  out[2 ] = xz + wy;
338
338
  out[4 ] = xy + wz;
339
- out[5 ] = 1.0 - (xx + zz);
339
+ out[5 ] = s_float_lit(1.0) - (xx + zz);
340
340
  out[6 ] = yz - wx;
341
341
  out[8 ] = xz - wy;
342
342
  out[9 ] = yz + wx;
343
- out[10] = 1.0 - (xx + yy);
343
+ out[10] = s_float_lit(1.0) - (xx + yy);
344
344
 
345
- out[7 ] = 0.0;
346
- out[3 ] = 0.0;
347
- out[11] = 0.0;
348
- out[12] = 0.0;
349
- out[13] = 0.0;
350
- out[14] = 0.0;
345
+ out[7 ] = s_float_lit(0.0);
346
+ out[3 ] = s_float_lit(0.0);
347
+ out[11] = s_float_lit(0.0);
348
+ out[12] = s_float_lit(0.0);
349
+ out[13] = s_float_lit(0.0);
350
+ out[14] = s_float_lit(0.0);
351
351
 
352
- out[15] = 1.0;
352
+ out[15] = s_float_lit(1.0);
353
353
  }
354
354
 
355
355
  void mat4_get_row4(const mat4_t in, int row, vec4_t out)
@@ -491,21 +491,21 @@ void mat4_inverse_orthogonal(const mat4_t in, mat4_t out)
491
491
  in[0],
492
492
  in[4],
493
493
  in[8],
494
- 0.0,
494
+ s_float_lit(0.0),
495
495
  in[1],
496
496
  in[5],
497
497
  in[9],
498
- 0.0,
498
+ s_float_lit(0.0),
499
499
  in[2],
500
500
  in[6],
501
501
  in[10],
502
- 0.0
502
+ s_float_lit(0.0)
503
503
  };
504
504
 
505
505
  temp[12] = -((m12 * temp[0]) + (m13 * temp[4]) + (m14 * temp[8]));
506
506
  temp[13] = -((m12 * temp[1]) + (m13 * temp[5]) + (m14 * temp[9]));
507
507
  temp[14] = -((m12 * temp[2]) + (m13 * temp[6]) + (m14 * temp[10]));
508
- temp[15] = 1.0;
508
+ temp[15] = s_float_lit(1.0);
509
509
 
510
510
  mat4_copy(temp, out);
511
511
  }
@@ -539,7 +539,7 @@ int mat4_inverse_affine(const mat4_t in, mat4_t out)
539
539
  return 0;
540
540
  }
541
541
 
542
- det = 1.0 / det;
542
+ det = s_float_lit(1.0) / det;
543
543
 
544
544
  out[0] = temp[0] * det;
545
545
  out[1] = temp[1] * det;
@@ -559,8 +559,8 @@ int mat4_inverse_affine(const mat4_t in, mat4_t out)
559
559
  out[13] = -((m12 * temp[1]) + (m13 * temp[5]) + (m14 * temp[9 ]));
560
560
  out[14] = -((m12 * temp[2]) + (m13 * temp[6]) + (m14 * temp[10]));
561
561
 
562
- out[3] = out[7] = out[11] = 0.0;
563
- out[15] = 1.0;
562
+ out[3] = out[7] = out[11] = s_float_lit(0.0);
563
+ out[15] = s_float_lit(1.0);
564
564
 
565
565
  return 1;
566
566
  }
@@ -644,7 +644,7 @@ int mat4_inverse_general(const mat4_t in, mat4_t out)
644
644
  }
645
645
 
646
646
  mat4_adjoint(in, out);
647
- det = 1.0 / det;
647
+ det = s_float_lit(1.0) / det;
648
648
  for (index = 0; index < 16; ++index) {
649
649
  out[index] *= det;
650
650
  }
@@ -673,7 +673,7 @@ void mat4_translation(s_float_t x, s_float_t y, s_float_t z, mat4_t out) {
673
673
  s_float_t m12 = x;
674
674
  s_float_t m13 = y;
675
675
  s_float_t m14 = z;
676
- s_float_t m15 = 1;
676
+ s_float_t m15 = s_float_lit(1.0);
677
677
 
678
678
  mat4_copy(g_mat4_identity, out);
679
679
 
@@ -40,6 +40,7 @@ typedef float s_float_t;
40
40
  #define s_atan(X) (atanf((X)))
41
41
  #define s_fabs(X) (fabsf((X)))
42
42
  #define s_sqrt(X) (sqrtf((X)))
43
+ #define s_float_lit(X) (X##f)
43
44
  #else
44
45
  typedef double s_float_t;
45
46
  #define s_cos(X) (cos((X)))
@@ -50,6 +51,7 @@ typedef double s_float_t;
50
51
  #define s_atan(X) (atan((X)))
51
52
  #define s_fabs(X) (fabs((X)))
52
53
  #define s_sqrt(X) (sqrt((X)))
54
+ #define s_float_lit(X) (X)
53
55
  #endif
54
56
 
55
57
  typedef s_float_t mat4_t[16];
@@ -67,10 +69,10 @@ typedef s_float_t quat_t[4];
67
69
  *
68
70
  * It should be stressed that this is absolutely not an accurate epsilon.
69
71
  */
70
- #define S_FLOAT_EPSILON (1.0e-9)
72
+ #define S_FLOAT_EPSILON s_float_lit(1.0e-9)
71
73
 
72
- #define S_DEG2RAD (0.01745329)
73
- #define S_RAD2DEG (57.2957795)
74
+ #define S_DEG2RAD s_float_lit(0.01745329)
75
+ #define S_RAD2DEG s_float_lit(57.2957795)
74
76
 
75
77
 
76
78
 
data/ext/snow-math/quat.c CHANGED
@@ -14,7 +14,7 @@ extern "C"
14
14
  {
15
15
  #endif /* __cplusplus */
16
16
 
17
- const quat_t g_quat_identity = {0.0, 0.0, 0.0, 1.0};
17
+ const quat_t g_quat_identity = { s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0), s_float_lit(1.0) };
18
18
 
19
19
  void quat_set(s_float_t x, s_float_t y, s_float_t z, s_float_t w, quat_t out)
20
20
  {
@@ -36,8 +36,8 @@ void quat_copy(const quat_t in, quat_t out)
36
36
 
37
37
  void quat_identity(quat_t q)
38
38
  {
39
- q[0] = q[1] = q[2] = 0.0;
40
- q[3] = 1.0;
39
+ q[0] = q[1] = q[2] = s_float_lit(0.0);
40
+ q[3] = s_float_lit(1.0);
41
41
  }
42
42
 
43
43
  void quat_inverse(const quat_t in, quat_t out)
@@ -81,8 +81,8 @@ void quat_multiply_vec3(const quat_t left, const vec3_t right, vec3_t out)
81
81
  vec3_t lxr_cross, lxlr_cross;
82
82
  vec3_cross_product(left, right, lxr_cross);
83
83
  vec3_cross_product(left, lxr_cross, lxlr_cross);
84
- vec3_scale(lxr_cross, 2.0 * left[3], lxr_cross);
85
- vec3_scale(lxlr_cross, 2.0, lxlr_cross);
84
+ vec3_scale(lxr_cross, s_float_lit(2.0) * left[3], lxr_cross);
85
+ vec3_scale(lxlr_cross, s_float_lit(2.0), lxlr_cross);
86
86
  vec3_add(lxr_cross, lxlr_cross, lxr_cross);
87
87
  vec3_add(right, lxr_cross, out);
88
88
  }
@@ -92,7 +92,7 @@ void quat_from_angle_axis(s_float_t angle, s_float_t x, s_float_t y, s_float_t z
92
92
  vec3_t v = {x, y, z};
93
93
  vec3_normalize(v, v);
94
94
 
95
- angle *= (S_DEG2RAD * 0.5);
95
+ angle *= (S_DEG2RAD * s_float_lit(0.5));
96
96
  const s_float_t s = s_sin(angle);
97
97
 
98
98
  out[0] = v[0] * s;
@@ -108,9 +108,9 @@ void quat_from_mat4(const mat4_t mat, quat_t out)
108
108
 
109
109
  trace = mat[0] + mat[5] + mat[10];
110
110
  if (trace > 0) {
111
- r = s_sqrt(trace + 1.0);
112
- out[3] = r * 0.5;
113
- r = 0.5 / r;
111
+ r = s_sqrt(trace + s_float_lit(1.0));
112
+ out[3] = r * s_float_lit(0.5);
113
+ r = s_float_lit(0.5) / r;
114
114
  out[0] = (mat[9] - mat[6]) * r;
115
115
  out[1] = (mat[2] - mat[8]) * r;
116
116
  out[2] = (mat[4] - mat[1]) * r;
@@ -122,10 +122,10 @@ void quat_from_mat4(const mat4_t mat, quat_t out)
122
122
  index = 1;
123
123
  }
124
124
 
125
- r = s_sqrt(mat[index * 5] - (mat[((index + 1)) % 3 * 5] + mat[((index + 2) % 3) * 5]) + 1.0);
126
- out[index] = r * 0.5;
125
+ r = s_sqrt(mat[index * 5] - (mat[((index + 1)) % 3 * 5] + mat[((index + 2) % 3) * 5]) + s_float_lit(1.0));
126
+ out[index] = r * s_float_lit(0.5);
127
127
 
128
- if (r) r = 0.5 / r;
128
+ if (r) r = s_float_lit(0.5) / r;
129
129
 
130
130
  switch (index)
131
131
  {
@@ -159,10 +159,10 @@ void quat_from_mat3(const mat3_t mat, quat_t out)
159
159
 
160
160
  trace = mat[0] + mat[4] + mat[8];
161
161
 
162
- if (trace > 0.0) {
163
- r = s_sqrt(trace + 1);
164
- out[3] = r * 0.5;
165
- r = 0.5 / r;
162
+ if (trace > s_float_lit(0.0)) {
163
+ r = s_sqrt(trace + s_float_lit(1.0));
164
+ out[3] = r * s_float_lit(0.5);
165
+ r = s_float_lit(0.5) / r;
166
166
  out[0] = (m12 - m21) * r;
167
167
  out[1] = (m20 - m02) * r;
168
168
  out[2] = (m01 - m10) * r;
@@ -177,9 +177,9 @@ void quat_from_mat3(const mat3_t mat, quat_t out)
177
177
  switch (index) {
178
178
  default:
179
179
  case 0:
180
- r = out[0] = s_sqrt(mat[0] - (mat[4] + mat[8]) + 1) * 0.5;
181
- if (r != 0.0 && r != -0.0) {
182
- r = 0.5 / r;
180
+ r = out[0] = s_sqrt(mat[0] - (mat[4] + mat[8]) + s_float_lit(1.0)) * s_float_lit(0.5);
181
+ if (r != s_float_lit(0.0) && r != s_float_lit(-0.0)) {
182
+ r = s_float_lit(0.5) / r;
183
183
  }
184
184
  out[1] = (m10 + m01) * r;
185
185
  out[2] = (m20 + m02) * r;
@@ -187,9 +187,9 @@ void quat_from_mat3(const mat3_t mat, quat_t out)
187
187
  break;
188
188
 
189
189
  case 1:
190
- r = out[1] = s_sqrt(mat[4] - (mat[8] + mat[0]) + 1) * 0.5;
191
- if (r != 0.0 && r != -0.0) {
192
- r = 0.5 / r;
190
+ r = out[1] = s_sqrt(mat[4] - (mat[8] + mat[0]) + s_float_lit(1.0)) * s_float_lit(0.5);
191
+ if (r != s_float_lit(0.0) && r != s_float_lit(-0.0)) {
192
+ r = s_float_lit(0.5) / r;
193
193
  }
194
194
  out[0] = (m10 + m01) * r;
195
195
  out[2] = (m12 + m21) * r;
@@ -197,9 +197,9 @@ void quat_from_mat3(const mat3_t mat, quat_t out)
197
197
  break;
198
198
 
199
199
  case 2:
200
- r = out[2] = s_sqrt(mat[4] - (mat[0] + mat[4]) + 1) * 0.5;
201
- if (r != 0.0 && r != -0.0) {
202
- r = 0.5 / r;
200
+ r = out[2] = s_sqrt(mat[4] - (mat[0] + mat[4]) + s_float_lit(1.0)) * s_float_lit(0.5);
201
+ if (r != s_float_lit(0.0) && r != s_float_lit(-0.0)) {
202
+ r = s_float_lit(0.5) / r;
203
203
  }
204
204
  out[0] = (m20 + m02) * r;
205
205
  out[1] = (m21 + m12) * r;
@@ -216,7 +216,7 @@ void quat_slerp(const quat_t from, const quat_t to, s_float_t delta, quat_t out)
216
216
 
217
217
  dot = vec4_dot_product((const s_float_t *)from, (const s_float_t *)to);
218
218
 
219
- if (dot < 0.0) {
219
+ if (dot < s_float_lit(0.0)) {
220
220
  dot = -dot;
221
221
  dx = -to[0];
222
222
  dy = -to[1];
@@ -229,12 +229,12 @@ void quat_slerp(const quat_t from, const quat_t to, s_float_t delta, quat_t out)
229
229
  dw = to[3];
230
230
  }
231
231
 
232
- delta = fminf(fmaxf(delta, 0.0), 1.0);
232
+ delta = fminf(fmaxf(delta, s_float_lit(0.0)), s_float_lit(1.0));
233
233
 
234
234
  angle = s_acos(dot);
235
- inverse_sin = 1.0 / s_sin(dot);
235
+ inverse_sin = s_float_lit(1.0) / s_sin(dot);
236
236
 
237
- scale0 = s_sin((1.0 - delta) * angle) * inverse_sin;
237
+ scale0 = s_sin((s_float_lit(1.0) - delta) * angle) * inverse_sin;
238
238
  scale1 = s_sin(delta * angle) * inverse_sin;
239
239
 
240
240
  out[0] = (from[0] * scale0) + (dx * scale1);
data/ext/snow-math/vec3.c CHANGED
@@ -14,8 +14,8 @@ extern "C"
14
14
  {
15
15
  #endif /* __cplusplus */
16
16
 
17
- const vec3_t g_vec3_zero = {0.0, 0.0, 0.0};
18
- const vec3_t g_vec3_one = {1.0, 1.0, 1.0};
17
+ const vec3_t g_vec3_zero = {s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0)};
18
+ const vec3_t g_vec3_one = {s_float_lit(1.0), s_float_lit(1.0), s_float_lit(1.0)};
19
19
 
20
20
  void vec3_copy(const vec3_t in, vec3_t out)
21
21
  {
@@ -51,7 +51,7 @@ s_float_t vec3_length(const vec3_t v)
51
51
  void vec3_normalize(const vec3_t in, vec3_t out)
52
52
  {
53
53
  s_float_t mag = vec3_length(in);
54
- if (mag) mag = 1.0 / mag;
54
+ if (mag) mag = s_float_lit(1.0) / mag;
55
55
  out[0] = in[0] * mag;
56
56
  out[1] = in[1] * mag;
57
57
  out[2] = in[2] * mag;
@@ -87,9 +87,9 @@ void vec3_negate(const vec3_t v, vec3_t out)
87
87
 
88
88
  void vec3_inverse(const vec3_t v, vec3_t out)
89
89
  {
90
- out[2] = (v[2] != 0.0 && v[2] != -0.0) ? (1.0 / v[2]) : v[2];
91
- out[1] = (v[1] != 0.0 && v[1] != -0.0) ? (1.0 / v[1]) : v[1];
92
- out[0] = (v[0] != 0.0 && v[0] != -0.0) ? (1.0 / v[0]) : v[0];
90
+ out[2] = (v[2] != s_float_lit(0.0) && v[2] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[2]) : v[2];
91
+ out[1] = (v[1] != s_float_lit(0.0) && v[1] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[1]) : v[1];
92
+ out[0] = (v[0] != s_float_lit(0.0) && v[0] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[0]) : v[0];
93
93
  }
94
94
 
95
95
  void vec3_project(const vec3_t in, const vec3_t normal, vec3_t out)
@@ -100,7 +100,7 @@ void vec3_project(const vec3_t in, const vec3_t normal, vec3_t out)
100
100
  void vec3_reflect(const vec3_t in, const vec3_t normal, vec3_t out)
101
101
  {
102
102
  vec3_t temp;
103
- vec3_scale(normal, 2 * vec3_dot_product(in, normal), temp);
103
+ vec3_scale(normal, s_float_lit(2.0) * vec3_dot_product(in, normal), temp);
104
104
  vec3_subtract(in, temp, out);
105
105
  }
106
106
 
@@ -134,7 +134,7 @@ void vec3_scale(const vec3_t v, s_float_t scalar, vec3_t out)
134
134
  int vec3_divide(const vec3_t v, s_float_t divisor, vec3_t out)
135
135
  {
136
136
  if (divisor) {
137
- divisor = ((s_float_t)1.0) / divisor;
137
+ divisor = s_float_lit(1.0) / divisor;
138
138
  out[2] = v[2] * divisor;
139
139
  out[1] = v[1] * divisor;
140
140
  out[0] = v[0] * divisor;
data/ext/snow-math/vec4.c CHANGED
@@ -14,9 +14,9 @@ extern "C"
14
14
  {
15
15
  #endif /* __cplusplus */
16
16
 
17
- const vec4_t g_vec4_zero = {0.0, 0.0, 0.0, 0.0};
18
- const vec4_t g_vec4_one = {1.0, 1.0, 1.0, 1.0};
19
- const vec4_t g_vec4_identity = {0.0, 0.0, 0.0, 1.0};
17
+ const vec4_t g_vec4_zero = {s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0)};
18
+ const vec4_t g_vec4_one = {s_float_lit(1.0), s_float_lit(1.0), s_float_lit(1.0), s_float_lit(1.0)};
19
+ const vec4_t g_vec4_identity = {s_float_lit(0.0), s_float_lit(0.0), s_float_lit(0.0), s_float_lit(1.0)};
20
20
 
21
21
  void vec4_copy(const vec4_t in, vec4_t out)
22
22
  {
@@ -54,7 +54,7 @@ s_float_t vec4_length(const vec4_t v)
54
54
  void vec4_normalize(const vec4_t in, vec4_t out)
55
55
  {
56
56
  s_float_t mag = vec4_length(in);
57
- if (mag) mag = 1.0 / mag;
57
+ if (mag) mag = s_float_lit(1.0) / mag;
58
58
  out[0] = in[0] * mag;
59
59
  out[1] = in[1] * mag;
60
60
  out[2] = in[2] * mag;
@@ -95,10 +95,10 @@ void vec4_negate(const vec4_t v, vec4_t out)
95
95
 
96
96
  void vec4_inverse(const vec4_t v, vec4_t out)
97
97
  {
98
- out[3] = (v[3] != 0.0 && v[3] != -0.0) ? (1.0 / v[3]) : v[3];
99
- out[2] = (v[2] != 0.0 && v[2] != -0.0) ? (1.0 / v[2]) : v[2];
100
- out[1] = (v[1] != 0.0 && v[1] != -0.0) ? (1.0 / v[1]) : v[1];
101
- out[0] = (v[0] != 0.0 && v[0] != -0.0) ? (1.0 / v[0]) : v[0];
98
+ out[3] = (v[3] != s_float_lit(0.0) && v[3] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[3]) : v[3];
99
+ out[2] = (v[2] != s_float_lit(0.0) && v[2] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[2]) : v[2];
100
+ out[1] = (v[1] != s_float_lit(0.0) && v[1] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[1]) : v[1];
101
+ out[0] = (v[0] != s_float_lit(0.0) && v[0] != s_float_lit(-0.0)) ? (s_float_lit(1.0) / v[0]) : v[0];
102
102
  }
103
103
 
104
104
  void vec4_project(const vec4_t in, const vec4_t normal, vec4_t out)
@@ -109,7 +109,7 @@ void vec4_project(const vec4_t in, const vec4_t normal, vec4_t out)
109
109
  void vec4_reflect(const vec4_t in, const vec4_t normal, vec4_t out)
110
110
  {
111
111
  vec4_t temp;
112
- vec4_scale(normal, 2 * vec4_dot_product(in, normal), temp);
112
+ vec4_scale(normal, s_float_lit(2.0) * vec4_dot_product(in, normal), temp);
113
113
  vec4_subtract(in, temp, out);
114
114
  }
115
115
 
@@ -133,7 +133,7 @@ void vec4_scale(const vec4_t v, s_float_t scalar, vec4_t out)
133
133
  int vec4_divide(const vec4_t v, s_float_t divisor, vec4_t out)
134
134
  {
135
135
  if (divisor) {
136
- divisor = ((s_float_t)1.0) / divisor;
136
+ divisor = s_float_lit(1.0) / divisor;
137
137
  out[3] = v[3] * divisor;
138
138
  out[2] = v[2] * divisor;
139
139
  out[1] = v[1] * divisor;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snow-math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Raymond Cower
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Math types built on the SnowPalm math code
14
14
  email: ncower@gmail.com
@@ -21,15 +21,12 @@ extra_rdoc_files:
21
21
  files:
22
22
  - lib/snow-math/array_cache.rb
23
23
  - lib/snow-math/inspect.rb
24
- - lib/snow-math/line.rb
25
24
  - lib/snow-math/mat3.rb
26
25
  - lib/snow-math/mat4.rb
27
- - lib/snow-math/plane.rb
28
26
  - lib/snow-math/ptr.rb
29
27
  - lib/snow-math/quat.rb
30
28
  - lib/snow-math/swizzle.rb
31
29
  - lib/snow-math/to_a.rb
32
- - lib/snow-math/vec2.rb
33
30
  - lib/snow-math/vec3.rb
34
31
  - lib/snow-math/vec4.rb
35
32
  - lib/snow-math.rb
File without changes
File without changes
File without changes