snow-math 1.6.1 → 1.7.0

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: 59c66cdb4331e39915f31821b06050210de0101b
4
- data.tar.gz: 38339703c8a3dc316120129c559b5d5fe096c1a9
3
+ metadata.gz: 07dcfa849094229689bdbf469119e52479b5034e
4
+ data.tar.gz: 51702b6e75a2b89f77c257a79ca5e1b9162a763a
5
5
  SHA512:
6
- metadata.gz: 848fb1b812af454cb1775db23d1cdd59f071c8f4f8dfbce4eb2315e760445a55ad6f02bb74443d25c6de9a521fdae2db837ca0087e2a6f8314211783ccb8b274
7
- data.tar.gz: 3236a1958069e2d11086fcc688e30c13c8b141a2b034f24a085b0f1142a2f72bc1c680b00760b129a209d364ad54282f1812ff841a2091ccd17c2aa512862ac9
6
+ metadata.gz: 6a625c25c0d0c193dc9cd1d76f921c6ac8e59d94da5da176418656afa924c6f7d2a9dfc8054c091736faa934a37354e5893fa1296c8bfb6905ad0b3f1ffdd562
7
+ data.tar.gz: a1f15c58795706985615239610c1a673ab009a41a12df9061c3bfac81b4af5f5c00cb03c74e0eba84236b230e9dd0beef48e3bc94ecd6d8d9fe286eea7ca892f
@@ -1,2 +1,10 @@
1
1
  #include "maths_local.h"
2
2
  #define __SNOW__MATHS_C__
3
+
4
+ s_float_t S_FLOAT_EPSILON = s_float_lit(
5
+ #ifdef USE_FLOAT
6
+ 1.0e-6
7
+ #else
8
+ 1.0e-9
9
+ #endif
10
+ );
@@ -69,7 +69,7 @@ typedef s_float_t quat_t[4];
69
69
  *
70
70
  * It should be stressed that this is absolutely not an accurate epsilon.
71
71
  */
72
- #define S_FLOAT_EPSILON s_float_lit(1.0e-9)
72
+ extern s_float_t S_FLOAT_EPSILON;
73
73
 
74
74
  #define S_DEG2RAD s_float_lit(0.01745329)
75
75
  #define S_RAD2DEG s_float_lit(57.2957795)
@@ -87,6 +87,37 @@ static VALUE sm_mathtype_array_length(VALUE sm_self)
87
87
  return rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_LENGTH);
88
88
  }
89
89
 
90
+
91
+
92
+ /*
93
+ * Freezes the array and its elements.
94
+ *
95
+ * call-seq: freeze -> self
96
+ */
97
+ static VALUE sm_mathtype_array_freeze(VALUE sm_self)
98
+ {
99
+ VALUE sm_cache;
100
+ VALUE sm_cached_entry;
101
+ long length;
102
+ long index;
103
+
104
+ if (OBJ_FROZEN(sm_self)) {
105
+ return sm_self;
106
+ }
107
+
108
+ sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
109
+ length = RARRAY_LEN(sm_cache);
110
+
111
+ for (index = 0; index < length; ++index) {
112
+ sm_cached_entry = rb_ary_entry(sm_cache, index);
113
+ if (RTEST(sm_cached_entry)) {
114
+ rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
115
+ }
116
+ }
117
+
118
+ return rb_call_super(0, 0);
119
+ }
120
+
90
121
  #endif
91
122
 
92
123
 
@@ -188,37 +219,6 @@ static VALUE sm_vec2_array_new(VALUE sm_self, VALUE sm_length_or_copy)
188
219
 
189
220
 
190
221
 
