snow-math 1.6.0 → 1.6.1

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: 9fdcc6853dcceb46023eaa23da15f3b86831168b
4
- data.tar.gz: 0d4b55799ed535e0fa71eb75b077f78bf8b6805b
3
+ metadata.gz: 59c66cdb4331e39915f31821b06050210de0101b
4
+ data.tar.gz: 38339703c8a3dc316120129c559b5d5fe096c1a9
5
5
  SHA512:
6
- metadata.gz: c688599c54baa7c0f3af312d797d9f571bf6eed518f3cc2c7168f2591ab8bc112159e730853f0f0e1ec766cefc7e334f58e4b21637065433c32d02e632a94731
7
- data.tar.gz: 5cc0c1fe37a23f0477e538dce8b2ba2b042cbb02fd711aae10890a3039075e11580a61604ee6dfa56332a7a35460cb08a871ab3cd11b031a700b5f4da8de6366
6
+ metadata.gz: 848fb1b812af454cb1775db23d1cdd59f071c8f4f8dfbce4eb2315e760445a55ad6f02bb74443d25c6de9a521fdae2db837ca0087e2a6f8314211783ccb8b274
7
+ data.tar.gz: 3236a1958069e2d11086fcc688e30c13c8b141a2b034f24a085b0f1142a2f72bc1c680b00760b129a209d364ad54282f1812ff841a2091ccd17c2aa512862ac9
@@ -72,6 +72,7 @@ See COPYING for license information
72
72
  #endif
73
73
  #if BUILD_ARRAY_TYPE
74
74
 
75
+ static ID kRB_NAME_FREEZE;
75
76
  static ID kRB_IVAR_MATHARRAY_LENGTH;
76
77
  static ID kRB_IVAR_MATHARRAY_CACHE;
77
78
  static ID kRB_IVAR_MATHARRAY_SOURCE;
@@ -187,6 +188,37 @@ static VALUE sm_vec2_array_new(VALUE sm_self, VALUE sm_length_or_copy)
187
188
 
188
189
 