191
- /*
192
- * Freezes the array and its elements.
193
- *
194
- * call-seq: freeze -> self
195
- */
196
- static VALUE sm_vec2_array_freeze(VALUE sm_self)
197
- {
198
- VALUE sm_cache;
199
- VALUE sm_cached_entry;
200
- long length;
201
- long index;
202
-
203
- if (OBJ_FROZEN(sm_self)) {
204
- return sm_self;
205
- }
206
-
207
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
208
- length = RARRAY_LEN(sm_cache);
209
-
210
- for (index = 0; index < length; ++index) {
211
- sm_cached_entry = rb_ary_entry(sm_cache, index);
212
- if (RTEST(sm_cached_entry) && !OBJ_FROZEN(sm_cached_entry)) {
213
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
214
- }
215
- }
216
-
217
- return rb_call_super(0, 0);
218
- }
219
-
220
-
221
-
222
222
  /*
223
223
  * Resizes the array to new_length and returns self.
224
224
  *
@@ -418,37 +418,6 @@ static VALUE sm_vec3_array_new(VALUE sm_self, VALUE sm_length_or_copy)
418
418
 
419
419
 
420
420
 
421
- /*
422
- * Freezes the array and its elements.
423
- *
424
- * call-seq: freeze -> self
425
- */
426
- static VALUE sm_vec3_array_freeze(VALUE sm_self)
427
- {
428
- VALUE sm_cache;
429
- VALUE sm_cached_entry;
430
- long length;
431
- long index;
432
-
433
- if (OBJ_FROZEN(sm_self)) {
434
- return sm_self;
435
- }
436
-
437
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
438
- length = RARRAY_LEN(sm_cache);
439
-
440
- for (index = 0; index < length; ++index) {
441
- sm_cached_entry = rb_ary_entry(sm_cache, index);
442
- if (RTEST(sm_cached_entry)) {
443
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
444
- }
445
- }
446
-
447
- return rb_call_super(0, 0);
448
- }
449
-
450
-
451
-
452
421
  /*
453
422
  * Resizes the array to new_length and returns self.
454
423
  *
@@ -647,37 +616,6 @@ static VALUE sm_vec4_array_new(VALUE sm_self, VALUE sm_length_or_copy)
647
616
 
648
617
 
649
618
 
650
- /*
651
- * Freezes the array and its elements.
652
- *
653
- * call-seq: freeze -> self
654
- */
655
- static VALUE sm_vec4_array_freeze(VALUE sm_self)
656
- {
657
- VALUE sm_cache;
658
- VALUE sm_cached_entry;
659
- long length;
660
- long index;
661
-
662
- if (OBJ_FROZEN(sm_self)) {
663
- return sm_self;
664
- }
665
-
666
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
667
- length = RARRAY_LEN(sm_cache);
668
-
669
- for (index = 0; index < length; ++index) {
670
- sm_cached_entry = rb_ary_entry(sm_cache, index);
671
- if (RTEST(sm_cached_entry)) {
672
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
673
- }
674
- }
675
-
676
- return rb_call_super(0, 0);
677
- }
678
-
679
-
680
-
681
619
  /*
682
620
  * Resizes the array to new_length and returns self.
683
621
  *
@@ -876,37 +814,6 @@ static VALUE sm_quat_array_new(VALUE sm_self, VALUE sm_length_or_copy)
876
814
 
877
815
 
878
816
 
879
- /*
880
- * Freezes the array and its elements.
881
- *
882
- * call-seq: freeze -> self
883
- */
884
- static VALUE sm_quat_array_freeze(VALUE sm_self)
885
- {
886
- VALUE sm_cache;
887
- VALUE sm_cached_entry;
888
- long length;
889
- long index;
890
-
891
- if (OBJ_FROZEN(sm_self)) {
892
- return sm_self;
893
- }
894
-
895
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
896
- length = RARRAY_LEN(sm_cache);
897
-
898
- for (index = 0; index < length; ++index) {
899
- sm_cached_entry = rb_ary_entry(sm_cache, index);
900
- if (RTEST(sm_cached_entry)) {
901
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
902
- }
903
- }
904
-
905
- return rb_call_super(0, 0);
906
- }
907
-
908
-
909
-
910
817
  /*
911
818
  * Resizes the array to new_length and returns self.
912
819
  *
@@ -1105,37 +1012,6 @@ static VALUE sm_mat3_array_new(VALUE sm_self, VALUE sm_length_or_copy)
1105
1012
 
1106
1013
 
1107
1014
 
1108
- /*
1109
- * Freezes the array and its elements.
1110
- *
1111
- * call-seq: freeze -> self
1112
- */
1113
- static VALUE sm_mat3_array_freeze(VALUE sm_self)
1114
- {
1115
- VALUE sm_cache;
1116
- VALUE sm_cached_entry;
1117
- long length;
1118
- long index;
1119
-
1120
- if (OBJ_FROZEN(sm_self)) {
1121
- return sm_self;
1122
- }
1123
-
1124
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
1125
- length = RARRAY_LEN(sm_cache);
1126
-
1127
- for (index = 0; index < length; ++index) {
1128
- sm_cached_entry = rb_ary_entry(sm_cache, index);
1129
- if (RTEST(sm_cached_entry)) {
1130
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
1131
- }
1132
- }
1133
-
1134
- return rb_call_super(0, 0);
1135
- }
1136
-
1137
-
1138
-
1139
1015
  /*
1140
1016
  * Resizes the array to new_length and returns self.
1141
1017
  *
@@ -1340,37 +1216,6 @@ static VALUE sm_mat4_array_new(VALUE sm_self, VALUE sm_length_or_copy)
1340
1216
 
1341
1217
 
1342
1218
 
1343
- /*
1344
- * Freezes the array and its elements.
1345
- *
1346
- * call-seq: freeze -> self
1347
- */
1348
- static VALUE sm_mat4_array_freeze(VALUE sm_self)
1349
- {
1350
- VALUE sm_cache;
1351
- VALUE sm_cached_entry;
1352
- long length;
1353
- long index;
1354
-
1355
- if (OBJ_FROZEN(sm_self)) {
1356
- return sm_self;
1357
- }
1358
-
1359
- sm_cache = rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE);
1360
- length = RARRAY_LEN(sm_cache);
1361
-
1362
- for (index = 0; index < length; ++index) {
1363
- sm_cached_entry = rb_ary_entry(sm_cache, index);
1364
- if (RTEST(sm_cached_entry)) {
1365
- rb_funcall2(sm_cached_entry, kRB_NAME_FREEZE, 0, 0);
1366
- }
1367
- }
1368
-
1369
- return rb_call_super(0, 0);
1370
- }
1371
-
1372
-
1373
-
1374
1219
  /*
1375
1220
  * Resizes the array to new_length and returns self.
1376
1221
  *
@@ -1576,7 +1421,7 @@ static VALUE sm_vec2_fetch (VALUE sm_self, VALUE sm_index)
1576
1421
  rb_raise(rb_eRangeError,
1577
1422
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
1578
1423
  }
1579
- return rb_float_new(self[0][NUM2INT(sm_index)]);
1424
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
1580
1425
  }
1581
1426
 
1582
1427
 
@@ -1596,7 +1441,7 @@ static VALUE sm_vec2_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
1596
1441
  rb_raise(rb_eRangeError,
1597
1442
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
1598
1443
  }
1599
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
1444
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
1600
1445
  return sm_value;
1601
1446
  }
1602
1447
 
@@ -2058,7 +1903,7 @@ static VALUE sm_vec2_dot_product(VALUE sm_self, VALUE sm_other)
2058
1903
  rb_obj_classname(sm_other));
2059
1904
  return Qnil;
2060
1905
  }
2061
- return rb_float_new(
1906
+ return DBL2NUM(
2062
1907
  vec2_dot_product(
2063
1908
  *sm_unwrap_vec2(sm_self, NULL),
2064
1909
  *sm_unwrap_vec2(sm_other, NULL)));
@@ -2124,8 +1969,8 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
2124
1969
  if (0) {
2125
1970
  case 2:
2126
1971
  if (!SM_RB_IS_A(argv[0], rb_cArray)) {
2127
- self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
2128
- self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
1972
+ self[0][0] = (s_float_t)NUM2DBL(argv[0]);
1973
+ self[0][1] = (s_float_t)NUM2DBL(argv[1]);
2129
1974
  break;
2130
1975
  }
2131
1976
  arr_index = NUM2SIZET(argv[1]);
@@ -2136,7 +1981,7 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
2136
1981
  const size_t arr_end = arr_index + 2;
2137
1982
  s_float_t *vec_elem = *self;
2138
1983
  for (; arr_index < arr_end; ++arr_index, ++vec_elem) {
2139
- *vec_elem = (s_float_t)rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
1984
+ *vec_elem = (s_float_t)NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
2140
1985
  }
2141
1986
  break;
2142
1987
  }
@@ -2181,7 +2026,7 @@ static VALUE sm_vec2_to_s(VALUE self)
2181
2026
  */
2182
2027
  static VALUE sm_vec2_magnitude_squared(VALUE sm_self)
2183
2028
  {
2184
- return rb_float_new(vec2_length_squared(*sm_unwrap_vec2(sm_self, NULL)));
2029
+ return DBL2NUM(vec2_length_squared(*sm_unwrap_vec2(sm_self, NULL)));
2185
2030
  }
2186
2031
 
2187
2032
 
@@ -2194,7 +2039,7 @@ static VALUE sm_vec2_magnitude_squared(VALUE sm_self)
2194
2039
  */
2195
2040
  static VALUE sm_vec2_magnitude(VALUE sm_self)
2196
2041
  {
2197
- return rb_float_new(vec2_length(*sm_unwrap_vec2(sm_self, NULL)));
2042
+ return DBL2NUM(vec2_length(*sm_unwrap_vec2(sm_self, NULL)));
2198
2043
  }
2199
2044
 
2200
2045
 
@@ -2213,7 +2058,7 @@ static VALUE sm_vec2_scale(int argc, VALUE *argv, VALUE sm_self)
2213
2058
  vec2_t *self = sm_unwrap_vec2(sm_self, NULL);
2214
2059
 
2215
2060
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
2216
- scalar = rb_num2dbl(sm_scalar);
2061
+ scalar = NUM2DBL(sm_scalar);
2217
2062
 
2218
2063
  if (SM_IS_A(sm_out, vec2) || SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
2219
2064
  rb_check_frozen(sm_out);
@@ -2244,7 +2089,7 @@ static VALUE sm_vec2_divide(int argc, VALUE *argv, VALUE sm_self)
2244
2089
  vec2_t *self = sm_unwrap_vec2(sm_self, NULL);
2245
2090
 
2246
2091
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
2247
- scalar = rb_num2dbl(sm_scalar);
2092
+ scalar = NUM2DBL(sm_scalar);
2248
2093
 
2249
2094
  if (SM_IS_A(sm_out, vec2) || SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
2250
2095
  rb_check_frozen(sm_out);
@@ -2329,7 +2174,7 @@ static VALUE sm_vec3_fetch (VALUE sm_self, VALUE sm_index)
2329
2174
  rb_raise(rb_eRangeError,
2330
2175
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
2331
2176
  }
2332
- return rb_float_new(self[0][NUM2INT(sm_index)]);
2177
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
2333
2178
  }
2334
2179
 
2335
2180
 
@@ -2349,7 +2194,7 @@ static VALUE sm_vec3_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
2349
2194
  rb_raise(rb_eRangeError,
2350
2195
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
2351
2196
  }
2352
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
2197
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
2353
2198
  return sm_value;
2354
2199
  }
2355
2200
 
@@ -2858,7 +2703,7 @@ static VALUE sm_vec3_dot_product(VALUE sm_self, VALUE sm_other)
2858
2703
  rb_obj_classname(sm_other));
2859
2704
  return Qnil;
2860
2705
  }
2861
- return rb_float_new(
2706
+ return DBL2NUM(
2862
2707
  vec3_dot_product(
2863
2708
  *sm_unwrap_vec3(sm_self, NULL),
2864
2709
  *sm_unwrap_vec3(sm_other, NULL)));
@@ -2936,7 +2781,7 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2936
2781
  const size_t arr_end = arr_index + 3;
2937
2782
  s_float_t *vec_elem = *self;
2938
2783
  for (; arr_index < arr_end; ++arr_index, ++vec_elem) {
2939
- *vec_elem = (s_float_t)rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
2784
+ *vec_elem = (s_float_t)NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
2940
2785
  }
2941
2786
  break;
2942
2787
  }
@@ -2947,9 +2792,9 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2947
2792
 
2948
2793
  /* X, Y, Z */
2949
2794
  case 3: {
2950
- self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
2951
- self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
2952
- self[0][2] = (s_float_t)rb_num2dbl(argv[2]);
2795
+ self[0][0] = (s_float_t)NUM2DBL(argv[0]);
2796
+ self[0][1] = (s_float_t)NUM2DBL(argv[1]);
2797
+ self[0][2] = (s_float_t)NUM2DBL(argv[2]);
2953
2798
  break;
2954
2799
  }
2955
2800
 
@@ -2993,7 +2838,7 @@ static VALUE sm_vec3_to_s(VALUE self)
2993
2838
  */
2994
2839
  static VALUE sm_vec3_magnitude_squared(VALUE sm_self)
2995
2840
  {
2996
- return rb_float_new(vec3_length_squared(*sm_unwrap_vec3(sm_self, NULL)));
2841
+ return DBL2NUM(vec3_length_squared(*sm_unwrap_vec3(sm_self, NULL)));
2997
2842
  }
2998
2843
 
2999
2844
 
@@ -3006,7 +2851,7 @@ static VALUE sm_vec3_magnitude_squared(VALUE sm_self)
3006
2851
  */
3007
2852
  static VALUE sm_vec3_magnitude(VALUE sm_self)
3008
2853
  {
3009
- return rb_float_new(vec3_length(*sm_unwrap_vec3(sm_self, NULL)));
2854
+ return DBL2NUM(vec3_length(*sm_unwrap_vec3(sm_self, NULL)));
3010
2855
  }
3011
2856
 
3012
2857
 
@@ -3025,7 +2870,7 @@ static VALUE sm_vec3_scale(int argc, VALUE *argv, VALUE sm_self)
3025
2870
  vec3_t *self = sm_unwrap_vec3(sm_self, NULL);
3026
2871
 
3027
2872
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
3028
- scalar = rb_num2dbl(sm_scalar);
2873
+ scalar = NUM2DBL(sm_scalar);
3029
2874
 
3030
2875
  if (SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
3031
2876
  rb_check_frozen(sm_out);
@@ -3056,7 +2901,7 @@ static VALUE sm_vec3_divide(int argc, VALUE *argv, VALUE sm_self)
3056
2901
  vec3_t *self = sm_unwrap_vec3(sm_self, NULL);
3057
2902
 
3058
2903
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
3059
- scalar = rb_num2dbl(sm_scalar);
2904
+ scalar = NUM2DBL(sm_scalar);
3060
2905
 
3061
2906
  if (SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
3062
2907
  rb_check_frozen(sm_out);
@@ -3140,7 +2985,7 @@ static VALUE sm_vec4_fetch (VALUE sm_self, VALUE sm_index)
3140
2985
  rb_raise(rb_eRangeError,
3141
2986
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
3142
2987
  }
3143
- return rb_float_new(self[0][NUM2INT(sm_index)]);
2988
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
3144
2989
  }
3145
2990
 
3146
2991
 
@@ -3160,7 +3005,7 @@ static VALUE sm_vec4_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
3160
3005
  rb_raise(rb_eRangeError,
3161
3006
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
3162
3007
  }
3163
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
3008
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
3164
3009
  return sm_value;
3165
3010
  }
3166
3011
 
@@ -3618,7 +3463,7 @@ static VALUE sm_vec4_dot_product(VALUE sm_self, VALUE sm_other)
3618
3463
  rb_obj_classname(sm_other));
3619
3464
  return Qnil;
3620
3465
  }
3621
- return rb_float_new(
3466
+ return DBL2NUM(
3622
3467
  vec4_dot_product(
3623
3468
  *sm_unwrap_vec4(sm_self, NULL),
3624
3469
  *sm_unwrap_vec4(sm_other, NULL)));
@@ -3702,7 +3547,7 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3702
3547
  const size_t arr_end = arr_index + 4;
3703
3548
  s_float_t *vec_elem = *self;
3704
3549
  for (; arr_index < arr_end; ++arr_index, ++vec_elem) {
3705
- *vec_elem = (s_float_t)rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
3550
+ *vec_elem = (s_float_t)NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
3706
3551
  }
3707
3552
  break;
3708
3553
  }
@@ -3713,11 +3558,11 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3713
3558
 
3714
3559
  /* W */
3715
3560
  case 4: {
3716
- self[0][3] = (s_float_t)rb_num2dbl(argv[3]);
3561
+ self[0][3] = (s_float_t)NUM2DBL(argv[3]);
3717
3562
  case 3: /* X, Y, Z */
3718
- self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
3719
- self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
3720
- self[0][2] = (s_float_t)rb_num2dbl(argv[2]);
3563
+ self[0][0] = (s_float_t)NUM2DBL(argv[0]);
3564
+ self[0][1] = (s_float_t)NUM2DBL(argv[1]);
3565
+ self[0][2] = (s_float_t)NUM2DBL(argv[2]);
3721
3566
  break;
3722
3567
  }
3723
3568
 
@@ -3761,7 +3606,7 @@ static VALUE sm_vec4_to_s(VALUE self)
3761
3606
  */
3762
3607
  static VALUE sm_vec4_magnitude_squared(VALUE sm_self)