189
190
 
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
+
190
222
  /*
191
223
  * Resizes the array to new_length and returns self.
192
224
  *
@@ -275,6 +307,10 @@ static VALUE sm_vec2_array_fetch(VALUE sm_self, VALUE sm_index)
275
307
  rb_ary_store(sm_cache, (long)index, sm_inner);
276
308
  }
277
309
 
310
+ if (OBJ_FROZEN(sm_self)) {
311
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
312
+ }
313
+
278
314
  return sm_inner;
279
315
  }
280
316
 
@@ -382,6 +418,37 @@ static VALUE sm_vec3_array_new(VALUE sm_self, VALUE sm_length_or_copy)
382
418
 
383
419
 
384
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
+
385
452
  /*
386
453
  * Resizes the array to new_length and returns self.
387
454
  *
@@ -470,6 +537,10 @@ static VALUE sm_vec3_array_fetch(VALUE sm_self, VALUE sm_index)
470
537
  rb_ary_store(sm_cache, (long)index, sm_inner);
471
538
  }
472
539
 
540
+ if (OBJ_FROZEN(sm_self)) {
541
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
542
+ }
543
+
473
544
  return sm_inner;
474
545
  }
475
546
 
@@ -576,6 +647,37 @@ static VALUE sm_vec4_array_new(VALUE sm_self, VALUE sm_length_or_copy)
576
647
 
577
648
 
578
649
 
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
+
579
681
  /*
580
682
  * Resizes the array to new_length and returns self.
581
683
  *
@@ -664,6 +766,10 @@ static VALUE sm_vec4_array_fetch(VALUE sm_self, VALUE sm_index)
664
766
  rb_ary_store(sm_cache, (long)index, sm_inner);
665
767
  }
666
768
 
769
+ if (OBJ_FROZEN(sm_self)) {
770
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
771
+ }
772
+
667
773
  return sm_inner;
668
774
  }
669
775
 
@@ -770,6 +876,37 @@ static VALUE sm_quat_array_new(VALUE sm_self, VALUE sm_length_or_copy)
770
876
 
771
877
 
772
878
 
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
+
773
910
  /*
774
911
  * Resizes the array to new_length and returns self.
775
912
  *
@@ -858,6 +995,10 @@ static VALUE sm_quat_array_fetch(VALUE sm_self, VALUE sm_index)
858
995
  rb_ary_store(sm_cache, (long)index, sm_inner);
859
996
  }
860
997
 
998
+ if (OBJ_FROZEN(sm_self)) {
999
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
1000
+ }
1001
+
861
1002
  return sm_inner;
862
1003
  }
863
1004
 
@@ -964,6 +1105,37 @@ static VALUE sm_mat3_array_new(VALUE sm_self, VALUE sm_length_or_copy)
964
1105
 
965
1106
 
966
1107
 
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
+
967
1139
  /*
968
1140
  * Resizes the array to new_length and returns self.
969
1141
  *
@@ -1052,6 +1224,10 @@ static VALUE sm_mat3_array_fetch(VALUE sm_self, VALUE sm_index)
1052
1224
  rb_ary_store(sm_cache, (long)index, sm_inner);
1053
1225
  }
1054
1226
 
1227
+ if (OBJ_FROZEN(sm_self)) {
1228
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
1229
+ }
1230
+
1055
1231
  return sm_inner;
1056
1232
  }
1057
1233
 
@@ -1164,6 +1340,37 @@ static VALUE sm_mat4_array_new(VALUE sm_self, VALUE sm_length_or_copy)
1164
1340
 
1165
1341
 
1166
1342
 
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
+
1167
1374
  /*
1168
1375
  * Resizes the array to new_length and returns self.
1169
1376
  *
@@ -1252,6 +1459,10 @@ static VALUE sm_mat4_array_fetch(VALUE sm_self, VALUE sm_index)
1252
1459
  rb_ary_store(sm_cache, (long)index, sm_inner);
1253
1460
  }
1254
1461
 
1462
+ if (OBJ_FROZEN(sm_self)) {
1463
+ rb_funcall2(sm_inner, kRB_NAME_FREEZE, 0, 0);
1464
+ }
1465
+
1255
1466
  return sm_inner;
1256
1467
  }
1257
1468
 
@@ -6694,6 +6905,7 @@ void Init_bindings()
6694
6905
  ID kRB_CONST_SIZE, kRB_CONST_LENGTH, kRB_CONST_FLOAT_SIZE, kRB_CONST_TYPE,
6695
6906
  kRB_SIZE_METHOD, kRB_BYTESIZE_METHOD;
6696
6907
 
6908
+ kRB_NAME_FREEZE = rb_intern("freeze");
6697
6909
  kRB_IVAR_MATHARRAY_LENGTH = rb_intern("__length");
6698
6910
  kRB_IVAR_MATHARRAY_CACHE = rb_intern("__cache");
6699
6911
  kRB_IVAR_MATHARRAY_SOURCE = rb_intern("__source");
@@ -6916,6 +7128,7 @@ void Init_bindings()
6916
7128
  s_sm_vec2_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec2Array", rb_cData);
6917
7129
  rb_const_set(s_sm_vec2_array_klass, kRB_CONST_TYPE, s_sm_vec2_klass);
6918
7130
  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);
6919
7132
  rb_define_method(s_sm_vec2_array_klass, "fetch", sm_vec2_array_fetch, 1);
6920
7133
  rb_define_method(s_sm_vec2_array_klass, "store", sm_vec2_array_store, 2);
6921
7134
  rb_define_method(s_sm_vec2_array_klass, "resize!", sm_vec2_array_resize, 1);
@@ -6927,6 +7140,7 @@ void Init_bindings()
6927
7140
  s_sm_vec3_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec3Array", rb_cData);
6928
7141
  rb_const_set(s_sm_vec3_array_klass, kRB_CONST_TYPE, s_sm_vec3_klass);
6929
7142
  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);
6930
7144
  rb_define_method(s_sm_vec3_array_klass, "fetch", sm_vec3_array_fetch, 1);
6931
7145
  rb_define_method(s_sm_vec3_array_klass, "store", sm_vec3_array_store, 2);
6932
7146
  rb_define_method(s_sm_vec3_array_klass, "resize!", sm_vec3_array_resize, 1);
@@ -6938,6 +7152,7 @@ void Init_bindings()
6938
7152
  s_sm_vec4_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Vec4Array", rb_cData);
6939
7153
  rb_const_set(s_sm_vec4_array_klass, kRB_CONST_TYPE, s_sm_vec4_klass);
6940
7154
  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);
6941
7156
  rb_define_method(s_sm_vec4_array_klass, "fetch", sm_vec4_array_fetch, 1);
6942
7157
  rb_define_method(s_sm_vec4_array_klass, "store", sm_vec4_array_store, 2);
6943
7158
  rb_define_method(s_sm_vec4_array_klass, "resize!", sm_vec4_array_resize, 1);
@@ -6949,6 +7164,7 @@ void Init_bindings()
6949
7164
  s_sm_quat_array_klass = rb_define_class_under(s_sm_snowmath_mod, "QuatArray", rb_cData);
6950
7165
  rb_const_set(s_sm_quat_array_klass, kRB_CONST_TYPE, s_sm_quat_klass);
6951
7166
  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);
6952
7168
  rb_define_method(s_sm_quat_array_klass, "fetch", sm_quat_array_fetch, 1);
6953
7169
  rb_define_method(s_sm_quat_array_klass, "store", sm_quat_array_store, 2);
6954
7170
  rb_define_method(s_sm_quat_array_klass, "resize!", sm_quat_array_resize, 1);
@@ -6960,6 +7176,7 @@ void Init_bindings()
6960
7176
  s_sm_mat3_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat3Array", rb_cData);
6961
7177
  rb_const_set(s_sm_mat3_array_klass, kRB_CONST_TYPE, s_sm_mat3_klass);
6962
7178
  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);
6963
7180
  rb_define_method(s_sm_mat3_array_klass, "fetch", sm_mat3_array_fetch, 1);
6964
7181
  rb_define_method(s_sm_mat3_array_klass, "store", sm_mat3_array_store, 2);
6965
7182
  rb_define_method(s_sm_mat3_array_klass, "resize!", sm_mat3_array_resize, 1);
@@ -6971,6 +7188,7 @@ void Init_bindings()
6971
7188
  s_sm_mat4_array_klass = rb_define_class_under(s_sm_snowmath_mod, "Mat4Array", rb_cData);
6972
7189
  rb_const_set(s_sm_mat4_array_klass, kRB_CONST_TYPE, s_sm_mat4_klass);
6973
7190
  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);
6974
7192
  rb_define_method(s_sm_mat4_array_klass, "fetch", sm_mat4_array_fetch, 1);
6975
7193
  rb_define_method(s_sm_mat4_array_klass, "store", sm_mat4_array_store, 2);
6976
7194
  rb_define_method(s_sm_mat4_array_klass, "resize!", sm_mat4_array_resize, 1);
@@ -28,6 +28,10 @@ end
28
28
  #
29
29
  class Snow::Mat3
30
30
 
31
+ IDENTITY = self.new.freeze
32
+ ONE = self.new(Array.new(9, 1)).freeze
33
+ ZERO = self.new(Array.new(9, 0)).freeze
34
+
31
35
  class << self ; alias_method :[], :new ; end
32
36
 
33
37
  alias_method :[], :fetch
@@ -110,9 +114,10 @@ class Snow::Mat3
110
114
  #
111
115
  # Calls #multiply(rhs, self).
112
116
  #
113
- # call-seq: multiply!(mat3) -> self
114
- # call-seq: multiply!(vec3) -> vec3
115
- # call-seq: multiply!(scalar) -> self
117
+ # call-seq:
118
+ # multiply!(mat3) -> self
119
+ # multiply!(vec3) -> vec3
120
+ # multiply!(scalar) -> self
116
121
  #
117
122
  def multiply!(rhs)
118
123
  multiply rhs, case rhs
@@ -29,6 +29,10 @@ end
29
29
  #
30
30
  class Snow::Mat4
31
31
 
32
+ IDENTITY = self.new.freeze
33
+ ONE = self.new(Array.new(16, 1)).freeze
34
+ ZERO = self.new(Array.new(16, 0)).freeze
35
+
32
36
  class << self ; alias_method :[], :new ; end
33
37
 
34
38
  alias_method :[], :fetch
@@ -137,8 +141,9 @@ class Snow::Mat4
137
141
 
138
142
  # Calls #translate(*args, self)
139
143
  #
140
- # call-seq: translate!(vec3) -> self
141
- # call-seq: translate!(x, y, z) -> self
144
+ # call-seq:
145
+ # translate!(vec3) -> self
146
+ # translate!(x, y, z) -> self
142
147
  def translate!(*args)
143
148
  translate(*args, self)
144
149
  end
@@ -25,6 +25,16 @@ end
25
25
  #
26
26
  class Snow::Quat
27
27
 
28
+ POS_X = self.new(1, 0, 0, 1).freeze
29
+ POS_Y = self.new(0, 1, 0, 1).freeze
30
+ POS_Z = self.new(0, 0, 1, 1).freeze
31
+ NEG_X = self.new(-1, 0, 0, 1).freeze
32
+ NEG_Y = self.new(0, -1, 0, 1).freeze
33
+ NEG_Z = self.new(0, 0, -1, 1).freeze
34
+ ONE = self.new(1, 1, 1, 1).freeze
35
+ ZERO = self.new(0, 0, 0, 0).freeze
36
+ IDENTITY = self.new(0, 0, 0, 1).freeze
37
+
28
38
  class << self ; alias_method :[], :new ; end
29
39
 
30
40
  alias_method :[], :fetch
@@ -28,6 +28,13 @@ end
28
28
  #
29
29
  class Snow::Vec2
30
30
 
31
+ POS_X = self.new(1, 0).freeze
32
+ POS_Y = self.new(0, 1).freeze
33
+ NEG_X = self.new(-1, 0).freeze
34
+ NEG_Y = self.new(0, -1).freeze
35
+ ONE = self.new(1, 1).freeze
36
+ ZERO = self.new.freeze
37
+
31
38
  class << self ; alias_method :[], :new ; end
32
39
 
33
40
  alias_method :[], :fetch
@@ -27,6 +27,15 @@ end
27
27
  #
28
28
  class Snow::Vec3
29
29
 
30
+ POS_X = self.new(1, 0, 0).freeze
31
+ POS_Y = self.new(0, 1, 0).freeze
32
+ POS_Z = self.new(0, 0, 1).freeze
33
+ NEG_X = self.new(-1, 0, 0).freeze
34
+ NEG_Y = self.new(0, -1, 0).freeze
35
+ NEG_Z = self.new(0, 0, -1).freeze
36
+ ONE = self.new(1, 1, 1).freeze
37
+ ZERO = self.new.freeze
38
+
30
39
  # Shortcut through to new
31
40
  class << self ; alias_method :[], :new ; end
32
41
 
@@ -27,6 +27,16 @@ end
27
27
  #
28
28
  class Snow::Vec4
29
29
 
30
+ POS_X = self.new(1, 0, 0, 1).freeze
31
+ POS_Y = self.new(0, 1, 0, 1).freeze
32
+ POS_Z = self.new(0, 0, 1, 1).freeze
33
+ NEG_X = self.new(-1, 0, 0, 1).freeze
34
+ NEG_Y = self.new(0, -1, 0, 1).freeze
35
+ NEG_Z = self.new(0, 0, -1, 1).freeze
36
+ ONE = self.new(1, 1, 1, 1).freeze
37
+ ZERO = self.new(0, 0, 0, 0).freeze
38
+ IDENTITY = self.new(0, 0, 0, 1).freeze
39
+
30
40
  class << self ; alias_method :[], :new ; end
31
41
 
32
42
  alias_method :[], :fetch
@@ -7,6 +7,6 @@ module Snow
7
7
  #
8
8
  # snow-math bindings version string.
9
9
  #
10
- SNOW_MATH_VERSION = '1.6.0'
10
+ SNOW_MATH_VERSION = '1.6.1'
11
11
 
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snow-math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Raymond Cower