3763
3608
  {
3764
- return rb_float_new(vec4_length_squared(*sm_unwrap_vec4(sm_self, NULL)));
3609
+ return DBL2NUM(vec4_length_squared(*sm_unwrap_vec4(sm_self, NULL)));
3765
3610
  }
3766
3611
 
3767
3612
 
@@ -3774,7 +3619,7 @@ static VALUE sm_vec4_magnitude_squared(VALUE sm_self)
3774
3619
  */
3775
3620
  static VALUE sm_vec4_magnitude(VALUE sm_self)
3776
3621
  {
3777
- return rb_float_new(vec4_length(*sm_unwrap_vec4(sm_self, NULL)));
3622
+ return DBL2NUM(vec4_length(*sm_unwrap_vec4(sm_self, NULL)));
3778
3623
  }
3779
3624
 
3780
3625
 
@@ -3794,7 +3639,7 @@ static VALUE sm_vec4_scale(int argc, VALUE *argv, VALUE sm_self)
3794
3639
  vec4_t *self = sm_unwrap_vec4(sm_self, NULL);
3795
3640
 
3796
3641
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
3797
- scalar = rb_num2dbl(sm_scalar);
3642
+ scalar = NUM2DBL(sm_scalar);
3798
3643
 
3799
3644
  if ((SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat))) {
3800
3645
  rb_check_frozen(sm_out);
@@ -3826,7 +3671,7 @@ static VALUE sm_vec4_divide(int argc, VALUE *argv, VALUE sm_self)
3826
3671
  vec4_t *self = sm_unwrap_vec4(sm_self, NULL);
3827
3672
 
3828
3673
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
3829
- scalar = rb_num2dbl(sm_scalar);
3674
+ scalar = NUM2DBL(sm_scalar);
3830
3675
 
3831
3676
  if ((SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat))) {
3832
3677
  rb_check_frozen(sm_out);
@@ -3909,7 +3754,7 @@ static VALUE sm_quat_fetch (VALUE sm_self, VALUE sm_index)
3909
3754
  rb_raise(rb_eRangeError,
3910
3755
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
3911
3756
  }
3912
- return rb_float_new(self[0][NUM2INT(sm_index)]);
3757
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
3913
3758
  }
3914
3759
 
3915
3760
 
@@ -3929,7 +3774,7 @@ static VALUE sm_quat_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
3929
3774
  rb_raise(rb_eRangeError,
3930
3775
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
3931
3776
  }
3932
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
3777
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
3933
3778
  return sm_value;
3934
3779
  }
3935
3780
 
@@ -4192,7 +4037,7 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
4192
4037
  const size_t arr_end = arr_index + 3;
4193
4038
  s_float_t *vec_elem = *self;
4194
4039
  for (; arr_index < arr_end; ++arr_index, ++vec_elem) {
4195
- *vec_elem = (s_float_t)rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
4040
+ *vec_elem = (s_float_t)NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
4196
4041
  }
4197
4042
  break;
4198
4043
  }
@@ -4203,11 +4048,11 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
4203
4048
 
4204
4049
  /* W */
4205
4050
  case 4: {
4206
- self[0][3] = (s_float_t)rb_num2dbl(argv[3]);
4051
+ self[0][3] = (s_float_t)NUM2DBL(argv[3]);
4207
4052
  case 3: /* X, Y, Z */
4208
- self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
4209
- self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
4210
- self[0][2] = (s_float_t)rb_num2dbl(argv[2]);
4053
+ self[0][0] = (s_float_t)NUM2DBL(argv[0]);
4054
+ self[0][1] = (s_float_t)NUM2DBL(argv[1]);
4055
+ self[0][2] = (s_float_t)NUM2DBL(argv[2]);
4211
4056
  break;
4212
4057
  }
4213
4058
 
@@ -4265,7 +4110,7 @@ static VALUE sm_quat_angle_axis(int argc, VALUE *argv, VALUE self)
4265
4110
  return Qnil;
4266
4111
  }
4267
4112
 
4268
- angle = (s_float_t)rb_num2dbl(sm_angle);
4113
+ angle = (s_float_t)NUM2DBL(sm_angle);
4269
4114
  axis = sm_unwrap_vec3(sm_axis, NULL);
4270
4115
 
4271
4116
  if (SM_IS_A(sm_out, quat) || SM_IS_A(sm_out, vec4)) {
@@ -4317,7 +4162,7 @@ static VALUE sm_quat_slerp(int argc, VALUE *argv, VALUE sm_self)
4317
4162
  s_float_t alpha;
4318
4163
 
4319
4164
  rb_scan_args(argc, argv, "21", &sm_destination, &sm_alpha, &sm_out);
4320
- alpha = rb_num2dbl(sm_alpha);
4165
+ alpha = NUM2DBL(sm_alpha);
4321
4166
 
4322
4167
  if (!SM_IS_A(sm_destination, vec4) && !SM_IS_A(sm_destination, quat)) {
4323
4168
  rb_raise(rb_eTypeError,
@@ -4389,7 +4234,7 @@ static VALUE sm_mat4_fetch (VALUE sm_self, VALUE sm_index)
4389
4234
  rb_raise(rb_eRangeError,
4390
4235
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
4391
4236
  }
4392
- return rb_float_new(self[0][NUM2INT(sm_index)]);
4237
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
4393
4238
  }
4394
4239
 
4395
4240
 
@@ -4409,7 +4254,7 @@ static VALUE sm_mat4_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
4409
4254
  rb_raise(rb_eRangeError,
4410
4255
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
4411
4256
  }
4412
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
4257
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
4413
4258
  return sm_value;
4414
4259
  }
4415
4260
 
@@ -5005,9 +4850,9 @@ static VALUE sm_mat4_translate(int argc, VALUE *argv, VALUE sm_self)
5005
4850
  }
5006
4851
 
5007
4852
  case 3: {
5008
- xyz[0] = rb_num2dbl(argv[0]);
5009
- xyz[1] = rb_num2dbl(argv[1]);
5010
- xyz[2] = rb_num2dbl(argv[2]);
4853
+ xyz[0] = NUM2DBL(argv[0]);
4854
+ xyz[1] = NUM2DBL(argv[1]);
4855
+ xyz[2] = NUM2DBL(argv[2]);
5011
4856
 
5012
4857
  SM_LABEL(get_output):
5013
4858
  if (RTEST(sm_out)) {
@@ -5057,9 +4902,9 @@ static VALUE sm_mat4_translation(int argc, VALUE *argv, VALUE sm_self)
5057
4902
  }
5058
4903
 
5059
4904
  case 3: {
5060
- xyz[0] = rb_num2dbl(argv[0]);
5061
- xyz[1] = rb_num2dbl(argv[1]);
5062
- xyz[2] = rb_num2dbl(argv[2]);
4905
+ xyz[0] = NUM2DBL(argv[0]);
4906
+ xyz[1] = NUM2DBL(argv[1]);
4907
+ xyz[2] = NUM2DBL(argv[2]);
5063
4908
 
5064
4909
  SM_LABEL(get_output):
5065
4910
  if (RTEST(sm_out)) {
@@ -5158,7 +5003,7 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
5158
5003
  const size_t arr_end = arr_index + 16;
5159
5004
  s_float_t *mat_elem = *self;
5160
5005
  for (; arr_index < arr_end; ++arr_index, ++mat_elem) {
5161
- *mat_elem = rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
5006
+ *mat_elem = NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
5162
5007
  }
5163
5008
  break;
5164
5009
  }
@@ -5189,7 +5034,7 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
5189
5034
  s_float_t *mat_elem = *self;
5190
5035
  VALUE *argv_p = argv;
5191
5036
  for (; argc; --argc, ++argv_p, ++mat_elem) {
5192
- *mat_elem = (s_float_t)rb_num2dbl(*argv_p);
5037
+ *mat_elem = (s_float_t)NUM2DBL(*argv_p);
5193
5038
  }
5194
5039
  break;
5195
5040
  }
@@ -5257,7 +5102,7 @@ static VALUE sm_mat4_angle_axis(int argc, VALUE *argv, VALUE self)
5257
5102
  return Qnil;
5258
5103
  }
5259
5104
 
5260
- angle = (s_float_t)rb_num2dbl(sm_angle);
5105
+ angle = (s_float_t)NUM2DBL(sm_angle);
5261
5106
  axis = sm_unwrap_vec3(sm_axis, NULL);
5262
5107
 
5263
5108
  if (SM_IS_A(sm_out, mat4)) {
@@ -5711,12 +5556,12 @@ static VALUE sm_mat4_frustum(int argc, VALUE *argv, VALUE self)
5711
5556
 
5712
5557
  rb_scan_args(argc, argv, "61", &sm_left, &sm_right, &sm_bottom, &sm_top, &sm_z_near, &sm_z_far, &sm_out);
5713
5558
 
5714
- left = (s_float_t)rb_num2dbl(sm_left);
5715
- right = (s_float_t)rb_num2dbl(sm_right);
5716
- bottom = (s_float_t)rb_num2dbl(sm_bottom);
5717
- top = (s_float_t)rb_num2dbl(sm_top);
5718
- z_near = (s_float_t)rb_num2dbl(sm_z_near);
5719
- z_far = (s_float_t)rb_num2dbl(sm_z_far);
5559
+ left = (s_float_t)NUM2DBL(sm_left);
5560
+ right = (s_float_t)NUM2DBL(sm_right);
5561
+ bottom = (s_float_t)NUM2DBL(sm_bottom);
5562
+ top = (s_float_t)NUM2DBL(sm_top);
5563
+ z_near = (s_float_t)NUM2DBL(sm_z_near);
5564
+ z_far = (s_float_t)NUM2DBL(sm_z_far);
5720
5565
 
5721
5566
  if (SM_IS_A(sm_out, mat4)) {
5722
5567
  rb_check_frozen(sm_out);
@@ -5758,12 +5603,12 @@ static VALUE sm_mat4_orthographic(int argc, VALUE *argv, VALUE self)
5758
5603
 
5759
5604
  rb_scan_args(argc, argv, "61", &sm_left, &sm_right, &sm_bottom, &sm_top, &sm_z_near, &sm_z_far, &sm_out);
5760
5605
 
5761
- left = (s_float_t)rb_num2dbl(sm_left);
5762
- right = (s_float_t)rb_num2dbl(sm_right);
5763
- bottom = (s_float_t)rb_num2dbl(sm_bottom);
5764
- top = (s_float_t)rb_num2dbl(sm_top);
5765
- z_near = (s_float_t)rb_num2dbl(sm_z_near);
5766
- z_far = (s_float_t)rb_num2dbl(sm_z_far);
5606
+ left = (s_float_t)NUM2DBL(sm_left);
5607
+ right = (s_float_t)NUM2DBL(sm_right);
5608
+ bottom = (s_float_t)NUM2DBL(sm_bottom);
5609
+ top = (s_float_t)NUM2DBL(sm_top);
5610
+ z_near = (s_float_t)NUM2DBL(sm_z_near);
5611
+ z_far = (s_float_t)NUM2DBL(sm_z_far);
5767
5612
 
5768
5613
  if (SM_IS_A(sm_out, mat4)) {
5769
5614
  rb_check_frozen(sm_out);
@@ -5801,10 +5646,10 @@ static VALUE sm_mat4_perspective(int argc, VALUE *argv, VALUE self)
5801
5646
 
5802
5647
  rb_scan_args(argc, argv, "41", &sm_fov_y, &sm_aspect, &sm_z_near, &sm_z_far, &sm_out);
5803
5648
 
5804
- fov_y = (s_float_t)rb_num2dbl(sm_fov_y);
5805
- aspect = (s_float_t)rb_num2dbl(sm_aspect);
5806
- z_near = (s_float_t)rb_num2dbl(sm_z_near);
5807
- z_far = (s_float_t)rb_num2dbl(sm_z_far);
5649
+ fov_y = (s_float_t)NUM2DBL(sm_fov_y);
5650
+ aspect = (s_float_t)NUM2DBL(sm_aspect);
5651
+ z_near = (s_float_t)NUM2DBL(sm_z_near);
5652
+ z_far = (s_float_t)NUM2DBL(sm_z_far);
5808
5653
 
5809
5654
  if (SM_IS_A(sm_out, mat4)) {
5810
5655
  rb_check_frozen(sm_out);
@@ -5875,9 +5720,9 @@ static VALUE sm_mat4_scale(int argc, VALUE *argv, VALUE sm_self)
5875
5720
  mat4_t *self = sm_unwrap_mat4(sm_self, NULL);
5876
5721
 
5877
5722
  rb_scan_args(argc, argv, "31", &sm_x, &sm_y, &sm_z, &sm_out);
5878
- x = rb_num2dbl(sm_x);
5879
- y = rb_num2dbl(sm_y);
5880
- z = rb_num2dbl(sm_z);
5723
+ x = NUM2DBL(sm_x);
5724
+ y = NUM2DBL(sm_y);
5725
+ z = NUM2DBL(sm_z);
5881
5726
 
5882
5727
  if (SM_IS_A(sm_out, mat4)) {
5883
5728
  rb_check_frozen(sm_out);
@@ -5957,7 +5802,7 @@ static VALUE sm_mat3_fetch (VALUE sm_self, VALUE sm_index)
5957
5802
  rb_raise(rb_eRangeError,
5958
5803
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
5959
5804
  }
5960
- return rb_float_new(self[0][NUM2INT(sm_index)]);
5805
+ return DBL2NUM(self[0][NUM2INT(sm_index)]);
5961
5806
  }
5962
5807
 
5963
5808
 
@@ -5977,7 +5822,7 @@ static VALUE sm_mat3_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
5977
5822
  rb_raise(rb_eRangeError,
5978
5823
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
5979
5824
  }
5980
- self[0][index] = (s_float_t)rb_num2dbl(sm_value);
5825
+ self[0][index] = (s_float_t)NUM2DBL(sm_value);
5981
5826
  return sm_value;
5982
5827
  }
5983
5828
 
@@ -6502,7 +6347,7 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6502
6347
  const size_t arr_end = arr_index + 9;
6503
6348
  s_float_t *mat_elem = *self;
6504
6349
  for (; arr_index < arr_end; ++arr_index, ++mat_elem) {
6505
- *mat_elem = rb_num2dbl(rb_ary_entry(arrdata, (long)arr_index));
6350
+ *mat_elem = NUM2DBL(rb_ary_entry(arrdata, (long)arr_index));
6506
6351
  }
6507
6352
  break;
6508
6353
  }
@@ -6533,7 +6378,7 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6533
6378
  s_float_t *mat_elem = *self;
6534
6379
  VALUE *argv_p = argv;
6535
6380
  for (; argc; --argc, ++argv_p, ++mat_elem) {
6536
- *mat_elem = (s_float_t)rb_num2dbl(*argv_p);
6381
+ *mat_elem = (s_float_t)NUM2DBL(*argv_p);
6537
6382
  }
6538
6383
  break;
6539
6384
  }
@@ -6598,7 +6443,7 @@ static VALUE sm_mat3_angle_axis(int argc, VALUE *argv, VALUE self)
6598
6443
  return Qnil;
6599
6444
  }
6600
6445
 
6601
- angle = (s_float_t)rb_num2dbl(sm_angle);
6446
+ angle = (s_float_t)NUM2DBL(sm_angle);
6602
6447
  axis = sm_unwrap_vec3(sm_axis, NULL);
6603
6448
 
6604
6449
  if (SM_IS_A(sm_out, mat3)) {
@@ -6844,9 +6689,9 @@ static VALUE sm_mat3_scale(int argc, VALUE *argv, VALUE sm_self)
6844
6689
  mat3_t *self = sm_unwrap_mat3(sm_self, NULL);
6845
6690
 
6846
6691
  rb_scan_args(argc, argv, "31", &sm_x, &sm_y, &sm_z, &sm_out);
6847
- x = rb_num2dbl(sm_x);
6848
- y = rb_num2dbl(sm_y);
6849
- z = rb_num2dbl(sm_z);
6692
+ x = NUM2DBL(sm_x);
6693
+ y = NUM2DBL(sm_y);
6694
+ z = NUM2DBL(sm_z);
6850
6695
 
6851
6696
  if (SM_IS_A(sm_out, mat3)) {
6852
6697
  rb_check_frozen(sm_out);
@@ -6900,6 +6745,65 @@ static VALUE sm_get_address(VALUE sm_self)
6900
6745
 
6901
6746
 
6902
6747
 
6748
+ /*
6749
+ call-seq:
6750
+ float_epsilon -> Float
6751
+
6752
+ Gets the float epsilon for snow-math types. By default, this is 1e-9 for
6753
+ double-precision floats and 1e-6 for single-precision floats.
6754
+ */
6755
+ static VALUE sm_get_float_epsilon(VALUE sm_self)
6756
+ {
6757
+ return DBL2NUM(S_FLOAT_EPSILON);
6758
+ }
6759
+
6760
+
6761
+
6762
+ /*
6763
+ call-seq:
6764
+ float_epsilon = value -> value
6765
+
6766
+ Sets the float epsilon for snow-math types. If snow-math is compiled to use
6767
+ single-precision floats, changing the epsilon for floats may cause the
6768
+ assigned value to lose precision itself in the cast, resulting in a subtly
6769
+ different epsilon than intended, as Ruby uses double-precision floats, which
6770
+ may lead you to think you're setting the epsilon to one value when it's
6771
+ another similar by not equal value.
6772
+
6773
+ Just be aware of what you're doing and the type of float you've compiled
6774
+ snow-math to use.
6775
+ */
6776
+ static VALUE sm_set_float_epsilon(VALUE sm_self, VALUE sm_value)
6777
+ {
6778
+ switch (TYPE(sm_value)) {
6779
+ case T_FLOAT:
6780
+ case T_FIXNUM:
6781
+ case T_BIGNUM:
6782
+ case T_RATIONAL:
6783
+ case T_COMPLEX: {
6784
+ S_FLOAT_EPSILON = (s_float_t)NUM2DBL(sm_value);
6785
+ break;
6786
+ }
6787
+ default: {
6788
+ VALUE sm_value_s = rb_any_to_s(sm_value);
6789
+ if (0) {
6790
+ case T_STRING:
6791
+ sm_value_s = sm_value;
6792
+ }
6793
+ S_FLOAT_EPSILON =
6794
+ #ifdef USE_FLOAT
6795
+ strtof(StringValueCStr(sm_value_s), NULL)
6796
+ #else
6797
+ strtod(StringValueCStr(sm_value_s), NULL)
6798
+ #endif
6799
+ ;
6800
+ break;
6801
+ }
6802
+ } /* switch (TYPE(sm_value)) */
6803
+ return sm_value;
6804
+ }
6805
+
6806
+
6903
6807
  void Init_bindings()
6904
6808
  {
6905
6809
  ID kRB_CONST_SIZE, kRB_CONST_LENGTH, kRB_CONST_FLOAT_SIZE, kRB_CONST_TYPE,
@@ -6909,10 +6813,6 @@ void Init_bindings()
6909
6813
  kRB_IVAR_MATHARRAY_LENGTH = rb_intern("__length");
6910
6814
  kRB_IVAR_MATHARRAY_CACHE = rb_intern("__cache");
6911
6815
  kRB_IVAR_MATHARRAY_SOURCE = rb_intern("__source");
6912
- kRB_CONST_SIZE = rb_intern("SIZE");
6913
- kRB_CONST_LENGTH = rb_intern("LENGTH");
6914
- kRB_CONST_FLOAT_SIZE = rb_intern("SNOW_MATH_FLOAT_SIZE");
6915
- kRB_CONST_TYPE = rb_intern("TYPE");
6916
6816
  kRB_SIZE_METHOD = rb_intern("size");
6917
6817
  kRB_BYTESIZE_METHOD = rb_intern("bytesize");
6918
6818
 
@@ -6929,19 +6829,25 @@ void Init_bindings()
6929
6829
  s_sm_mat3_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat3", rb_cData);
6930
6830
  s_sm_mat4_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat4", rb_cData);
6931
6831
 
6932
- rb_const_set(s_sm_snowmath_mod, kRB_CONST_FLOAT_SIZE, INT2FIX(sizeof(s_float_t)));
6933
- rb_const_set(s_sm_vec2_klass, kRB_CONST_SIZE, INT2FIX(sizeof(vec2_t)));
6934
- rb_const_set(s_sm_vec3_klass, kRB_CONST_SIZE, INT2FIX(sizeof(vec3_t)));
6935
- rb_const_set(s_sm_vec4_klass, kRB_CONST_SIZE, INT2FIX(sizeof(vec4_t)));
6936
- rb_const_set(s_sm_quat_klass, kRB_CONST_SIZE, INT2FIX(sizeof(quat_t)));
6937
- rb_const_set(s_sm_mat3_klass, kRB_CONST_SIZE, INT2FIX(sizeof(mat3_t)));
6938
- rb_const_set(s_sm_mat4_klass, kRB_CONST_SIZE, INT2FIX(sizeof(mat4_t)));
6939
- rb_const_set(s_sm_vec2_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(vec2_t) / sizeof(s_float_t)));
6940
- rb_const_set(s_sm_vec3_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(vec3_t) / sizeof(s_float_t)));
6941
- rb_const_set(s_sm_vec4_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(vec4_t) / sizeof(s_float_t)));
6942
- rb_const_set(s_sm_quat_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(quat_t) / sizeof(s_float_t)));
6943
- rb_const_set(s_sm_mat3_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(mat3_t) / sizeof(s_float_t)));
6944
- rb_const_set(s_sm_mat4_klass, kRB_CONST_LENGTH, INT2FIX(sizeof(mat4_t) / sizeof(s_float_t)));
6832
+ rb_define_const(s_sm_snowmath_mod, "SNOW_MATH_FLOAT_SIZE", INT2FIX(sizeof(s_float_t)));
6833
+ rb_define_const(s_sm_snowmath_mod, "SNOW_MATH_DEFAULT_FLOAT_EPSILON", DBL2NUM(S_FLOAT_EPSILON));
6834
+ rb_define_const(s_sm_snowmath_mod, "DEGREES_TO_RADIANS", DBL2NUM(S_DEG2RAD));
6835
+ rb_define_const(s_sm_snowmath_mod, "RADIANS_TO_DEGREES", DBL2NUM(S_RAD2DEG));
6836
+ rb_define_const(s_sm_vec2_klass, "SIZE", INT2FIX(sizeof(vec2_t)));
6837
+ rb_define_const(s_sm_vec3_klass, "SIZE", INT2FIX(sizeof(vec3_t)));
6838
+ rb_define_const(s_sm_vec4_klass, "SIZE", INT2FIX(sizeof(vec4_t)));
6839
+ rb_define_const(s_sm_quat_klass, "SIZE", INT2FIX(sizeof(quat_t)));
6840
+ rb_define_const(s_sm_mat3_klass, "SIZE", INT2FIX(sizeof(mat3_t)));
6841
+ rb_define_const(s_sm_mat4_klass, "SIZE", INT2FIX(sizeof(mat4_t)));
6842
+ rb_define_const(s_sm_vec2_klass, "LENGTH", INT2FIX(sizeof(vec2_t) / sizeof(s_float_t)));
6843
+ rb_define_const(s_sm_vec3_klass, "LENGTH", INT2FIX(sizeof(vec3_t) / sizeof(s_float_t)));
6844
+ rb_define_const(s_sm_vec4_klass, "LENGTH", INT2FIX(sizeof(vec4_t) / sizeof(s_float_t)));
6845
+ rb_define_const(s_sm_quat_klass, "LENGTH", INT2FIX(sizeof(quat_t) / sizeof(s_float_t)));
6846
+ rb_define_const(s_sm_mat3_klass, "LENGTH", INT2FIX(sizeof(mat3_t) / sizeof(s_float_t)));
6847
+ rb_define_const(s_sm_mat4_klass, "LENGTH", INT2FIX(sizeof(mat4_t) / sizeof(s_float_t)));
6848
+
6849
+ rb_define_singleton_method(s_sm_snowmath_mod, "float_epsilon=", sm_set_float_epsilon, 1);
6850
+ rb_define_singleton_method(s_sm_snowmath_mod, "float_epsilon", sm_get_float_epsilon, 0);
6945
6851
 
6946
6852
  rb_define_singleton_method(s_sm_vec2_klass, "new", sm_vec2_new, -1);
6947
6853
  rb_define_method(s_sm_vec2_klass, "initialize", sm_vec2_init, -1);
@@ -7126,9 +7032,9 @@ void Init_bindings()
7126
7032
  #if BUILD_ARRAY_TYPE
7127
7033
 
7128
7034
  s_sm_vec2_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec2Array", rb_cData);
7129
- rb_const_set(s_sm_vec2_array_klass, kRB_CONST_TYPE, s_sm_vec2_klass);
7035
+ rb_define_const(s_sm_vec2_array_klass, "TYPE", s_sm_vec2_klass);
7130
7036
  rb_define_singleton_method(s_sm_vec2_array_klass, "new", sm_vec2_array_new, 1);
7131
- rb_define_method(s_sm_vec2_array_klass, "freeze", sm_vec2_array_freeze, 0);
7037
+ rb_define_method(s_sm_vec2_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7132
7038
  rb_define_method(s_sm_vec2_array_klass, "fetch", sm_vec2_array_fetch, 1);
7133
7039
  rb_define_method(s_sm_vec2_array_klass, "store", sm_vec2_array_store, 2);
7134
7040
  rb_define_method(s_sm_vec2_array_klass, "resize!", sm_vec2_array_resize, 1);
@@ -7138,9 +7044,9 @@ void Init_bindings()
7138
7044
  rb_alias(s_sm_vec2_array_klass, kRB_BYTESIZE_METHOD, kRB_SIZE_METHOD);
7139
7045
 
7140
7046
  s_sm_vec3_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec3Array", rb_cData);
7141
- rb_const_set(s_sm_vec3_array_klass, kRB_CONST_TYPE, s_sm_vec3_klass);
7047
+ rb_define_const(s_sm_vec3_array_klass, "TYPE", s_sm_vec3_klass);
7142
7048
  rb_define_singleton_method(s_sm_vec3_array_klass, "new", sm_vec3_array_new, 1);
7143
- rb_define_method(s_sm_vec3_array_klass, "freeze", sm_vec3_array_freeze, 0);
7049
+ rb_define_method(s_sm_vec3_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7144
7050
  rb_define_method(s_sm_vec3_array_klass, "fetch", sm_vec3_array_fetch, 1);
7145
7051
  rb_define_method(s_sm_vec3_array_klass, "store", sm_vec3_array_store, 2);
7146
7052
  rb_define_method(s_sm_vec3_array_klass, "resize!", sm_vec3_array_resize, 1);
@@ -7150,9 +7056,9 @@ void Init_bindings()
7150
7056
  rb_alias(s_sm_vec3_array_klass, kRB_BYTESIZE_METHOD, kRB_SIZE_METHOD);
7151
7057
 
7152
7058
  s_sm_vec4_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec4Array", rb_cData);
7153
- rb_const_set(s_sm_vec4_array_klass, kRB_CONST_TYPE, s_sm_vec4_klass);
7059
+ rb_define_const(s_sm_vec4_array_klass, "TYPE", s_sm_vec4_klass);
7154
7060
  rb_define_singleton_method(s_sm_vec4_array_klass, "new", sm_vec4_array_new, 1);
7155
- rb_define_method(s_sm_vec4_array_klass, "freeze", sm_vec4_array_freeze, 0);
7061
+ rb_define_method(s_sm_vec4_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7156
7062
  rb_define_method(s_sm_vec4_array_klass, "fetch", sm_vec4_array_fetch, 1);
7157
7063
  rb_define_method(s_sm_vec4_array_klass, "store", sm_vec4_array_store, 2);
7158
7064
  rb_define_method(s_sm_vec4_array_klass, "resize!", sm_vec4_array_resize, 1);
@@ -7162,9 +7068,9 @@ void Init_bindings()
7162
7068
  rb_alias(s_sm_vec4_array_klass, kRB_BYTESIZE_METHOD, kRB_SIZE_METHOD);
7163
7069
 
7164
7070
  s_sm_quat_array_klass = rb_define_class_under(s_sm_snowmath_mod, "QuatArray", rb_cData);
7165
- rb_const_set(s_sm_quat_array_klass, kRB_CONST_TYPE, s_sm_quat_klass);
7071
+ rb_define_const(s_sm_quat_array_klass, "TYPE", s_sm_quat_klass);
7166
7072
  rb_define_singleton_method(s_sm_quat_array_klass, "new", sm_quat_array_new, 1);
7167
- rb_define_method(s_sm_quat_array_klass, "freeze", sm_quat_array_freeze, 0);
7073
+ rb_define_method(s_sm_quat_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7168
7074
  rb_define_method(s_sm_quat_array_klass, "fetch", sm_quat_array_fetch, 1);
7169
7075
  rb_define_method(s_sm_quat_array_klass, "store", sm_quat_array_store, 2);
7170
7076
  rb_define_method(s_sm_quat_array_klass, "resize!", sm_quat_array_resize, 1);
@@ -7174,9 +7080,9 @@ void Init_bindings()
7174
7080
  rb_alias(s_sm_quat_array_klass, kRB_BYTESIZE_METHOD, kRB_SIZE_METHOD);
7175
7081
 
7176
7082
  s_sm_mat3_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat3Array", rb_cData);
7177
- rb_const_set(s_sm_mat3_array_klass, kRB_CONST_TYPE, s_sm_mat3_klass);
7083
+ rb_define_const(s_sm_mat3_array_klass, "TYPE", s_sm_mat3_klass);
7178
7084
  rb_define_singleton_method(s_sm_mat3_array_klass, "new", sm_mat3_array_new, 1);
7179
- rb_define_method(s_sm_mat3_array_klass, "freeze", sm_mat3_array_freeze, 0);
7085
+ rb_define_method(s_sm_mat3_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7180
7086
  rb_define_method(s_sm_mat3_array_klass, "fetch", sm_mat3_array_fetch, 1);
7181
7087
  rb_define_method(s_sm_mat3_array_klass, "store", sm_mat3_array_store, 2);
7182
7088
  rb_define_method(s_sm_mat3_array_klass, "resize!", sm_mat3_array_resize, 1);
@@ -7186,9 +7092,9 @@ void Init_bindings()
7186
7092
  rb_alias(s_sm_mat3_array_klass, kRB_BYTESIZE_METHOD, kRB_SIZE_METHOD);
7187
7093
 
7188
7094
  s_sm_mat4_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat4Array", rb_cData);
7189
- rb_const_set(s_sm_mat4_array_klass, kRB_CONST_TYPE, s_sm_mat4_klass);
7095
+ rb_define_const(s_sm_mat4_array_klass, "TYPE", s_sm_mat4_klass);
7190
7096
  rb_define_singleton_method(s_sm_mat4_array_klass, "new", sm_mat4_array_new, 1);
7191
- rb_define_method(s_sm_mat4_array_klass, "freeze", sm_mat4_array_freeze, 0);
7097
+ rb_define_method(s_sm_mat4_array_klass, "freeze", sm_mathtype_array_freeze, 0);
7192
7098
  rb_define_method(s_sm_mat4_array_klass, "fetch", sm_mat4_array_fetch, 1);
7193
7099
  rb_define_method(s_sm_mat4_array_klass, "store", sm_mat4_array_store, 2);
7194
7100
  rb_define_method(s_sm_mat4_array_klass, "resize!", sm_mat4_array_resize, 1);
@@ -136,6 +136,47 @@ class Snow::Mat3
136
136
  scale x, y, z, self
137
137
  end
138
138
 
139
+ #
140
+ # Returns the pitch (X-axis rotation) of this matrix in degrees. This assumes
141
+ # the matrix is orthogonal.
142
+ #
143
+ def pitch
144
+ tx = self[6]
145
+ tz = self[8]
146
+ Math::atan2(
147
+ self[7],
148
+ Math::sqrt(tx * tx + tz * tz)) * ::Snow::RADIANS_TO_DEGREES
149
+ end
150
+
151
+ #
152
+ # Returns the yaw (Y-axis rotation) of this matrix in degrees. This assumes
153
+ # the matrix is orthogonal.
154
+ #
155
+ def yaw
156
+ -Math::atan2(self[6], self[8]) * ::Snow::RADIANS_TO_DEGREES
157
+ end
158
+
159
+ #
160
+ # Returns the roll (Z-axis rotation) of this matrix in degrees. This assumes
161
+ # the matrix is orthogonal.
162
+ #
163
+ def roll
164
+ Math::atan2(self[1], self[4]) * ::Snow::RADIANS_TO_DEGREES
165
+ end
166
+
167
+ #
168
+ # call-seq:
169
+ # orthogonal? -> true or false
170
+ #
171
+ # Returns whether self is an orthogonal matrix (its columns and rows are all
172
+ # unit vectors). Note that this allocates a new matrix. You probably don't
173
+ # want to call it often.
174
+ #
175
+ def orthogonal?
176
+ temp = self.transpose
177
+ multiply_mat3(temp, temp) == IDENTITY
178
+ end
179
+
139
180
 
140
181
  alias_method :*, :multiply
141
182
  alias_method :**, :scale
@@ -162,6 +162,46 @@ class Snow::Mat4
162
162
  inverse_general self
163
163
  end
164
164
 
165
+ #
166
+ # Returns the pitch (X-axis rotation) of this matrix in degrees. This assumes
167
+ # the matrix is orthogonal.
168
+ #
169
+ def pitch
170
+ tx = self[8]
171
+ tz = self[10]
172
+ Math::atan2(
173
+ self[9],
174
+ Math::sqrt(tx * tx + tz * tz)) * ::Snow::RADIANS_TO_DEGREES
175
+ end
176
+
177
+ #
178
+ # Returns the yaw (Y-axis rotation) of this matrix in degrees. This assumes
179
+ # the matrix is orthogonal.
180
+ #
181
+ def yaw
182
+ -Math::atan2(self[8], self[10]) * ::Snow::RADIANS_TO_DEGREES
183
+ end
184
+
185
+ #
186
+ # Returns the roll (Z-axis rotation) of this matrix in degrees. This assumes
187
+ # the matrix is orthogonal.
188
+ #
189
+ def roll
190
+ Math::atan2(self[1], self[5]) * ::Snow::RADIANS_TO_DEGREES
191
+ end
192
+
193
+ #
194
+ # call-seq:
195
+ # orthogonal? -> true or false
196
+ #
197
+ # Returns whether self is an orthogonal matrix (its columns and rows are all
198
+ # unit vectors). Note that this allocates a new matrix.
199
+ #
200
+ def orthogonal?
201
+ temp = self.transpose
202
+ multiply_mat4(temp, temp) == IDENTITY
203
+ end
204
+
165
205
 
166
206
  alias_method :*, :multiply
167
207
  alias_method :**, :scale
@@ -7,6 +7,6 @@ module Snow
7
7
  #
8
8
  # snow-math bindings version string.
9
9
  #
10
- SNOW_MATH_VERSION = '1.6.1'
10
+ SNOW_MATH_VERSION = '1.7.0'
11
11
 
12
12
  end
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.6.1
4
+ version: 1.7.0
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-28 00:00:00.000000000 Z
11
+ date: 2013-07-29 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