snow-math 1.5.3 → 1.6.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: 3a51bb323669b2f4f06bba42373bee886ff6fe5b
4
- data.tar.gz: 89770e67ef087bd254efd4138ffa60acf345baac
3
+ metadata.gz: 9fdcc6853dcceb46023eaa23da15f3b86831168b
4
+ data.tar.gz: 0d4b55799ed535e0fa71eb75b077f78bf8b6805b
5
5
  SHA512:
6
- metadata.gz: c88c4b0e95a1791b79ce954cd5411e17468a37fa603c00066fdd80133ee4b5275299afed4f0705962bc211d2d2f0c4c2ac6ee550be226a15df313af36386853a
7
- data.tar.gz: 39428e2b13941b242a1b642c901751bf857ca08740b57e602c5f8b42653490543a7834e3c9ebf756a48f107bb363589c2cc1e9e43e9696a1748ec3418b42e82a
6
+ metadata.gz: c688599c54baa7c0f3af312d797d9f571bf6eed518f3cc2c7168f2591ab8bc112159e730853f0f0e1ec766cefc7e334f58e4b21637065433c32d02e632a94731
7
+ data.tar.gz: 5cc0c1fe37a23f0477e538dce8b2ba2b042cbb02fd711aae10890a3039075e11580a61604ee6dfa56332a7a35460cb08a871ab3cd11b031a700b5f4da8de6366
@@ -24,12 +24,12 @@ const mat3_t g_mat3_identity = {
24
24
 
25
25
 
26
26
 
27
- // Rows
27
+ /* Rows */
28
28
  #define S_MR 0
29
29
  #define S_MS 3
30
30
  #define S_MT 6
31
31
 
32
- // row components
32
+ /* row components */
33
33
  #define S_MR_X 0
34
34
  #define S_MR_Y 1
35
35
  #define S_MR_Z 2
@@ -40,7 +40,7 @@ const mat3_t g_mat3_identity = {
40
40
  #define S_MT_Y 7
41
41
  #define S_MT_Z 8
42
42
 
43
- // columns
43
+ /* columns */
44
44
  #define S_MIR_X 0
45
45
  #define S_MIR_Y 3
46
46
  #define S_MIR_Z 6
@@ -684,7 +684,7 @@ void mat4_multiply(const mat4_t left, const mat4_t right, mat4_t out)
684
684
  mat4_t temp;
685
685
  vec4_t c;
686
686
 
687
- // Transpose the left matrix so we can be a little more cache-friendly.
687
+ /* Transpose the left matrix so we can be a little more cache-friendly. */
688
688
  mat4_transpose(left, temp);
689
689
 
690
690
  c[0] = temp[0];
@@ -209,6 +209,8 @@ static VALUE sm_vec2_array_resize(VALUE sm_self, VALUE sm_new_length)
209
209
  size_t new_length;
210
210
  size_t old_length;
211
211
 
212
+ rb_check_frozen(sm_self);
213
+
212
214
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
213
215
  new_length = NUM2SIZET(sm_new_length);
214
216
 
@@ -292,6 +294,8 @@ static VALUE sm_vec2_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
292
294
  size_t length = NUM2SIZET(sm_mathtype_array_length(sm_self));
293
295
  size_t index = NUM2SIZET(sm_index);
294
296
 
297
+ rb_check_frozen(sm_self);
298
+
295
299
  if (index >= length) {
296
300
  rb_raise(rb_eRangeError,
297
301
  "Index %zu out of bounds for array with length %zu",
@@ -400,6 +404,8 @@ static VALUE sm_vec3_array_resize(VALUE sm_self, VALUE sm_new_length)
400
404
  size_t new_length;
401
405
  size_t old_length;
402
406
 
407
+ rb_check_frozen(sm_self);
408
+
403
409
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
404
410
  new_length = NUM2SIZET(sm_new_length);
405
411
 
@@ -483,6 +489,8 @@ static VALUE sm_vec3_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
483
489
  size_t length = NUM2SIZET(sm_mathtype_array_length(sm_self));
484
490
  size_t index = NUM2SIZET(sm_index);
485
491
 
492
+ rb_check_frozen(sm_self);
493
+
486
494
  if (index >= length) {
487
495
  rb_raise(rb_eRangeError,
488
496
  "Index %zu out of bounds for array with length %zu",
@@ -590,6 +598,8 @@ static VALUE sm_vec4_array_resize(VALUE sm_self, VALUE sm_new_length)
590
598
  size_t new_length;
591
599
  size_t old_length;
592
600
 
601
+ rb_check_frozen(sm_self);
602
+
593
603
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
594
604
  new_length = NUM2SIZET(sm_new_length);
595
605
 
@@ -673,6 +683,8 @@ static VALUE sm_vec4_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
673
683
  size_t length = NUM2SIZET(sm_mathtype_array_length(sm_self));
674
684
  size_t index = NUM2SIZET(sm_index);
675
685
 
686
+ rb_check_frozen(sm_self);
687
+
676
688
  if (index >= length) {
677
689
  rb_raise(rb_eRangeError,
678
690
  "Index %zu out of bounds for array with length %zu",
@@ -780,6 +792,8 @@ static VALUE sm_quat_array_resize(VALUE sm_self, VALUE sm_new_length)
780
792
  size_t new_length;
781
793
  size_t old_length;
782
794
 
795
+ rb_check_frozen(sm_self);
796
+
783
797
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
784
798
  new_length = NUM2SIZET(sm_new_length);
785
799
 
@@ -863,6 +877,8 @@ static VALUE sm_quat_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
863
877
  size_t length = NUM2SIZET(sm_mathtype_array_length(sm_self));
864
878
  size_t index = NUM2SIZET(sm_index);
865
879
 
880
+ rb_check_frozen(sm_self);
881
+
866
882
  if (index >= length) {
867
883
  rb_raise(rb_eRangeError,
868
884
  "Index %zu out of bounds for array with length %zu",
@@ -970,6 +986,8 @@ static VALUE sm_mat3_array_resize(VALUE sm_self, VALUE sm_new_length)
970
986
  size_t new_length;
971
987
  size_t old_length;
972
988
 
989
+ rb_check_frozen(sm_self);
990
+
973
991
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
974
992
  new_length = NUM2SIZET(sm_new_length);
975
993
 
@@ -1056,6 +1074,8 @@ static VALUE sm_mat3_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
1056
1074
  size_t index = NUM2SIZET(sm_index);
1057
1075
  int is_mat3 = 0;
1058
1076
 
1077
+ rb_check_frozen(sm_self);
1078
+
1059
1079
  if (index >= length) {
1060
1080
  rb_raise(rb_eRangeError,
1061
1081
  "Index %zu out of bounds for array with length %zu",
@@ -1166,6 +1186,8 @@ static VALUE sm_mat4_array_resize(VALUE sm_self, VALUE sm_new_length)
1166
1186
  size_t new_length;
1167
1187
  size_t old_length;
1168
1188
 
1189
+ rb_check_frozen(sm_self);
1190
+
1169
1191
  old_length = NUM2SIZET(sm_mathtype_array_length(sm_self));
1170
1192
  new_length = NUM2SIZET(sm_new_length);
1171
1193
 
@@ -1252,6 +1274,8 @@ static VALUE sm_mat4_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value)
1252
1274
  size_t index = NUM2SIZET(sm_index);
1253
1275
  int is_mat4 = 0;
1254
1276
 
1277
+ rb_check_frozen(sm_self);
1278
+
1255
1279
  if (index >= length) {
1256
1280
  rb_raise(rb_eRangeError,
1257
1281
  "Index %zu out of bounds for array with length %zu",
@@ -1356,6 +1380,7 @@ static VALUE sm_vec2_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
1356
1380
  static const int max_index = sizeof(vec2_t) / sizeof(s_float_t);
1357
1381
  vec2_t *self = sm_unwrap_vec2(sm_self, NULL);
1358
1382
  int index = NUM2INT(sm_index);
1383
+ rb_check_frozen(sm_self);
1359
1384
  if (index < 0 || index >= max_index) {
1360
1385
  rb_raise(rb_eRangeError,
1361
1386
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -1398,35 +1423,37 @@ static VALUE sm_vec2_length (VALUE self)
1398
1423
  * call-seq:
1399
1424
  * copy(output = nil) -> output or new vec2
1400
1425
  */
1401
- static VALUE sm_vec2_copy(int argc, VALUE *argv, VALUE sm_self)
1402
- {
1403
- VALUE sm_out;
1404
- vec2_t *self;
1405
- rb_scan_args(argc, argv, "01", &sm_out);
1406
- self = sm_unwrap_vec2(sm_self, NULL);
1407
- if (argc == 1) {
1408
- if (!RTEST(sm_out)) {
1409
- goto SM_LABEL(skip_output);
1410
- }{
1411
- 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)) {
1412
- rb_raise(rb_eTypeError,
1413
- kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1414
- rb_obj_classname(sm_out));
1415
- return Qnil;
1416
- }
1417
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1418
- vec2_copy (*self, *output);
1419
- }} else if (argc == 0) {
1420
- SM_LABEL(skip_output): {
1421
- vec2_t output;
1422
- vec2_copy (*self, output);
1423
- sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1424
- rb_obj_call_init(sm_out, 0, 0);
1425
- }} else {
1426
- rb_raise(rb_eArgError, "Invalid number of arguments to copy");
1427
- }
1428
- return sm_out;
1429
- }
1426
+ static VALUE sm_vec2_copy(int argc, VALUE *argv, VALUE sm_self)
1427
+ {
1428
+ VALUE sm_out;
1429
+ vec2_t *self;
1430
+ rb_scan_args(argc, argv, "01", &sm_out);
1431
+ self = sm_unwrap_vec2(sm_self, NULL);
1432
+ if (argc == 1) {
1433
+ if (!RTEST(sm_out)) {
1434
+ goto SM_LABEL(skip_output);
1435
+ }{
1436
+ vec2_t *output;
1437
+ 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)) {
1438
+ rb_raise(rb_eTypeError,
1439
+ kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1440
+ rb_obj_classname(sm_out));
1441
+ return Qnil;
1442
+ }
1443
+ rb_check_frozen(sm_out);
1444
+ output = sm_unwrap_vec2(sm_out, NULL);
1445
+ vec2_copy (*self, *output);
1446
+ }} else if (argc == 0) {
1447
+ SM_LABEL(skip_output): {
1448
+ vec2_t output;
1449
+ vec2_copy (*self, output);
1450
+ sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1451
+ rb_obj_call_init(sm_out, 0, 0);
1452
+ }} else {
1453
+ rb_raise(rb_eArgError, "Invalid number of arguments to copy");
1454
+ }
1455
+ return sm_out;
1456
+ }
1430
1457
 
1431
1458
 
1432
1459
 
@@ -1437,35 +1464,37 @@ static VALUE sm_vec2_length (VALUE self)
1437
1464
  * call-seq:
1438
1465
  * normalize(output = nil) -> output or new vec2
1439
1466
  */
1440
- static VALUE sm_vec2_normalize(int argc, VALUE *argv, VALUE sm_self)
1441
- {
1442
- VALUE sm_out;
1443
- vec2_t *self;
1444
- rb_scan_args(argc, argv, "01", &sm_out);
1445
- self = sm_unwrap_vec2(sm_self, NULL);
1446
- if (argc == 1) {
1447
- if (!RTEST(sm_out)) {
1448
- goto SM_LABEL(skip_output);
1449
- }{
1450
- 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)) {
1451
- rb_raise(rb_eTypeError,
1452
- kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1453
- rb_obj_classname(sm_out));
1454
- return Qnil;
1455
- }
1456
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1457
- vec2_normalize (*self, *output);
1458
- }} else if (argc == 0) {
1459
- SM_LABEL(skip_output): {
1460
- vec2_t output;
1461
- vec2_normalize (*self, output);
1462
- sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1463
- rb_obj_call_init(sm_out, 0, 0);
1464
- }} else {
1465
- rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
1466
- }
1467
- return sm_out;
1468
- }
1467
+ static VALUE sm_vec2_normalize(int argc, VALUE *argv, VALUE sm_self)
1468
+ {
1469
+ VALUE sm_out;
1470
+ vec2_t *self;
1471
+ rb_scan_args(argc, argv, "01", &sm_out);
1472
+ self = sm_unwrap_vec2(sm_self, NULL);
1473
+ if (argc == 1) {
1474
+ if (!RTEST(sm_out)) {
1475
+ goto SM_LABEL(skip_output);
1476
+ }{
1477
+ vec2_t *output;
1478
+ 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)) {
1479
+ rb_raise(rb_eTypeError,
1480
+ kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1481
+ rb_obj_classname(sm_out));
1482
+ return Qnil;
1483
+ }
1484
+ rb_check_frozen(sm_out);
1485
+ output = sm_unwrap_vec2(sm_out, NULL);
1486
+ vec2_normalize (*self, *output);
1487
+ }} else if (argc == 0) {
1488
+ SM_LABEL(skip_output): {
1489
+ vec2_t output;
1490
+ vec2_normalize (*self, output);
1491
+ sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1492
+ rb_obj_call_init(sm_out, 0, 0);
1493
+ }} else {
1494
+ rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
1495
+ }
1496
+ return sm_out;
1497
+ }
1469
1498
 
1470
1499
 
1471
1500
 
@@ -1476,35 +1505,37 @@ static VALUE sm_vec2_length (VALUE self)
1476
1505
  * call-seq:
1477
1506
  * inverse(output = nil) -> output or new vec2
1478
1507
  */
1479
- static VALUE sm_vec2_inverse(int argc, VALUE *argv, VALUE sm_self)
1480
- {
1481
- VALUE sm_out;
1482
- vec2_t *self;
1483
- rb_scan_args(argc, argv, "01", &sm_out);
1484
- self = sm_unwrap_vec2(sm_self, NULL);
1485
- if (argc == 1) {
1486
- if (!RTEST(sm_out)) {
1487
- goto SM_LABEL(skip_output);
1488
- }{
1489
- 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)) {
1490
- rb_raise(rb_eTypeError,
1491
- kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1492
- rb_obj_classname(sm_out));
1493
- return Qnil;
1494
- }
1495
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1496
- vec2_inverse (*self, *output);
1497
- }} else if (argc == 0) {
1498
- SM_LABEL(skip_output): {
1499
- vec2_t output;
1500
- vec2_inverse (*self, output);
1501
- sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1502
- rb_obj_call_init(sm_out, 0, 0);
1503
- }} else {
1504
- rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
1505
- }
1506
- return sm_out;
1507
- }
1508
+ static VALUE sm_vec2_inverse(int argc, VALUE *argv, VALUE sm_self)
1509
+ {
1510
+ VALUE sm_out;
1511
+ vec2_t *self;
1512
+ rb_scan_args(argc, argv, "01", &sm_out);
1513
+ self = sm_unwrap_vec2(sm_self, NULL);
1514
+ if (argc == 1) {
1515
+ if (!RTEST(sm_out)) {
1516
+ goto SM_LABEL(skip_output);
1517
+ }{
1518
+ vec2_t *output;
1519
+ 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)) {
1520
+ rb_raise(rb_eTypeError,
1521
+ kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1522
+ rb_obj_classname(sm_out));
1523
+ return Qnil;
1524
+ }
1525
+ rb_check_frozen(sm_out);
1526
+ output = sm_unwrap_vec2(sm_out, NULL);
1527
+ vec2_inverse (*self, *output);
1528
+ }} else if (argc == 0) {
1529
+ SM_LABEL(skip_output): {
1530
+ vec2_t output;
1531
+ vec2_inverse (*self, output);
1532
+ sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1533
+ rb_obj_call_init(sm_out, 0, 0);
1534
+ }} else {
1535
+ rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
1536
+ }
1537
+ return sm_out;
1538
+ }
1508
1539
 
1509
1540
 
1510
1541
 
@@ -1514,35 +1545,37 @@ static VALUE sm_vec2_length (VALUE self)
1514
1545
  * call-seq:
1515
1546
  * negate(output = nil) -> output or new vec2
1516
1547
  */
1517
- static VALUE sm_vec2_negate(int argc, VALUE *argv, VALUE sm_self)
1518
- {
1519
- VALUE sm_out;
1520
- vec2_t *self;
1521
- rb_scan_args(argc, argv, "01", &sm_out);
1522
- self = sm_unwrap_vec2(sm_self, NULL);
1523
- if (argc == 1) {
1524
- if (!RTEST(sm_out)) {
1525
- goto SM_LABEL(skip_output);
1526
- }{
1527
- if (!SM_IS_A(sm_out, vec2) && !SM_IS_A(sm_out, vec2) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
1528
- rb_raise(rb_eTypeError,
1529
- kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1530
- rb_obj_classname(sm_out));
1531
- return Qnil;
1532
- }
1533
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1534
- vec2_negate (*self, *output);
1535
- }} else if (argc == 0) {
1536
- SM_LABEL(skip_output): {
1537
- vec2_t output;
1538
- vec2_negate (*self, output);
1539
- sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1540
- rb_obj_call_init(sm_out, 0, 0);
1541
- }} else {
1542
- rb_raise(rb_eArgError, "Invalid number of arguments to negate");
1543
- }
1544
- return sm_out;
1545
- }
1548
+ static VALUE sm_vec2_negate(int argc, VALUE *argv, VALUE sm_self)
1549
+ {
1550
+ VALUE sm_out;
1551
+ vec2_t *self;
1552
+ rb_scan_args(argc, argv, "01", &sm_out);
1553
+ self = sm_unwrap_vec2(sm_self, NULL);
1554
+ if (argc == 1) {
1555
+ if (!RTEST(sm_out)) {
1556
+ goto SM_LABEL(skip_output);
1557
+ }{
1558
+ vec2_t *output;
1559
+ if (!SM_IS_A(sm_out, vec2) && !SM_IS_A(sm_out, vec2) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
1560
+ rb_raise(rb_eTypeError,
1561
+ kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1562
+ rb_obj_classname(sm_out));
1563
+ return Qnil;
1564
+ }
1565
+ rb_check_frozen(sm_out);
1566
+ output = sm_unwrap_vec2(sm_out, NULL);
1567
+ vec2_negate (*self, *output);
1568
+ }} else if (argc == 0) {
1569
+ SM_LABEL(skip_output): {
1570
+ vec2_t output;
1571
+ vec2_negate (*self, output);
1572
+ sm_out = sm_wrap_vec2(output, rb_obj_class(sm_self));
1573
+ rb_obj_call_init(sm_out, 0, 0);
1574
+ }} else {
1575
+ rb_raise(rb_eArgError, "Invalid number of arguments to negate");
1576
+ }
1577
+ return sm_out;
1578
+ }
1546
1579
 
1547
1580
 
1548
1581
 
@@ -1571,13 +1604,15 @@ static VALUE sm_vec2_project(int argc, VALUE *argv, VALUE sm_self)
1571
1604
  if (!RTEST(sm_out)) {
1572
1605
  goto SM_LABEL(skip_output);
1573
1606
  }{
1607
+ vec2_t *output;
1574
1608
  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)) {
1575
1609
  rb_raise(rb_eTypeError,
1576
1610
  kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1577
1611
  rb_obj_classname(sm_out));
1578
1612
  return Qnil;
1579
1613
  }
1580
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1614
+ rb_check_frozen(sm_out);
1615
+ output = sm_unwrap_vec2(sm_out, NULL);
1581
1616
  vec2_project(*self, *rhs, *output);
1582
1617
  }} else if (argc == 1) {
1583
1618
  SM_LABEL(skip_output): {
@@ -1618,13 +1653,15 @@ static VALUE sm_vec2_reflect(int argc, VALUE *argv, VALUE sm_self)
1618
1653
  if (!RTEST(sm_out)) {
1619
1654
  goto SM_LABEL(skip_output);
1620
1655
  }{
1656
+ vec2_t *output;
1621
1657
  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)) {
1622
1658
  rb_raise(rb_eTypeError,
1623
1659
  kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1624
1660
  rb_obj_classname(sm_out));
1625
1661
  return Qnil;
1626
1662
  }
1627
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1663
+ rb_check_frozen(sm_out);
1664
+ output = sm_unwrap_vec2(sm_out, NULL);
1628
1665
  vec2_reflect(*self, *rhs, *output);
1629
1666
  }} else if (argc == 1) {
1630
1667
  SM_LABEL(skip_output): {
@@ -1666,13 +1703,15 @@ static VALUE sm_vec2_multiply(int argc, VALUE *argv, VALUE sm_self)
1666
1703
  if (!RTEST(sm_out)) {
1667
1704
  goto SM_LABEL(skip_output);
1668
1705
  }{
1706
+ vec2_t *output;
1669
1707
  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)) {
1670
1708
  rb_raise(rb_eTypeError,
1671
1709
  kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1672
1710
  rb_obj_classname(sm_out));
1673
1711
  return Qnil;
1674
1712
  }
1675
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1713
+ rb_check_frozen(sm_out);
1714
+ output = sm_unwrap_vec2(sm_out, NULL);
1676
1715
  vec2_multiply(*self, *rhs, *output);
1677
1716
  }} else if (argc == 1) {
1678
1717
  SM_LABEL(skip_output): {
@@ -1713,13 +1752,15 @@ static VALUE sm_vec2_add(int argc, VALUE *argv, VALUE sm_self)
1713
1752
  if (!RTEST(sm_out)) {
1714
1753
  goto SM_LABEL(skip_output);
1715
1754
  }{
1755
+ vec2_t *output;
1716
1756
  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)) {
1717
1757
  rb_raise(rb_eTypeError,
1718
1758
  kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1719
1759
  rb_obj_classname(sm_out));
1720
1760
  return Qnil;
1721
1761
  }
1722
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1762
+ rb_check_frozen(sm_out);
1763
+ output = sm_unwrap_vec2(sm_out, NULL);
1723
1764
  vec2_add(*self, *rhs, *output);
1724
1765
  }} else if (argc == 1) {
1725
1766
  SM_LABEL(skip_output): {
@@ -1761,13 +1802,15 @@ static VALUE sm_vec2_subtract(int argc, VALUE *argv, VALUE sm_self)
1761
1802
  if (!RTEST(sm_out)) {
1762
1803
  goto SM_LABEL(skip_output);
1763
1804
  }{
1805
+ vec2_t *output;
1764
1806
  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)) {
1765
1807
  rb_raise(rb_eTypeError,
1766
1808
  kSM_WANT_TWO_TO_FOUR_FORMAT_LIT,
1767
1809
  rb_obj_classname(sm_out));
1768
1810
  return Qnil;
1769
1811
  }
1770
- vec2_t *output = sm_unwrap_vec2(sm_out, NULL);
1812
+ rb_check_frozen(sm_out);
1813
+ output = sm_unwrap_vec2(sm_out, NULL);
1771
1814
  vec2_subtract(*self, *rhs, *output);
1772
1815
  }} else if (argc == 1) {
1773
1816
  SM_LABEL(skip_output): {
@@ -1849,12 +1892,14 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
1849
1892
  vec2_t *self = sm_unwrap_vec2(sm_self, NULL);
1850
1893
  size_t arr_index = 0;
1851
1894
 
1895
+ rb_check_frozen(sm_self);
1896
+
1852
1897
  switch(argc) {
1853
1898
 
1854
- // Default value
1899
+ /* Default value */
1855
1900
  case 0: { break; }
1856
1901
 
1857
- // Copy or by-array
1902
+ /* Copy or by-array */
1858
1903
  case 1: {
1859
1904
  if (SM_IS_A(argv[0], vec2) ||
1860
1905
  SM_IS_A(argv[0], vec3) ||
@@ -1864,7 +1909,7 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
1864
1909
  break;
1865
1910
  }
1866
1911
 
1867
- // Optional offset into array provided
1912
+ /* Optional offset into array provided */
1868
1913
  if (0) {
1869
1914
  case 2:
1870
1915
  if (!SM_RB_IS_A(argv[0], rb_cArray)) {
@@ -1875,7 +1920,7 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
1875
1920
  arr_index = NUM2SIZET(argv[1]);
1876
1921
  }
1877
1922
 
1878
- // Array of values
1923
+ /* Array of values */
1879
1924
  VALUE arrdata = argv[0];
1880
1925
  const size_t arr_end = arr_index + 2;
1881
1926
  s_float_t *vec_elem = *self;
@@ -1889,7 +1934,7 @@ static VALUE sm_vec2_init(int argc, VALUE *argv, VALUE sm_self)
1889
1934
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
1890
1935
  break;
1891
1936
  }
1892
- } // switch (argc)
1937
+ } /* switch (argc) */
1893
1938
 
1894
1939
  return sm_self;
1895
1940
  }
@@ -1960,6 +2005,7 @@ static VALUE sm_vec2_scale(int argc, VALUE *argv, VALUE sm_self)
1960
2005
  scalar = rb_num2dbl(sm_scalar);
1961
2006
 
1962
2007
  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)) {
2008
+ rb_check_frozen(sm_out);
1963
2009
  vec2_scale(*self, scalar, *sm_unwrap_vec2(sm_out, NULL));
1964
2010
  } else {
1965
2011
  vec2_t out;
@@ -1990,6 +2036,7 @@ static VALUE sm_vec2_divide(int argc, VALUE *argv, VALUE sm_self)
1990
2036
  scalar = rb_num2dbl(sm_scalar);
1991
2037
 
1992
2038
  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)) {
2039
+ rb_check_frozen(sm_out);
1993
2040
  vec2_divide(*self, scalar, *sm_unwrap_vec2(sm_out, NULL));
1994
2041
  } else {
1995
2042
  vec2_t out;
@@ -2086,6 +2133,7 @@ static VALUE sm_vec3_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
2086
2133
  static const int max_index = sizeof(vec3_t) / sizeof(s_float_t);
2087
2134
  vec3_t *self = sm_unwrap_vec3(sm_self, NULL);
2088
2135
  int index = NUM2INT(sm_index);
2136
+ rb_check_frozen(sm_self);
2089
2137
  if (index < 0 || index >= max_index) {
2090
2138
  rb_raise(rb_eRangeError,
2091
2139
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -2128,35 +2176,37 @@ static VALUE sm_vec3_length (VALUE self)
2128
2176
  * call-seq:
2129
2177
  * copy(output = nil) -> output or new vec3
2130
2178
  */
2131
- static VALUE sm_vec3_copy(int argc, VALUE *argv, VALUE sm_self)
2132
- {
2133
- VALUE sm_out;
2134
- vec3_t *self;
2135
- rb_scan_args(argc, argv, "01", &sm_out);
2136
- self = sm_unwrap_vec3(sm_self, NULL);
2137
- if (argc == 1) {
2138
- if (!RTEST(sm_out)) {
2139
- goto SM_LABEL(skip_output);
2140
- }{
2141
- if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2142
- rb_raise(rb_eTypeError,
2143
- kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2144
- rb_obj_classname(sm_out));
2145
- return Qnil;
2146
- }
2147
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2148
- vec3_copy (*self, *output);
2149
- }} else if (argc == 0) {
2150
- SM_LABEL(skip_output): {
2151
- vec3_t output;
2152
- vec3_copy (*self, output);
2153
- sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2154
- rb_obj_call_init(sm_out, 0, 0);
2155
- }} else {
2156
- rb_raise(rb_eArgError, "Invalid number of arguments to copy");
2157
- }
2158
- return sm_out;
2159
- }
2179
+ static VALUE sm_vec3_copy(int argc, VALUE *argv, VALUE sm_self)
2180
+ {
2181
+ VALUE sm_out;
2182
+ vec3_t *self;
2183
+ rb_scan_args(argc, argv, "01", &sm_out);
2184
+ self = sm_unwrap_vec3(sm_self, NULL);
2185
+ if (argc == 1) {
2186
+ if (!RTEST(sm_out)) {
2187
+ goto SM_LABEL(skip_output);
2188
+ }{
2189
+ vec3_t *output;
2190
+ if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2191
+ rb_raise(rb_eTypeError,
2192
+ kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2193
+ rb_obj_classname(sm_out));
2194
+ return Qnil;
2195
+ }
2196
+ rb_check_frozen(sm_out);
2197
+ output = sm_unwrap_vec3(sm_out, NULL);
2198
+ vec3_copy (*self, *output);
2199
+ }} else if (argc == 0) {
2200
+ SM_LABEL(skip_output): {
2201
+ vec3_t output;
2202
+ vec3_copy (*self, output);
2203
+ sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2204
+ rb_obj_call_init(sm_out, 0, 0);
2205
+ }} else {
2206
+ rb_raise(rb_eArgError, "Invalid number of arguments to copy");
2207
+ }
2208
+ return sm_out;
2209
+ }
2160
2210
 
2161
2211
 
2162
2212
 
@@ -2167,35 +2217,37 @@ static VALUE sm_vec3_length (VALUE self)
2167
2217
  * call-seq:
2168
2218
  * normalize(output = nil) -> output or new vec3
2169
2219
  */
2170
- static VALUE sm_vec3_normalize(int argc, VALUE *argv, VALUE sm_self)
2171
- {
2172
- VALUE sm_out;
2173
- vec3_t *self;
2174
- rb_scan_args(argc, argv, "01", &sm_out);
2175
- self = sm_unwrap_vec3(sm_self, NULL);
2176
- if (argc == 1) {
2177
- if (!RTEST(sm_out)) {
2178
- goto SM_LABEL(skip_output);
2179
- }{
2180
- if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2181
- rb_raise(rb_eTypeError,
2182
- kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2183
- rb_obj_classname(sm_out));
2184
- return Qnil;
2185
- }
2186
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2187
- vec3_normalize (*self, *output);
2188
- }} else if (argc == 0) {
2189
- SM_LABEL(skip_output): {
2190
- vec3_t output;
2191
- vec3_normalize (*self, output);
2192
- sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2193
- rb_obj_call_init(sm_out, 0, 0);
2194
- }} else {
2195
- rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
2196
- }
2197
- return sm_out;
2198
- }
2220
+ static VALUE sm_vec3_normalize(int argc, VALUE *argv, VALUE sm_self)
2221
+ {
2222
+ VALUE sm_out;
2223
+ vec3_t *self;
2224
+ rb_scan_args(argc, argv, "01", &sm_out);
2225
+ self = sm_unwrap_vec3(sm_self, NULL);
2226
+ if (argc == 1) {
2227
+ if (!RTEST(sm_out)) {
2228
+ goto SM_LABEL(skip_output);
2229
+ }{
2230
+ vec3_t *output;
2231
+ if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2232
+ rb_raise(rb_eTypeError,
2233
+ kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2234
+ rb_obj_classname(sm_out));
2235
+ return Qnil;
2236
+ }
2237
+ rb_check_frozen(sm_out);
2238
+ output = sm_unwrap_vec3(sm_out, NULL);
2239
+ vec3_normalize (*self, *output);
2240
+ }} else if (argc == 0) {
2241
+ SM_LABEL(skip_output): {
2242
+ vec3_t output;
2243
+ vec3_normalize (*self, output);
2244
+ sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2245
+ rb_obj_call_init(sm_out, 0, 0);
2246
+ }} else {
2247
+ rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
2248
+ }
2249
+ return sm_out;
2250
+ }
2199
2251
 
2200
2252
 
2201
2253
 
@@ -2206,35 +2258,37 @@ static VALUE sm_vec3_length (VALUE self)
2206
2258
  * call-seq:
2207
2259
  * inverse(output = nil) -> output or new vec3
2208
2260
  */
2209
- static VALUE sm_vec3_inverse(int argc, VALUE *argv, VALUE sm_self)
2210
- {
2211
- VALUE sm_out;
2212
- vec3_t *self;
2213
- rb_scan_args(argc, argv, "01", &sm_out);
2214
- self = sm_unwrap_vec3(sm_self, NULL);
2215
- if (argc == 1) {
2216
- if (!RTEST(sm_out)) {
2217
- goto SM_LABEL(skip_output);
2218
- }{
2219
- if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2220
- rb_raise(rb_eTypeError,
2221
- kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2222
- rb_obj_classname(sm_out));
2223
- return Qnil;
2224
- }
2225
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2226
- vec3_inverse (*self, *output);
2227
- }} else if (argc == 0) {
2228
- SM_LABEL(skip_output): {
2229
- vec3_t output;
2230
- vec3_inverse (*self, output);
2231
- sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2232
- rb_obj_call_init(sm_out, 0, 0);
2233
- }} else {
2234
- rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
2235
- }
2236
- return sm_out;
2237
- }
2261
+ static VALUE sm_vec3_inverse(int argc, VALUE *argv, VALUE sm_self)
2262
+ {
2263
+ VALUE sm_out;
2264
+ vec3_t *self;
2265
+ rb_scan_args(argc, argv, "01", &sm_out);
2266
+ self = sm_unwrap_vec3(sm_self, NULL);
2267
+ if (argc == 1) {
2268
+ if (!RTEST(sm_out)) {
2269
+ goto SM_LABEL(skip_output);
2270
+ }{
2271
+ vec3_t *output;
2272
+ if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2273
+ rb_raise(rb_eTypeError,
2274
+ kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2275
+ rb_obj_classname(sm_out));
2276
+ return Qnil;
2277
+ }
2278
+ rb_check_frozen(sm_out);
2279
+ output = sm_unwrap_vec3(sm_out, NULL);
2280
+ vec3_inverse (*self, *output);
2281
+ }} else if (argc == 0) {
2282
+ SM_LABEL(skip_output): {
2283
+ vec3_t output;
2284
+ vec3_inverse (*self, output);
2285
+ sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2286
+ rb_obj_call_init(sm_out, 0, 0);
2287
+ }} else {
2288
+ rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
2289
+ }
2290
+ return sm_out;
2291
+ }
2238
2292
 
2239
2293
 
2240
2294
 
@@ -2244,35 +2298,37 @@ static VALUE sm_vec3_length (VALUE self)
2244
2298
  * call-seq:
2245
2299
  * negate(output = nil) -> output or new vec3
2246
2300
  */
2247
- static VALUE sm_vec3_negate(int argc, VALUE *argv, VALUE sm_self)
2248
- {
2249
- VALUE sm_out;
2250
- vec3_t *self;
2251
- rb_scan_args(argc, argv, "01", &sm_out);
2252
- self = sm_unwrap_vec3(sm_self, NULL);
2253
- if (argc == 1) {
2254
- if (!RTEST(sm_out)) {
2255
- goto SM_LABEL(skip_output);
2256
- }{
2257
- if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2258
- rb_raise(rb_eTypeError,
2259
- kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2260
- rb_obj_classname(sm_out));
2261
- return Qnil;
2262
- }
2263
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2264
- vec3_negate (*self, *output);
2265
- }} else if (argc == 0) {
2266
- SM_LABEL(skip_output): {
2267
- vec3_t output;
2268
- vec3_negate (*self, output);
2269
- sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2270
- rb_obj_call_init(sm_out, 0, 0);
2271
- }} else {
2272
- rb_raise(rb_eArgError, "Invalid number of arguments to negate");
2273
- }
2274
- return sm_out;
2275
- }
2301
+ static VALUE sm_vec3_negate(int argc, VALUE *argv, VALUE sm_self)
2302
+ {
2303
+ VALUE sm_out;
2304
+ vec3_t *self;
2305
+ rb_scan_args(argc, argv, "01", &sm_out);
2306
+ self = sm_unwrap_vec3(sm_self, NULL);
2307
+ if (argc == 1) {
2308
+ if (!RTEST(sm_out)) {
2309
+ goto SM_LABEL(skip_output);
2310
+ }{
2311
+ vec3_t *output;
2312
+ if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2313
+ rb_raise(rb_eTypeError,
2314
+ kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2315
+ rb_obj_classname(sm_out));
2316
+ return Qnil;
2317
+ }
2318
+ rb_check_frozen(sm_out);
2319
+ output = sm_unwrap_vec3(sm_out, NULL);
2320
+ vec3_negate (*self, *output);
2321
+ }} else if (argc == 0) {
2322
+ SM_LABEL(skip_output): {
2323
+ vec3_t output;
2324
+ vec3_negate (*self, output);
2325
+ sm_out = sm_wrap_vec3(output, rb_obj_class(sm_self));
2326
+ rb_obj_call_init(sm_out, 0, 0);
2327
+ }} else {
2328
+ rb_raise(rb_eArgError, "Invalid number of arguments to negate");
2329
+ }
2330
+ return sm_out;
2331
+ }
2276
2332
 
2277
2333
 
2278
2334
 
@@ -2301,13 +2357,15 @@ static VALUE sm_vec3_project(int argc, VALUE *argv, VALUE sm_self)
2301
2357
  if (!RTEST(sm_out)) {
2302
2358
  goto SM_LABEL(skip_output);
2303
2359
  }{
2360
+ vec3_t *output;
2304
2361
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2305
2362
  rb_raise(rb_eTypeError,
2306
2363
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2307
2364
  rb_obj_classname(sm_out));
2308
2365
  return Qnil;
2309
2366
  }
2310
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2367
+ rb_check_frozen(sm_out);
2368
+ output = sm_unwrap_vec3(sm_out, NULL);
2311
2369
  vec3_project(*self, *rhs, *output);
2312
2370
  }} else if (argc == 1) {
2313
2371
  SM_LABEL(skip_output): {
@@ -2348,13 +2406,15 @@ static VALUE sm_vec3_reflect(int argc, VALUE *argv, VALUE sm_self)
2348
2406
  if (!RTEST(sm_out)) {
2349
2407
  goto SM_LABEL(skip_output);
2350
2408
  }{
2409
+ vec3_t *output;
2351
2410
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2352
2411
  rb_raise(rb_eTypeError,
2353
2412
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2354
2413
  rb_obj_classname(sm_out));
2355
2414
  return Qnil;
2356
2415
  }
2357
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2416
+ rb_check_frozen(sm_out);
2417
+ output = sm_unwrap_vec3(sm_out, NULL);
2358
2418
  vec3_reflect(*self, *rhs, *output);
2359
2419
  }} else if (argc == 1) {
2360
2420
  SM_LABEL(skip_output): {
@@ -2395,13 +2455,15 @@ static VALUE sm_vec3_cross_product(int argc, VALUE *argv, VALUE sm_self)
2395
2455
  if (!RTEST(sm_out)) {
2396
2456
  goto SM_LABEL(skip_output);
2397
2457
  }{
2458
+ vec3_t *output;
2398
2459
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2399
2460
  rb_raise(rb_eTypeError,
2400
2461
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2401
2462
  rb_obj_classname(sm_out));
2402
2463
  return Qnil;
2403
2464
  }
2404
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2465
+ rb_check_frozen(sm_out);
2466
+ output = sm_unwrap_vec3(sm_out, NULL);
2405
2467
  vec3_cross_product(*self, *rhs, *output);
2406
2468
  }} else if (argc == 1) {
2407
2469
  SM_LABEL(skip_output): {
@@ -2443,13 +2505,15 @@ static VALUE sm_vec3_multiply(int argc, VALUE *argv, VALUE sm_self)
2443
2505
  if (!RTEST(sm_out)) {
2444
2506
  goto SM_LABEL(skip_output);
2445
2507
  }{
2508
+ vec3_t *output;
2446
2509
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2447
2510
  rb_raise(rb_eTypeError,
2448
2511
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2449
2512
  rb_obj_classname(sm_out));
2450
2513
  return Qnil;
2451
2514
  }
2452
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2515
+ rb_check_frozen(sm_out);
2516
+ output = sm_unwrap_vec3(sm_out, NULL);
2453
2517
  vec3_multiply(*self, *rhs, *output);
2454
2518
  }} else if (argc == 1) {
2455
2519
  SM_LABEL(skip_output): {
@@ -2490,13 +2554,15 @@ static VALUE sm_vec3_add(int argc, VALUE *argv, VALUE sm_self)
2490
2554
  if (!RTEST(sm_out)) {
2491
2555
  goto SM_LABEL(skip_output);
2492
2556
  }{
2557
+ vec3_t *output;
2493
2558
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2494
2559
  rb_raise(rb_eTypeError,
2495
2560
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2496
2561
  rb_obj_classname(sm_out));
2497
2562
  return Qnil;
2498
2563
  }
2499
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2564
+ rb_check_frozen(sm_out);
2565
+ output = sm_unwrap_vec3(sm_out, NULL);
2500
2566
  vec3_add(*self, *rhs, *output);
2501
2567
  }} else if (argc == 1) {
2502
2568
  SM_LABEL(skip_output): {
@@ -2538,13 +2604,15 @@ static VALUE sm_vec3_subtract(int argc, VALUE *argv, VALUE sm_self)
2538
2604
  if (!RTEST(sm_out)) {
2539
2605
  goto SM_LABEL(skip_output);
2540
2606
  }{
2607
+ vec3_t *output;
2541
2608
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2542
2609
  rb_raise(rb_eTypeError,
2543
2610
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
2544
2611
  rb_obj_classname(sm_out));
2545
2612
  return Qnil;
2546
2613
  }
2547
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
2614
+ rb_check_frozen(sm_out);
2615
+ output = sm_unwrap_vec3(sm_out, NULL);
2548
2616
  vec3_subtract(*self, *rhs, *output);
2549
2617
  }} else if (argc == 1) {
2550
2618
  SM_LABEL(skip_output): {
@@ -2623,12 +2691,14 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2623
2691
  vec3_t *self = sm_unwrap_vec3(sm_self, NULL);
2624
2692
  size_t arr_index = 0;
2625
2693
 
2694
+ rb_check_frozen(sm_self);
2695
+
2626
2696
  switch(argc) {
2627
2697
 
2628
- // Default value
2698
+ /* Default value */
2629
2699
  case 0: { break; }
2630
2700
 
2631
- // Copy or by-array
2701
+ /* Copy or by-array */
2632
2702
  case 1: {
2633
2703
  if (SM_IS_A(argv[0], vec3) ||
2634
2704
  SM_IS_A(argv[0], vec4) ||
@@ -2643,13 +2713,13 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2643
2713
  break;
2644
2714
  }
2645
2715
 
2646
- // Optional offset into array provided
2716
+ /* Optional offset into array provided */
2647
2717
  if (0) {
2648
2718
  case 2:
2649
2719
  arr_index = NUM2SIZET(argv[1]);
2650
2720
  }
2651
2721
 
2652
- // Array of values
2722
+ /* Array of values */
2653
2723
  if (SM_RB_IS_A(argv[0], rb_cArray)) {
2654
2724
  VALUE arrdata = argv[0];
2655
2725
  const size_t arr_end = arr_index + 3;
@@ -2664,7 +2734,7 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2664
2734
  break;
2665
2735
  }
2666
2736
 
2667
- // X, Y, Z
2737
+ /* X, Y, Z */
2668
2738
  case 3: {
2669
2739
  self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
2670
2740
  self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
@@ -2676,7 +2746,7 @@ static VALUE sm_vec3_init(int argc, VALUE *argv, VALUE sm_self)
2676
2746
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
2677
2747
  break;
2678
2748
  }
2679
- } // switch (argc)
2749
+ } /* switch (argc) */
2680
2750
 
2681
2751
  return sm_self;
2682
2752
  }
@@ -2746,7 +2816,8 @@ static VALUE sm_vec3_scale(int argc, VALUE *argv, VALUE sm_self)
2746
2816
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
2747
2817
  scalar = rb_num2dbl(sm_scalar);
2748
2818
 
2749
- if (SM_IS_A(sm_out, vec3)) {
2819
+ if (SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
2820
+ rb_check_frozen(sm_out);
2750
2821
  vec3_scale(*self, scalar, *sm_unwrap_vec3(sm_out, NULL));
2751
2822
  } else {
2752
2823
  vec3_t out;
@@ -2776,7 +2847,8 @@ static VALUE sm_vec3_divide(int argc, VALUE *argv, VALUE sm_self)
2776
2847
  rb_scan_args(argc, argv, "11", &sm_scalar, &sm_out);
2777
2848
  scalar = rb_num2dbl(sm_scalar);
2778
2849
 
2779
- if (SM_IS_A(sm_out, vec3)) {
2850
+ if (SM_IS_A(sm_out, vec3) || SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat)) {
2851
+ rb_check_frozen(sm_out);
2780
2852
  vec3_divide(*self, scalar, *sm_unwrap_vec3(sm_out, NULL));
2781
2853
  } else {
2782
2854
  vec3_t out;
@@ -2872,6 +2944,7 @@ static VALUE sm_vec4_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
2872
2944
  static const int max_index = sizeof(vec4_t) / sizeof(s_float_t);
2873
2945
  vec4_t *self = sm_unwrap_vec4(sm_self, NULL);
2874
2946
  int index = NUM2INT(sm_index);
2947
+ rb_check_frozen(sm_self);
2875
2948
  if (index < 0 || index >= max_index) {
2876
2949
  rb_raise(rb_eRangeError,
2877
2950
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -2914,35 +2987,37 @@ static VALUE sm_vec4_length (VALUE self)
2914
2987
  * call-seq:
2915
2988
  * copy(output = nil) -> output or new vec4 / quat
2916
2989
  */
2917
- static VALUE sm_vec4_copy(int argc, VALUE *argv, VALUE sm_self)
2918
- {
2919
- VALUE sm_out;
2920
- vec4_t *self;
2921
- rb_scan_args(argc, argv, "01", &sm_out);
2922
- self = sm_unwrap_vec4(sm_self, NULL);
2923
- if (argc == 1) {
2924
- if (!RTEST(sm_out)) {
2925
- goto SM_LABEL(skip_output);
2926
- }{
2927
- if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2928
- rb_raise(rb_eTypeError,
2929
- kSM_WANT_FOUR_FORMAT_LIT,
2930
- rb_obj_classname(sm_out));
2931
- return Qnil;
2932
- }
2933
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
2934
- vec4_copy (*self, *output);
2935
- }} else if (argc == 0) {
2936
- SM_LABEL(skip_output): {
2937
- vec4_t output;
2938
- vec4_copy (*self, output);
2939
- sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
2940
- rb_obj_call_init(sm_out, 0, 0);
2941
- }} else {
2942
- rb_raise(rb_eArgError, "Invalid number of arguments to copy");
2943
- }
2944
- return sm_out;
2945
- }
2990
+ static VALUE sm_vec4_copy(int argc, VALUE *argv, VALUE sm_self)
2991
+ {
2992
+ VALUE sm_out;
2993
+ vec4_t *self;
2994
+ rb_scan_args(argc, argv, "01", &sm_out);
2995
+ self = sm_unwrap_vec4(sm_self, NULL);
2996
+ if (argc == 1) {
2997
+ if (!RTEST(sm_out)) {
2998
+ goto SM_LABEL(skip_output);
2999
+ }{
3000
+ vec4_t *output;
3001
+ if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3002
+ rb_raise(rb_eTypeError,
3003
+ kSM_WANT_FOUR_FORMAT_LIT,
3004
+ rb_obj_classname(sm_out));
3005
+ return Qnil;
3006
+ }
3007
+ rb_check_frozen(sm_out);
3008
+ output = sm_unwrap_vec4(sm_out, NULL);
3009
+ vec4_copy (*self, *output);
3010
+ }} else if (argc == 0) {
3011
+ SM_LABEL(skip_output): {
3012
+ vec4_t output;
3013
+ vec4_copy (*self, output);
3014
+ sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3015
+ rb_obj_call_init(sm_out, 0, 0);
3016
+ }} else {
3017
+ rb_raise(rb_eArgError, "Invalid number of arguments to copy");
3018
+ }
3019
+ return sm_out;
3020
+ }
2946
3021
 
2947
3022
 
2948
3023
 
@@ -2953,34 +3028,36 @@ static VALUE sm_vec4_length (VALUE self)
2953
3028
  * call-seq:
2954
3029
  * normalize(output = nil) -> output or new vec4 / quat
2955
3030
  */
2956
- static VALUE sm_vec4_normalize(int argc, VALUE *argv, VALUE sm_self)
2957
- {
2958
- VALUE sm_out;
2959
- vec4_t *self;
2960
- rb_scan_args(argc, argv, "01", &sm_out);
2961
- self = sm_unwrap_vec4(sm_self, NULL);
2962
- if (argc == 1) {
2963
- if (!RTEST(sm_out)) {
2964
- goto SM_LABEL(skip_output);
2965
- }{
2966
- if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
2967
- rb_raise(rb_eTypeError,
2968
- kSM_WANT_FOUR_FORMAT_LIT,
2969
- rb_obj_classname(sm_out));
2970
- }
2971
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
2972
- vec4_normalize (*self, *output);
2973
- }} else if (argc == 0) {
2974
- SM_LABEL(skip_output): {
2975
- vec4_t output;
2976
- vec4_normalize (*self, output);
2977
- sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
2978
- rb_obj_call_init(sm_out, 0, 0);
2979
- }} else {
2980
- rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
2981
- }
2982
- return sm_out;
2983
- }
3031
+ static VALUE sm_vec4_normalize(int argc, VALUE *argv, VALUE sm_self)
3032
+ {
3033
+ VALUE sm_out;
3034
+ vec4_t *self;
3035
+ rb_scan_args(argc, argv, "01", &sm_out);
3036
+ self = sm_unwrap_vec4(sm_self, NULL);
3037
+ if (argc == 1) {
3038
+ if (!RTEST(sm_out)) {
3039
+ goto SM_LABEL(skip_output);
3040
+ }{
3041
+ vec4_t *output;
3042
+ if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3043
+ rb_raise(rb_eTypeError,
3044
+ kSM_WANT_FOUR_FORMAT_LIT,
3045
+ rb_obj_classname(sm_out));
3046
+ }
3047
+ rb_check_frozen(sm_out);
3048
+ output = sm_unwrap_vec4(sm_out, NULL);
3049
+ vec4_normalize (*self, *output);
3050
+ }} else if (argc == 0) {
3051
+ SM_LABEL(skip_output): {
3052
+ vec4_t output;
3053
+ vec4_normalize (*self, output);
3054
+ sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3055
+ rb_obj_call_init(sm_out, 0, 0);
3056
+ }} else {
3057
+ rb_raise(rb_eArgError, "Invalid number of arguments to normalize");
3058
+ }
3059
+ return sm_out;
3060
+ }
2984
3061
 
2985
3062
 
2986
3063
 
@@ -2991,35 +3068,37 @@ static VALUE sm_vec4_length (VALUE self)
2991
3068
  * call-seq:
2992
3069
  * inverse(output = nil) -> output or new vec4
2993
3070
  */
2994
- static VALUE sm_vec4_inverse(int argc, VALUE *argv, VALUE sm_self)
2995
- {
2996
- VALUE sm_out;
2997
- vec4_t *self;
2998
- rb_scan_args(argc, argv, "01", &sm_out);
2999
- self = sm_unwrap_vec4(sm_self, NULL);
3000
- if (argc == 1) {
3001
- if (!RTEST(sm_out)) {
3002
- goto SM_LABEL(skip_output);
3003
- }{
3004
- if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3005
- rb_raise(rb_eTypeError,
3006
- kSM_WANT_FOUR_FORMAT_LIT,
3007
- rb_obj_classname(sm_out));
3008
- return Qnil;
3009
- }
3010
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3011
- vec4_inverse (*self, *output);
3012
- }} else if (argc == 0) {
3013
- SM_LABEL(skip_output): {
3014
- vec4_t output;
3015
- vec4_inverse (*self, output);
3016
- sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3017
- rb_obj_call_init(sm_out, 0, 0);
3018
- }} else {
3019
- rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
3020
- }
3021
- return sm_out;
3022
- }
3071
+ static VALUE sm_vec4_inverse(int argc, VALUE *argv, VALUE sm_self)
3072
+ {
3073
+ VALUE sm_out;
3074
+ vec4_t *self;
3075
+ rb_scan_args(argc, argv, "01", &sm_out);
3076
+ self = sm_unwrap_vec4(sm_self, NULL);
3077
+ if (argc == 1) {
3078
+ if (!RTEST(sm_out)) {
3079
+ goto SM_LABEL(skip_output);
3080
+ }{
3081
+ vec4_t *output;
3082
+ if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3083
+ rb_raise(rb_eTypeError,
3084
+ kSM_WANT_FOUR_FORMAT_LIT,
3085
+ rb_obj_classname(sm_out));
3086
+ return Qnil;
3087
+ }
3088
+ rb_check_frozen(sm_out);
3089
+ output = sm_unwrap_vec4(sm_out, NULL);
3090
+ vec4_inverse (*self, *output);
3091
+ }} else if (argc == 0) {
3092
+ SM_LABEL(skip_output): {
3093
+ vec4_t output;
3094
+ vec4_inverse (*self, output);
3095
+ sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3096
+ rb_obj_call_init(sm_out, 0, 0);
3097
+ }} else {
3098
+ rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
3099
+ }
3100
+ return sm_out;
3101
+ }
3023
3102
 
3024
3103
 
3025
3104
 
@@ -3029,35 +3108,37 @@ static VALUE sm_vec4_length (VALUE self)
3029
3108
  * call-seq:
3030
3109
  * negate(output = nil) -> output or new vec4 or quat
3031
3110
  */
3032
- static VALUE sm_vec4_negate(int argc, VALUE *argv, VALUE sm_self)
3033
- {
3034
- VALUE sm_out;
3035
- vec4_t *self;
3036
- rb_scan_args(argc, argv, "01", &sm_out);
3037
- self = sm_unwrap_vec4(sm_self, NULL);
3038
- if (argc == 1) {
3039
- if (!RTEST(sm_out)) {
3040
- goto SM_LABEL(skip_output);
3041
- }{
3042
- if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3043
- rb_raise(rb_eTypeError,
3044
- kSM_WANT_FOUR_FORMAT_LIT,
3045
- rb_obj_classname(sm_out));
3046
- return Qnil;
3047
- }
3048
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3049
- vec4_negate (*self, *output);
3050
- }} else if (argc == 0) {
3051
- SM_LABEL(skip_output): {
3052
- vec4_t output;
3053
- vec4_negate (*self, output);
3054
- sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3055
- rb_obj_call_init(sm_out, 0, 0);
3056
- }} else {
3057
- rb_raise(rb_eArgError, "Invalid number of arguments to negate");
3058
- }
3059
- return sm_out;
3060
- }
3111
+ static VALUE sm_vec4_negate(int argc, VALUE *argv, VALUE sm_self)
3112
+ {
3113
+ VALUE sm_out;
3114
+ vec4_t *self;
3115
+ rb_scan_args(argc, argv, "01", &sm_out);
3116
+ self = sm_unwrap_vec4(sm_self, NULL);
3117
+ if (argc == 1) {
3118
+ if (!RTEST(sm_out)) {
3119
+ goto SM_LABEL(skip_output);
3120
+ }{
3121
+ vec4_t *output;
3122
+ if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3123
+ rb_raise(rb_eTypeError,
3124
+ kSM_WANT_FOUR_FORMAT_LIT,
3125
+ rb_obj_classname(sm_out));
3126
+ return Qnil;
3127
+ }
3128
+ rb_check_frozen(sm_out);
3129
+ output = sm_unwrap_vec4(sm_out, NULL);
3130
+ vec4_negate (*self, *output);
3131
+ }} else if (argc == 0) {
3132
+ SM_LABEL(skip_output): {
3133
+ vec4_t output;
3134
+ vec4_negate (*self, output);
3135
+ sm_out = sm_wrap_vec4(output, rb_obj_class(sm_self));
3136
+ rb_obj_call_init(sm_out, 0, 0);
3137
+ }} else {
3138
+ rb_raise(rb_eArgError, "Invalid number of arguments to negate");
3139
+ }
3140
+ return sm_out;
3141
+ }
3061
3142
 
3062
3143
 
3063
3144
 
@@ -3086,13 +3167,15 @@ static VALUE sm_vec4_project(int argc, VALUE *argv, VALUE sm_self)
3086
3167
  if (!RTEST(sm_out)) {
3087
3168
  goto SM_LABEL(skip_output);
3088
3169
  }{
3170
+ vec4_t *output;
3089
3171
  if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3090
3172
  rb_raise(rb_eTypeError,
3091
3173
  kSM_WANT_FOUR_FORMAT_LIT,
3092
3174
  rb_obj_classname(sm_out));
3093
3175
  return Qnil;
3094
3176
  }
3095
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3177
+ rb_check_frozen(sm_out);
3178
+ output = sm_unwrap_vec4(sm_out, NULL);
3096
3179
  vec4_project(*self, *rhs, *output);
3097
3180
  }} else if (argc == 1) {
3098
3181
  SM_LABEL(skip_output): {
@@ -3133,13 +3216,15 @@ static VALUE sm_vec4_reflect(int argc, VALUE *argv, VALUE sm_self)
3133
3216
  if (!RTEST(sm_out)) {
3134
3217
  goto SM_LABEL(skip_output);
3135
3218
  }{
3219
+ vec4_t *output;
3136
3220
  if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3137
3221
  rb_raise(rb_eTypeError,
3138
3222
  kSM_WANT_FOUR_FORMAT_LIT,
3139
3223
  rb_obj_classname(sm_out));
3140
3224
  return Qnil;
3141
3225
  }
3142
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3226
+ rb_check_frozen(sm_out);
3227
+ output = sm_unwrap_vec4(sm_out, NULL);
3143
3228
  vec4_reflect(*self, *rhs, *output);
3144
3229
  }} else if (argc == 1) {
3145
3230
  SM_LABEL(skip_output): {
@@ -3181,13 +3266,15 @@ static VALUE sm_vec4_multiply(int argc, VALUE *argv, VALUE sm_self)
3181
3266
  if (!RTEST(sm_out)) {
3182
3267
  goto SM_LABEL(skip_output);
3183
3268
  }{
3269
+ vec4_t *output;
3184
3270
  if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3185
3271
  rb_raise(rb_eTypeError,
3186
3272
  kSM_WANT_FOUR_FORMAT_LIT,
3187
3273
  rb_obj_classname(sm_out));
3188
3274
  return Qnil;
3189
3275
  }
3190
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3276
+ rb_check_frozen(sm_out);
3277
+ output = sm_unwrap_vec4(sm_out, NULL);
3191
3278
  vec4_multiply(*self, *rhs, *output);
3192
3279
  }} else if (argc == 1) {
3193
3280
  SM_LABEL(skip_output): {
@@ -3229,13 +3316,15 @@ static VALUE sm_vec4_add(int argc, VALUE *argv, VALUE sm_self)
3229
3316
  if (!RTEST(sm_out)) {
3230
3317
  goto SM_LABEL(skip_output);
3231
3318
  }{
3319
+ vec4_t *output;
3232
3320
  if (!SM_IS_A(sm_rhs, vec4) && !SM_IS_A(sm_rhs, quat)) {
3233
3321
  rb_raise(rb_eTypeError,
3234
3322
  kSM_WANT_FOUR_FORMAT_LIT,
3235
3323
  rb_obj_classname(sm_rhs));
3236
3324
  return Qnil;
3237
3325
  }
3238
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3326
+ rb_check_frozen(sm_out);
3327
+ output = sm_unwrap_vec4(sm_out, NULL);
3239
3328
  vec4_add(*self, *rhs, *output);
3240
3329
  }} else if (argc == 1) {
3241
3330
  SM_LABEL(skip_output): {
@@ -3277,13 +3366,15 @@ static VALUE sm_vec4_subtract(int argc, VALUE *argv, VALUE sm_self)
3277
3366
  if (!RTEST(sm_out)) {
3278
3367
  goto SM_LABEL(skip_output);
3279
3368
  }{
3369
+ vec4_t *output;
3280
3370
  if (!SM_IS_A(sm_rhs, vec4) && !SM_IS_A(sm_rhs, quat)) {
3281
3371
  rb_raise(rb_eTypeError,
3282
3372
  kSM_WANT_FOUR_FORMAT_LIT,
3283
3373
  rb_obj_classname(sm_rhs));
3284
3374
  return Qnil;
3285
3375
  }
3286
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
3376
+ rb_check_frozen(sm_out);
3377
+ output = sm_unwrap_vec4(sm_out, NULL);
3287
3378
  vec4_subtract(*self, *rhs, *output);
3288
3379
  }} else if (argc == 1) {
3289
3380
  SM_LABEL(skip_output): {
@@ -3360,12 +3451,14 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3360
3451
  vec4_t *self = sm_unwrap_vec4(sm_self, NULL);
3361
3452
  size_t arr_index = 0;
3362
3453
 
3454
+ rb_check_frozen(sm_self);
3455
+
3363
3456
  switch(argc) {
3364
3457
 
3365
- // Default value
3458
+ /* Default value */
3366
3459
  case 0: { break; }
3367
3460
 
3368
- // Copy or by-array
3461
+ /* Copy or by-array */
3369
3462
  case 1: {
3370
3463
  if (SM_IS_A(argv[0], quat) ||
3371
3464
  SM_IS_A(argv[0], vec4)) {
@@ -3386,13 +3479,13 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3386
3479
  break;
3387
3480
  }
3388
3481
 
3389
- // Optional offset into array provided
3482
+ /* Optional offset into array provided */
3390
3483
  if (0) {
3391
3484
  case 2:
3392
3485
  arr_index = NUM2SIZET(argv[1]);
3393
3486
  }
3394
3487
 
3395
- // Array of values
3488
+ /* Array of values */
3396
3489
  if (SM_RB_IS_A(argv[0], rb_cArray)) {
3397
3490
  VALUE arrdata = argv[0];
3398
3491
  const size_t arr_end = arr_index + 4;
@@ -3407,10 +3500,10 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3407
3500
  break;
3408
3501
  }
3409
3502
 
3410
- // W
3503
+ /* W */
3411
3504
  case 4: {
3412
3505
  self[0][3] = (s_float_t)rb_num2dbl(argv[3]);
3413
- case 3: // X, Y, Z
3506
+ case 3: /* X, Y, Z */
3414
3507
  self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
3415
3508
  self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
3416
3509
  self[0][2] = (s_float_t)rb_num2dbl(argv[2]);
@@ -3421,7 +3514,7 @@ static VALUE sm_vec4_init(int argc, VALUE *argv, VALUE sm_self)
3421
3514
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
3422
3515
  break;
3423
3516
  }
3424
- } // switch (argc)
3517
+ } /* switch (argc) */
3425
3518
 
3426
3519
  return sm_self;
3427
3520
  }
@@ -3493,6 +3586,7 @@ static VALUE sm_vec4_scale(int argc, VALUE *argv, VALUE sm_self)
3493
3586
  scalar = rb_num2dbl(sm_scalar);
3494
3587
 
3495
3588
  if ((SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat))) {
3589
+ rb_check_frozen(sm_out);
3496
3590
  vec4_scale(*self, scalar, *sm_unwrap_vec4(sm_out, NULL));
3497
3591
  } else {
3498
3592
  vec4_t out;
@@ -3524,6 +3618,7 @@ static VALUE sm_vec4_divide(int argc, VALUE *argv, VALUE sm_self)
3524
3618
  scalar = rb_num2dbl(sm_scalar);
3525
3619
 
3526
3620
  if ((SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat))) {
3621
+ rb_check_frozen(sm_out);
3527
3622
  vec4_divide(*self, scalar, *sm_unwrap_vec4(sm_out, NULL));
3528
3623
  } else {
3529
3624
  vec4_t out;
@@ -3618,6 +3713,7 @@ static VALUE sm_quat_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
3618
3713
  static const int max_index = sizeof(quat_t) / sizeof(s_float_t);
3619
3714
  quat_t *self = sm_unwrap_quat(sm_self, NULL);
3620
3715
  int index = NUM2INT(sm_index);
3716
+ rb_check_frozen(sm_self);
3621
3717
  if (index < 0 || index >= max_index) {
3622
3718
  rb_raise(rb_eRangeError,
3623
3719
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -3661,35 +3757,37 @@ static VALUE sm_quat_length (VALUE self)
3661
3757
  * call-seq:
3662
3758
  * inverse(output = nil) -> output or new quat
3663
3759
  */
3664
- static VALUE sm_quat_inverse(int argc, VALUE *argv, VALUE sm_self)
3665
- {
3666
- VALUE sm_out;
3667
- quat_t *self;
3668
- rb_scan_args(argc, argv, "01", &sm_out);
3669
- self = sm_unwrap_quat(sm_self, NULL);
3670
- if (argc == 1) {
3671
- if (!RTEST(sm_out)) {
3672
- goto SM_LABEL(skip_output);
3673
- }{
3674
- if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3675
- rb_raise(rb_eTypeError,
3676
- kSM_WANT_FOUR_FORMAT_LIT,
3677
- rb_obj_classname(sm_out));
3678
- return Qnil;
3679
- }
3680
- quat_t *output = sm_unwrap_quat(sm_out, NULL);
3681
- quat_inverse (*self, *output);
3682
- }} else if (argc == 0) {
3683
- SM_LABEL(skip_output): {
3684
- quat_t output;
3685
- quat_inverse (*self, output);
3686
- sm_out = sm_wrap_quat(output, rb_obj_class(sm_self));
3687
- rb_obj_call_init(sm_out, 0, 0);
3688
- }} else {
3689
- rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
3690
- }
3691
- return sm_out;
3692
- }
3760
+ static VALUE sm_quat_inverse(int argc, VALUE *argv, VALUE sm_self)
3761
+ {
3762
+ VALUE sm_out;
3763
+ quat_t *self;
3764
+ rb_scan_args(argc, argv, "01", &sm_out);
3765
+ self = sm_unwrap_quat(sm_self, NULL);
3766
+ if (argc == 1) {
3767
+ if (!RTEST(sm_out)) {
3768
+ goto SM_LABEL(skip_output);
3769
+ }{
3770
+ quat_t *output;
3771
+ if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3772
+ rb_raise(rb_eTypeError,
3773
+ kSM_WANT_FOUR_FORMAT_LIT,
3774
+ rb_obj_classname(sm_out));
3775
+ return Qnil;
3776
+ }
3777
+ rb_check_frozen(sm_out);
3778
+ output = sm_unwrap_quat(sm_out, NULL);
3779
+ quat_inverse (*self, *output);
3780
+ }} else if (argc == 0) {
3781
+ SM_LABEL(skip_output): {
3782
+ quat_t output;
3783
+ quat_inverse (*self, output);
3784
+ sm_out = sm_wrap_quat(output, rb_obj_class(sm_self));
3785
+ rb_obj_call_init(sm_out, 0, 0);
3786
+ }} else {
3787
+ rb_raise(rb_eArgError, "Invalid number of arguments to inverse");
3788
+ }
3789
+ return sm_out;
3790
+ }
3693
3791
 
3694
3792
 
3695
3793
 
@@ -3718,13 +3816,15 @@ static VALUE sm_quat_multiply(int argc, VALUE *argv, VALUE sm_self)
3718
3816
  if (!RTEST(sm_out)) {
3719
3817
  goto SM_LABEL(skip_output);
3720
3818
  }{
3819
+ quat_t *output;
3721
3820
  if (!!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3722
3821
  rb_raise(rb_eTypeError,
3723
3822
  kSM_WANT_FOUR_FORMAT_LIT,
3724
3823
  rb_obj_classname(sm_out));
3725
3824
  return Qnil;
3726
3825
  }
3727
- quat_t *output = sm_unwrap_quat(sm_out, NULL);
3826
+ rb_check_frozen(sm_out);
3827
+ output = sm_unwrap_quat(sm_out, NULL);
3728
3828
  quat_multiply(*self, *rhs, *output);
3729
3829
  }} else if (argc == 1) {
3730
3830
  SM_LABEL(skip_output): {
@@ -3765,13 +3865,15 @@ static VALUE sm_quat_multiply_vec3(int argc, VALUE *argv, VALUE sm_self)
3765
3865
  if (!RTEST(sm_out)) {
3766
3866
  goto SM_LABEL(skip_output);
3767
3867
  }{
3868
+ vec3_t *output;
3768
3869
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
3769
3870
  rb_raise(rb_eTypeError,
3770
3871
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
3771
3872
  rb_obj_classname(sm_out));
3772
3873
  return Qnil;
3773
3874
  }
3774
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
3875
+ rb_check_frozen(sm_out);
3876
+ output = sm_unwrap_vec3(sm_out, NULL);
3775
3877
  quat_multiply_vec3(*self, *rhs, *output);
3776
3878
  }} else if (argc == 1) {
3777
3879
  SM_LABEL(skip_output): {
@@ -3827,12 +3929,14 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
3827
3929
  quat_t *self = sm_unwrap_quat(sm_self, NULL);
3828
3930
  size_t arr_index = 0;
3829
3931
 
3932
+ rb_check_frozen(sm_self);
3933
+
3830
3934
  switch(argc) {
3831
3935
 
3832
- // Default value
3936
+ /* Default value */
3833
3937
  case 0: { break; }
3834
3938
 
3835
- // Copy or by-array
3939
+ /* Copy or by-array */
3836
3940
  case 1: {
3837
3941
  if (SM_IS_A(argv[0], quat) ||
3838
3942
  SM_IS_A(argv[0], vec4)) {
@@ -3865,13 +3969,13 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
3865
3969
  break;
3866
3970
  }
3867
3971
 
3868
- // Optional offset into array provided
3972
+ /* Optional offset into array provided */
3869
3973
  if (0) {
3870
3974
  case 2:
3871
3975
  arr_index = NUM2SIZET(argv[1]);
3872
3976
  }
3873
3977
 
3874
- // Array of values
3978
+ /* Array of values */
3875
3979
  if (SM_RB_IS_A(argv[0], rb_cArray)) {
3876
3980
  VALUE arrdata = argv[0];
3877
3981
  const size_t arr_end = arr_index + 3;
@@ -3886,10 +3990,10 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
3886
3990
  break;
3887
3991
  }
3888
3992
 
3889
- // W
3993
+ /* W */
3890
3994
  case 4: {
3891
3995
  self[0][3] = (s_float_t)rb_num2dbl(argv[3]);
3892
- case 3: // X, Y, Z
3996
+ case 3: /* X, Y, Z */
3893
3997
  self[0][0] = (s_float_t)rb_num2dbl(argv[0]);
3894
3998
  self[0][1] = (s_float_t)rb_num2dbl(argv[1]);
3895
3999
  self[0][2] = (s_float_t)rb_num2dbl(argv[2]);
@@ -3900,7 +4004,7 @@ static VALUE sm_quat_init(int argc, VALUE *argv, VALUE sm_self)
3900
4004
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
3901
4005
  break;
3902
4006
  }
3903
- } // switch (argc)
4007
+ } /* switch (argc) */
3904
4008
 
3905
4009
  return sm_self;
3906
4010
  }
@@ -3954,6 +4058,7 @@ static VALUE sm_quat_angle_axis(int argc, VALUE *argv, VALUE self)
3954
4058
  axis = sm_unwrap_vec3(sm_axis, NULL);
3955
4059
 
3956
4060
  if (SM_IS_A(sm_out, quat) || SM_IS_A(sm_out, vec4)) {
4061
+ rb_check_frozen(sm_out);
3957
4062
  quat_t *out = sm_unwrap_quat(sm_out, NULL);
3958
4063
  quat_from_angle_axis(angle, (*axis)[0], (*axis)[1], (*axis)[2], *out);
3959
4064
  } else {
@@ -4013,6 +4118,7 @@ static VALUE sm_quat_slerp(int argc, VALUE *argv, VALUE sm_self)
4013
4118
  destination = sm_unwrap_quat(sm_destination, NULL);
4014
4119
 
4015
4120
  if ((SM_IS_A(sm_out, vec4) || SM_IS_A(sm_out, quat))) {
4121
+ rb_check_frozen(sm_out);
4016
4122
  quat_slerp(*self, *destination, alpha, *sm_unwrap_quat(sm_out, NULL));
4017
4123
  } else {
4018
4124
  quat_t out;
@@ -4087,6 +4193,7 @@ static VALUE sm_mat4_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
4087
4193
  static const int max_index = sizeof(mat4_t) / sizeof(s_float_t);
4088
4194
  mat4_t *self = sm_unwrap_mat4(sm_self, NULL);
4089
4195
  int index = NUM2INT(sm_index);
4196
+ rb_check_frozen(sm_self);
4090
4197
  if (index < 0 || index >= max_index) {
4091
4198
  rb_raise(rb_eRangeError,
4092
4199
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -4129,30 +4236,32 @@ static VALUE sm_mat4_length (VALUE self)
4129
4236
  * call-seq:
4130
4237
  * copy(output = nil) -> output or new mat4
4131
4238
  */
4132
- static VALUE sm_mat4_copy(int argc, VALUE *argv, VALUE sm_self)
4133
- {
4134
- VALUE sm_out;
4135
- mat4_t *self;
4136
- rb_scan_args(argc, argv, "01", &sm_out);
4137
- self = sm_unwrap_mat4(sm_self, NULL);
4138
- if (argc == 1) {
4139
- if (!RTEST(sm_out)) {
4140
- goto SM_LABEL(skip_output);
4141
- }{
4142
- SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4143
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
4144
- mat4_copy (*self, *output);
4145
- }} else if (argc == 0) {
4146
- SM_LABEL(skip_output): {
4147
- mat4_t output;
4148
- mat4_copy (*self, output);
4149
- sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4150
- rb_obj_call_init(sm_out, 0, 0);
4151
- }} else {
4152
- rb_raise(rb_eArgError, "Invalid number of arguments to copy");
4153
- }
4154
- return sm_out;
4155
- }
4239
+ static VALUE sm_mat4_copy(int argc, VALUE *argv, VALUE sm_self)
4240
+ {
4241
+ VALUE sm_out;
4242
+ mat4_t *self;
4243
+ rb_scan_args(argc, argv, "01", &sm_out);
4244
+ self = sm_unwrap_mat4(sm_self, NULL);
4245
+ if (argc == 1) {
4246
+ if (!RTEST(sm_out)) {
4247
+ goto SM_LABEL(skip_output);
4248
+ }{
4249
+ mat4_t *output;
4250
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4251
+ rb_check_frozen(sm_out);
4252
+ output = sm_unwrap_mat4(sm_out, NULL);
4253
+ mat4_copy (*self, *output);
4254
+ }} else if (argc == 0) {
4255
+ SM_LABEL(skip_output): {
4256
+ mat4_t output;
4257
+ mat4_copy (*self, output);
4258
+ sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4259
+ rb_obj_call_init(sm_out, 0, 0);
4260
+ }} else {
4261
+ rb_raise(rb_eArgError, "Invalid number of arguments to copy");
4262
+ }
4263
+ return sm_out;
4264
+ }
4156
4265
 
4157
4266
 
4158
4267
 
@@ -4162,30 +4271,32 @@ static VALUE sm_mat4_length (VALUE self)
4162
4271
  * call-seq:
4163
4272
  * to_mat3(output = nil) -> output or new mat3
4164
4273
  */
4165
- static VALUE sm_mat4_to_mat3(int argc, VALUE *argv, VALUE sm_self)
4166
- {
4167
- VALUE sm_out;
4168
- mat4_t *self;
4169
- rb_scan_args(argc, argv, "01", &sm_out);
4170
- self = sm_unwrap_mat4(sm_self, NULL);
4171
- if (argc == 1) {
4172
- if (!RTEST(sm_out)) {
4173
- goto SM_LABEL(skip_output);
4174
- }{
4175
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
4176
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
4177
- mat4_to_mat3 (*self, *output);
4178
- }} else if (argc == 0) {
4179
- SM_LABEL(skip_output): {
4180
- mat3_t output;
4181
- mat4_to_mat3 (*self, output);
4182
- sm_out = sm_wrap_mat3(output, s_sm_mat4_klass);
4183
- rb_obj_call_init(sm_out, 0, 0);
4184
- }} else {
4185
- rb_raise(rb_eArgError, "Invalid number of arguments to to_mat3");
4186
- }
4187
- return sm_out;
4188
- }
4274
+ static VALUE sm_mat4_to_mat3(int argc, VALUE *argv, VALUE sm_self)
4275
+ {
4276
+ VALUE sm_out;
4277
+ mat4_t *self;
4278
+ rb_scan_args(argc, argv, "01", &sm_out);
4279
+ self = sm_unwrap_mat4(sm_self, NULL);
4280
+ if (argc == 1) {
4281
+ if (!RTEST(sm_out)) {
4282
+ goto SM_LABEL(skip_output);
4283
+ }{
4284
+ mat3_t *output;
4285
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
4286
+ rb_check_frozen(sm_out);
4287
+ output = sm_unwrap_mat3(sm_out, NULL);
4288
+ mat4_to_mat3 (*self, *output);
4289
+ }} else if (argc == 0) {
4290
+ SM_LABEL(skip_output): {
4291
+ mat3_t output;
4292
+ mat4_to_mat3 (*self, output);
4293
+ sm_out = sm_wrap_mat3(output, s_sm_mat4_klass);
4294
+ rb_obj_call_init(sm_out, 0, 0);
4295
+ }} else {
4296
+ rb_raise(rb_eArgError, "Invalid number of arguments to to_mat3");
4297
+ }
4298
+ return sm_out;
4299
+ }
4189
4300
 
4190
4301
 
4191
4302
 
@@ -4195,30 +4306,32 @@ static VALUE sm_mat4_length (VALUE self)
4195
4306
  * call-seq:
4196
4307
  * transpose(output = nil) -> output or new mat4
4197
4308
  */
4198
- static VALUE sm_mat4_transpose(int argc, VALUE *argv, VALUE sm_self)
4199
- {
4200
- VALUE sm_out;
4201
- mat4_t *self;
4202
- rb_scan_args(argc, argv, "01", &sm_out);
4203
- self = sm_unwrap_mat4(sm_self, NULL);
4204
- if (argc == 1) {
4205
- if (!RTEST(sm_out)) {
4206
- goto SM_LABEL(skip_output);
4207
- }{
4208
- SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4209
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
4210
- mat4_transpose (*self, *output);
4211
- }} else if (argc == 0) {
4212
- SM_LABEL(skip_output): {
4213
- mat4_t output;
4214
- mat4_transpose (*self, output);
4215
- sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4216
- rb_obj_call_init(sm_out, 0, 0);
4217
- }} else {
4218
- rb_raise(rb_eArgError, "Invalid number of arguments to transpose");
4219
- }
4220
- return sm_out;
4221
- }
4309
+ static VALUE sm_mat4_transpose(int argc, VALUE *argv, VALUE sm_self)
4310
+ {
4311
+ VALUE sm_out;
4312
+ mat4_t *self;
4313
+ rb_scan_args(argc, argv, "01", &sm_out);
4314
+ self = sm_unwrap_mat4(sm_self, NULL);
4315
+ if (argc == 1) {
4316
+ if (!RTEST(sm_out)) {
4317
+ goto SM_LABEL(skip_output);
4318
+ }{
4319
+ mat4_t *output;
4320
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4321
+ rb_check_frozen(sm_out);
4322
+ output = sm_unwrap_mat4(sm_out, NULL);
4323
+ mat4_transpose (*self, *output);
4324
+ }} else if (argc == 0) {
4325
+ SM_LABEL(skip_output): {
4326
+ mat4_t output;
4327
+ mat4_transpose (*self, output);
4328
+ sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4329
+ rb_obj_call_init(sm_out, 0, 0);
4330
+ }} else {
4331
+ rb_raise(rb_eArgError, "Invalid number of arguments to transpose");
4332
+ }
4333
+ return sm_out;
4334
+ }
4222
4335
 
4223
4336
 
4224
4337
 
@@ -4228,30 +4341,32 @@ static VALUE sm_mat4_length (VALUE self)
4228
4341
  * call-seq:
4229
4342
  * inverse_orthogonal(output = nil) -> output or new mat4
4230
4343
  */
4231
- static VALUE sm_mat4_inverse_orthogonal(int argc, VALUE *argv, VALUE sm_self)
4232
- {
4233
- VALUE sm_out;
4234
- mat4_t *self;
4235
- rb_scan_args(argc, argv, "01", &sm_out);
4236
- self = sm_unwrap_mat4(sm_self, NULL);
4237
- if (argc == 1) {
4238
- if (!RTEST(sm_out)) {
4239
- goto SM_LABEL(skip_output);
4240
- }{
4241
- SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4242
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
4243
- mat4_inverse_orthogonal (*self, *output);
4244
- }} else if (argc == 0) {
4245
- SM_LABEL(skip_output): {
4246
- mat4_t output;
4247
- mat4_inverse_orthogonal (*self, output);
4248
- sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4249
- rb_obj_call_init(sm_out, 0, 0);
4250
- }} else {
4251
- rb_raise(rb_eArgError, "Invalid number of arguments to inverse_orthogonal");
4252
- }
4253
- return sm_out;
4254
- }
4344
+ static VALUE sm_mat4_inverse_orthogonal(int argc, VALUE *argv, VALUE sm_self)
4345
+ {
4346
+ VALUE sm_out;
4347
+ mat4_t *self;
4348
+ rb_scan_args(argc, argv, "01", &sm_out);
4349
+ self = sm_unwrap_mat4(sm_self, NULL);
4350
+ if (argc == 1) {
4351
+ if (!RTEST(sm_out)) {
4352
+ goto SM_LABEL(skip_output);
4353
+ }{
4354
+ mat4_t *output;
4355
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4356
+ rb_check_frozen(sm_out);
4357
+ output = sm_unwrap_mat4(sm_out, NULL);
4358
+ mat4_inverse_orthogonal (*self, *output);
4359
+ }} else if (argc == 0) {
4360
+ SM_LABEL(skip_output): {
4361
+ mat4_t output;
4362
+ mat4_inverse_orthogonal (*self, output);
4363
+ sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4364
+ rb_obj_call_init(sm_out, 0, 0);
4365
+ }} else {
4366
+ rb_raise(rb_eArgError, "Invalid number of arguments to inverse_orthogonal");
4367
+ }
4368
+ return sm_out;
4369
+ }
4255
4370
 
4256
4371
 
4257
4372
 
@@ -4261,30 +4376,32 @@ static VALUE sm_mat4_length (VALUE self)
4261
4376
  * call-seq:
4262
4377
  * adjoint(output = nil) -> output or new mat4
4263
4378
  */
4264
- static VALUE sm_mat4_adjoint(int argc, VALUE *argv, VALUE sm_self)
4265
- {
4266
- VALUE sm_out;
4267
- mat4_t *self;
4268
- rb_scan_args(argc, argv, "01", &sm_out);
4269
- self = sm_unwrap_mat4(sm_self, NULL);
4270
- if (argc == 1) {
4271
- if (!RTEST(sm_out)) {
4272
- goto SM_LABEL(skip_output);
4273
- }{
4274
- SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4275
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
4276
- mat4_adjoint (*self, *output);
4277
- }} else if (argc == 0) {
4278
- SM_LABEL(skip_output): {
4279
- mat4_t output;
4280
- mat4_adjoint (*self, output);
4281
- sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4282
- rb_obj_call_init(sm_out, 0, 0);
4283
- }} else {
4284
- rb_raise(rb_eArgError, "Invalid number of arguments to adjoint");
4285
- }
4286
- return sm_out;
4287
- }
4379
+ static VALUE sm_mat4_adjoint(int argc, VALUE *argv, VALUE sm_self)
4380
+ {
4381
+ VALUE sm_out;
4382
+ mat4_t *self;
4383
+ rb_scan_args(argc, argv, "01", &sm_out);
4384
+ self = sm_unwrap_mat4(sm_self, NULL);
4385
+ if (argc == 1) {
4386
+ if (!RTEST(sm_out)) {
4387
+ goto SM_LABEL(skip_output);
4388
+ }{
4389
+ mat4_t *output;
4390
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4391
+ rb_check_frozen(sm_out);
4392
+ output = sm_unwrap_mat4(sm_out, NULL);
4393
+ mat4_adjoint (*self, *output);
4394
+ }} else if (argc == 0) {
4395
+ SM_LABEL(skip_output): {
4396
+ mat4_t output;
4397
+ mat4_adjoint (*self, output);
4398
+ sm_out = sm_wrap_mat4(output, rb_obj_class(sm_self));
4399
+ rb_obj_call_init(sm_out, 0, 0);
4400
+ }} else {
4401
+ rb_raise(rb_eArgError, "Invalid number of arguments to adjoint");
4402
+ }
4403
+ return sm_out;
4404
+ }
4288
4405
 
4289
4406
 
4290
4407
 
@@ -4308,8 +4425,10 @@ static VALUE sm_mat4_multiply(int argc, VALUE *argv, VALUE sm_self)
4308
4425
  if (!RTEST(sm_out)) {
4309
4426
  goto SM_LABEL(skip_output);
4310
4427
  }{
4428
+ mat4_t *output;
4311
4429
  SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
4312
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
4430
+ rb_check_frozen(sm_out);
4431
+ output = sm_unwrap_mat4(sm_out, NULL);
4313
4432
  mat4_multiply(*self, *rhs, *output);
4314
4433
  }} else if (argc == 1) {
4315
4434
  SM_LABEL(skip_output): {
@@ -4350,13 +4469,15 @@ static VALUE sm_mat4_multiply_vec4(int argc, VALUE *argv, VALUE sm_self)
4350
4469
  if (!RTEST(sm_out)) {
4351
4470
  goto SM_LABEL(skip_output);
4352
4471
  }{
4472
+ vec4_t *output;
4353
4473
  if (!SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
4354
4474
  rb_raise(rb_eTypeError,
4355
4475
  kSM_WANT_FOUR_FORMAT_LIT,
4356
4476
  rb_obj_classname(sm_out));
4357
4477
  return Qnil;
4358
4478
  }
4359
- vec4_t *output = sm_unwrap_vec4(sm_out, NULL);
4479
+ rb_check_frozen(sm_out);
4480
+ output = sm_unwrap_vec4(sm_out, NULL);
4360
4481
  mat4_multiply_vec4(*self, *rhs, *output);
4361
4482
  }} else if (argc == 1) {
4362
4483
  SM_LABEL(skip_output): {
@@ -4397,13 +4518,15 @@ static VALUE sm_mat4_transform_vec3(int argc, VALUE *argv, VALUE sm_self)
4397
4518
  if (!RTEST(sm_out)) {
4398
4519
  goto SM_LABEL(skip_output);
4399
4520
  }{
4521
+ vec3_t *output;
4400
4522
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
4401
4523
  rb_raise(rb_eTypeError,
4402
4524
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
4403
4525
  rb_obj_classname(sm_out));
4404
4526
  return Qnil;
4405
4527
  }
4406
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
4528
+ rb_check_frozen(sm_out);
4529
+ output = sm_unwrap_vec3(sm_out, NULL);
4407
4530
  mat4_transform_vec3(*self, *rhs, *output);
4408
4531
  }} else if (argc == 1) {
4409
4532
  SM_LABEL(skip_output): {
@@ -4445,13 +4568,15 @@ static VALUE sm_mat4_rotate_vec3(int argc, VALUE *argv, VALUE sm_self)
4445
4568
  if (!RTEST(sm_out)) {
4446
4569
  goto SM_LABEL(skip_output);
4447
4570
  }{
4571
+ vec3_t *output;
4448
4572
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
4449
4573
  rb_raise(rb_eTypeError,
4450
4574
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
4451
4575
  rb_obj_classname(sm_out));
4452
4576
  return Qnil;
4453
4577
  }
4454
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
4578
+ rb_check_frozen(sm_out);
4579
+ output = sm_unwrap_vec3(sm_out, NULL);
4455
4580
  mat4_rotate_vec3(*self, *rhs, *output);
4456
4581
  }} else if (argc == 1) {
4457
4582
  SM_LABEL(skip_output): {
@@ -4493,13 +4618,15 @@ static VALUE sm_mat4_inv_rotate_vec3(int argc, VALUE *argv, VALUE sm_self)
4493
4618
  if (!RTEST(sm_out)) {
4494
4619
  goto SM_LABEL(skip_output);
4495
4620
  }{
4621
+ vec3_t *output;
4496
4622
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
4497
4623
  rb_raise(rb_eTypeError,
4498
4624
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
4499
4625
  rb_obj_classname(sm_out));
4500
4626
  return Qnil;
4501
4627
  }
4502
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
4628
+ rb_check_frozen(sm_out);
4629
+ output = sm_unwrap_vec3(sm_out, NULL);
4503
4630
  mat4_inv_rotate_vec3(*self, *rhs, *output);
4504
4631
  }} else if (argc == 1) {
4505
4632
  SM_LABEL(skip_output): {
@@ -4543,6 +4670,7 @@ static VALUE sm_mat4_inverse_affine(int argc, VALUE *argv, VALUE sm_self)
4543
4670
  rb_obj_classname(sm_out));
4544
4671
  return Qnil;
4545
4672
  }
4673
+ rb_check_frozen(sm_out);
4546
4674
 
4547
4675
  output = sm_unwrap_mat4(sm_out, NULL);
4548
4676
  if (!mat4_inverse_affine(*self, *output)) {
@@ -4596,6 +4724,7 @@ static VALUE sm_mat4_inverse_general(int argc, VALUE *argv, VALUE sm_self)
4596
4724
  rb_obj_classname(sm_out));
4597
4725
  return Qnil;
4598
4726
  }
4727
+ rb_check_frozen(sm_out);
4599
4728
 
4600
4729
  output = sm_unwrap_mat4(sm_out, NULL);
4601
4730
  if (!mat4_inverse_general(*self, *output)) {
@@ -4671,6 +4800,7 @@ static VALUE sm_mat4_translate(int argc, VALUE *argv, VALUE sm_self)
4671
4800
 
4672
4801
  SM_LABEL(get_output):
4673
4802
  if (RTEST(sm_out)) {
4803
+ rb_check_frozen(sm_out);
4674
4804
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
4675
4805
  mat4_translate(xyz[0], xyz[1], xyz[2], *self, *out);
4676
4806
  } else {
@@ -4722,6 +4852,7 @@ static VALUE sm_mat4_translation(int argc, VALUE *argv, VALUE sm_self)
4722
4852
 
4723
4853
  SM_LABEL(get_output):
4724
4854
  if (RTEST(sm_out)) {
4855
+ rb_check_frozen(sm_out);
4725
4856
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
4726
4857
  mat4_translation(xyz[0], xyz[1], xyz[2], *out);
4727
4858
  } else {
@@ -4775,40 +4906,42 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
4775
4906
  mat4_t *self = sm_unwrap_mat4(sm_self, NULL);
4776
4907
  size_t arr_index = 0;
4777
4908
 
4909
+ rb_check_frozen(sm_self);
4910
+
4778
4911
  switch (argc) {
4779
4912
 
4780
4913
  case 0: {
4781
- // Identity (handled in _new)
4914
+ /* Identity (handled in _new) */
4782
4915
  break;
4783
4916
  }
4784
4917
 
4785
- // Copy Mat4 or provided [Numeric..]
4918
+ /* Copy Mat4 or provided [Numeric..] */
4786
4919
  case 1: {
4787
- // Copy Mat4
4920
+ /* Copy Mat4 */
4788
4921
  if (SM_IS_A(argv[0], mat4)) {
4789
4922
  sm_unwrap_mat4(argv[0], *self);
4790
4923
  break;
4791
4924
  }
4792
4925
 
4793
- // Copy Mat3
4926
+ /* Copy Mat3 */
4794
4927
  if (SM_IS_A(argv[0], mat3)) {
4795
4928
  mat3_to_mat4(*sm_unwrap_mat4(argv[0], NULL), *self);
4796
4929
  break;
4797
4930
  }
4798
4931
 
4799
- // Build from Quaternion
4932
+ /* Build from Quaternion */
4800
4933
  if (SM_IS_A(argv[0], quat)) {
4801
4934
  mat4_from_quat(*sm_unwrap_quat(argv[0], NULL), *self);
4802
4935
  break;
4803
4936
  }
4804
4937
 
4805
- // Optional offset into array provided
4938
+ /* Optional offset into array provided */
4806
4939
  if (0) {
4807
4940
  case 2:
4808
4941
  arr_index = NUM2SIZET(argv[1]);
4809
4942
  }
4810
4943
 
4811
- // Array of values
4944
+ /* Array of values */
4812
4945
  if (SM_RB_IS_A(argv[0], rb_cArray)) {
4813
4946
  VALUE arrdata = argv[0];
4814
4947
  const size_t arr_end = arr_index + 16;
@@ -4823,7 +4956,7 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
4823
4956
  break;
4824
4957
  }
4825
4958
 
4826
- // Mat4(Vec4, Vec4, Vec4, Vec4)
4959
+ /* Mat4(Vec4, Vec4, Vec4, Vec4) */
4827
4960
  case 4: {
4828
4961
  size_t arg_index;
4829
4962
  s_float_t *mat_elem = *self;
@@ -4840,7 +4973,7 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
4840
4973
  break;
4841
4974
  }
4842
4975
 
4843
- // Mat4(Numeric m00 .. m16)
4976
+ /* Mat4(Numeric m00 .. m16) */
4844
4977
  case 16: {
4845
4978
  s_float_t *mat_elem = *self;
4846
4979
  VALUE *argv_p = argv;
@@ -4854,7 +4987,7 @@ static VALUE sm_mat4_init(int argc, VALUE *argv, VALUE sm_self)
4854
4987
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
4855
4988
  break;
4856
4989
  }
4857
- } // swtich (argc)
4990
+ } /* switch (argc) */
4858
4991
 
4859
4992
  return sm_self;
4860
4993
  }
@@ -4917,6 +5050,7 @@ static VALUE sm_mat4_angle_axis(int argc, VALUE *argv, VALUE self)
4917
5050
  axis = sm_unwrap_vec3(sm_axis, NULL);
4918
5051
 
4919
5052
  if (SM_IS_A(sm_out, mat4)) {
5053
+ rb_check_frozen(sm_out);
4920
5054
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
4921
5055
  mat4_rotation(angle, (*axis)[0], (*axis)[1], (*axis)[2], *out);
4922
5056
  } else {
@@ -4965,6 +5099,7 @@ static VALUE sm_mat4_get_row3(int argc, VALUE *argv, VALUE sm_self)
4965
5099
  rb_obj_classname(sm_out));
4966
5100
  return Qnil;
4967
5101
  }
5102
+ rb_check_frozen(sm_out);
4968
5103
  } else {
4969
5104
  goto SM_LABEL(no_output);
4970
5105
  }
@@ -5028,6 +5163,7 @@ static VALUE sm_mat4_get_row4(int argc, VALUE *argv, VALUE sm_self)
5028
5163
  rb_obj_classname(sm_out));
5029
5164
  return Qnil;
5030
5165
  }
5166
+ rb_check_frozen(sm_out);
5031
5167
  } else {
5032
5168
  goto SM_LABEL(no_output);
5033
5169
  }
@@ -5091,6 +5227,7 @@ static VALUE sm_mat4_get_column3(int argc, VALUE *argv, VALUE sm_self)
5091
5227
  rb_obj_classname(sm_out));
5092
5228
  return Qnil;
5093
5229
  }
5230
+ rb_check_frozen(sm_out);
5094
5231
  } else {
5095
5232
  goto SM_LABEL(no_output);
5096
5233
  }
@@ -5154,6 +5291,7 @@ static VALUE sm_mat4_get_column4(int argc, VALUE *argv, VALUE sm_self)
5154
5291
  rb_obj_classname(sm_out));
5155
5292
  return Qnil;
5156
5293
  }
5294
+ rb_check_frozen(sm_out);
5157
5295
  } else {
5158
5296
  goto SM_LABEL(no_output);
5159
5297
  }
@@ -5370,6 +5508,7 @@ static VALUE sm_mat4_frustum(int argc, VALUE *argv, VALUE self)
5370
5508
  z_far = (s_float_t)rb_num2dbl(sm_z_far);
5371
5509
 
5372
5510
  if (SM_IS_A(sm_out, mat4)) {
5511
+ rb_check_frozen(sm_out);
5373
5512
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
5374
5513
  mat4_frustum(left, right, bottom, top, z_near, z_far, *out);
5375
5514
  } else {
@@ -5416,6 +5555,7 @@ static VALUE sm_mat4_orthographic(int argc, VALUE *argv, VALUE self)
5416
5555
  z_far = (s_float_t)rb_num2dbl(sm_z_far);
5417
5556
 
5418
5557
  if (SM_IS_A(sm_out, mat4)) {
5558
+ rb_check_frozen(sm_out);
5419
5559
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
5420
5560
  mat4_orthographic(left, right, bottom, top, z_near, z_far, *out);
5421
5561
  } else {
@@ -5456,6 +5596,7 @@ static VALUE sm_mat4_perspective(int argc, VALUE *argv, VALUE self)
5456
5596
  z_far = (s_float_t)rb_num2dbl(sm_z_far);
5457
5597
 
5458
5598
  if (SM_IS_A(sm_out, mat4)) {
5599
+ rb_check_frozen(sm_out);
5459
5600
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
5460
5601
  mat4_perspective(fov_y, aspect, z_near, z_far, *out);
5461
5602
  } else {
@@ -5494,6 +5635,7 @@ static VALUE sm_mat4_look_at(int argc, VALUE *argv, VALUE self)
5494
5635
  up = sm_unwrap_vec3(sm_up, NULL);
5495
5636
 
5496
5637
  if (SM_IS_A(sm_out, mat4)) {
5638
+ rb_check_frozen(sm_out);
5497
5639
  mat4_t *out = sm_unwrap_mat4(sm_out, NULL);
5498
5640
  mat4_look_at(*eye, *center, *up, *out);
5499
5641
  } else {
@@ -5527,6 +5669,7 @@ static VALUE sm_mat4_scale(int argc, VALUE *argv, VALUE sm_self)
5527
5669
  z = rb_num2dbl(sm_z);
5528
5670
 
5529
5671
  if (SM_IS_A(sm_out, mat4)) {
5672
+ rb_check_frozen(sm_out);
5530
5673
  mat4_scale(*self, x, y, z, *sm_unwrap_mat4(sm_out, NULL));
5531
5674
  } else {
5532
5675
  mat4_t out;
@@ -5618,6 +5761,7 @@ static VALUE sm_mat3_store (VALUE sm_self, VALUE sm_index, VALUE sm_value)
5618
5761
  static const int max_index = sizeof(mat3_t) / sizeof(s_float_t);
5619
5762
  mat3_t *self = sm_unwrap_mat3(sm_self, NULL);
5620
5763
  int index = NUM2INT(sm_index);
5764
+ rb_check_frozen(sm_self);
5621
5765
  if (index < 0 || index >= max_index) {
5622
5766
  rb_raise(rb_eRangeError,
5623
5767
  "Index %d is out of bounds, must be from 0 through %d", index, max_index - 1);
@@ -5660,30 +5804,32 @@ static VALUE sm_mat3_length (VALUE self)
5660
5804
  * call-seq:
5661
5805
  * copy(output = nil) -> output or new mat3
5662
5806
  */
5663
- static VALUE sm_mat3_copy(int argc, VALUE *argv, VALUE sm_self)
5664
- {
5665
- VALUE sm_out;
5666
- mat3_t *self;
5667
- rb_scan_args(argc, argv, "01", &sm_out);
5668
- self = sm_unwrap_mat3(sm_self, NULL);
5669
- if (argc == 1) {
5670
- if (!RTEST(sm_out)) {
5671
- goto SM_LABEL(skip_output);
5672
- }{
5673
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5674
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
5675
- mat3_copy (*self, *output);
5676
- }} else if (argc == 0) {
5677
- SM_LABEL(skip_output): {
5678
- mat3_t output;
5679
- mat3_copy (*self, output);
5680
- sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5681
- rb_obj_call_init(sm_out, 0, 0);
5682
- }} else {
5683
- rb_raise(rb_eArgError, "Invalid number of arguments to copy");
5684
- }
5685
- return sm_out;
5686
- }
5807
+ static VALUE sm_mat3_copy(int argc, VALUE *argv, VALUE sm_self)
5808
+ {
5809
+ VALUE sm_out;
5810
+ mat3_t *self;
5811
+ rb_scan_args(argc, argv, "01", &sm_out);
5812
+ self = sm_unwrap_mat3(sm_self, NULL);
5813
+ if (argc == 1) {
5814
+ if (!RTEST(sm_out)) {
5815
+ goto SM_LABEL(skip_output);
5816
+ }{
5817
+ mat3_t *output;
5818
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5819
+ rb_check_frozen(sm_out);
5820
+ output = sm_unwrap_mat3(sm_out, NULL);
5821
+ mat3_copy (*self, *output);
5822
+ }} else if (argc == 0) {
5823
+ SM_LABEL(skip_output): {
5824
+ mat3_t output;
5825
+ mat3_copy (*self, output);
5826
+ sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5827
+ rb_obj_call_init(sm_out, 0, 0);
5828
+ }} else {
5829
+ rb_raise(rb_eArgError, "Invalid number of arguments to copy");
5830
+ }
5831
+ return sm_out;
5832
+ }
5687
5833
 
5688
5834
 
5689
5835
 
@@ -5693,30 +5839,32 @@ static VALUE sm_mat3_length (VALUE self)
5693
5839
  * call-seq:
5694
5840
  * to_mat4(output = nil) -> output or new mat4
5695
5841
  */
5696
- static VALUE sm_mat3_to_mat4(int argc, VALUE *argv, VALUE sm_self)
5697
- {
5698
- VALUE sm_out;
5699
- mat3_t *self;
5700
- rb_scan_args(argc, argv, "01", &sm_out);
5701
- self = sm_unwrap_mat3(sm_self, NULL);
5702
- if (argc == 1) {
5703
- if (!RTEST(sm_out)) {
5704
- goto SM_LABEL(skip_output);
5705
- }{
5706
- SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
5707
- mat4_t *output = sm_unwrap_mat4(sm_out, NULL);
5708
- mat3_to_mat4 (*self, *output);
5709
- }} else if (argc == 0) {
5710
- SM_LABEL(skip_output): {
5711
- mat4_t output;
5712
- mat3_to_mat4 (*self, output);
5713
- sm_out = sm_wrap_mat4(output, s_sm_mat3_klass);
5714
- rb_obj_call_init(sm_out, 0, 0);
5715
- }} else {
5716
- rb_raise(rb_eArgError, "Invalid number of arguments to to_mat4");
5717
- }
5718
- return sm_out;
5719
- }
5842
+ static VALUE sm_mat3_to_mat4(int argc, VALUE *argv, VALUE sm_self)
5843
+ {
5844
+ VALUE sm_out;
5845
+ mat3_t *self;
5846
+ rb_scan_args(argc, argv, "01", &sm_out);
5847
+ self = sm_unwrap_mat3(sm_self, NULL);
5848
+ if (argc == 1) {
5849
+ if (!RTEST(sm_out)) {
5850
+ goto SM_LABEL(skip_output);
5851
+ }{
5852
+ mat4_t *output;
5853
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat4);
5854
+ rb_check_frozen(sm_out);
5855
+ output = sm_unwrap_mat4(sm_out, NULL);
5856
+ mat3_to_mat4 (*self, *output);
5857
+ }} else if (argc == 0) {
5858
+ SM_LABEL(skip_output): {
5859
+ mat4_t output;
5860
+ mat3_to_mat4 (*self, output);
5861
+ sm_out = sm_wrap_mat4(output, s_sm_mat3_klass);
5862
+ rb_obj_call_init(sm_out, 0, 0);
5863
+ }} else {
5864
+ rb_raise(rb_eArgError, "Invalid number of arguments to to_mat4");
5865
+ }
5866
+ return sm_out;
5867
+ }
5720
5868
 
5721
5869
 
5722
5870
 
@@ -5726,30 +5874,32 @@ static VALUE sm_mat3_length (VALUE self)
5726
5874
  * call-seq:
5727
5875
  * transpose(output = nil) -> output or new mat3
5728
5876
  */
5729
- static VALUE sm_mat3_transpose(int argc, VALUE *argv, VALUE sm_self)
5730
- {
5731
- VALUE sm_out;
5732
- mat3_t *self;
5733
- rb_scan_args(argc, argv, "01", &sm_out);
5734
- self = sm_unwrap_mat3(sm_self, NULL);
5735
- if (argc == 1) {
5736
- if (!RTEST(sm_out)) {
5737
- goto SM_LABEL(skip_output);
5738
- }{
5739
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5740
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
5741
- mat3_transpose (*self, *output);
5742
- }} else if (argc == 0) {
5743
- SM_LABEL(skip_output): {
5744
- mat3_t output;
5745
- mat3_transpose (*self, output);
5746
- sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5747
- rb_obj_call_init(sm_out, 0, 0);
5748
- }} else {
5749
- rb_raise(rb_eArgError, "Invalid number of arguments to transpose");
5750
- }
5751
- return sm_out;
5752
- }
5877
+ static VALUE sm_mat3_transpose(int argc, VALUE *argv, VALUE sm_self)
5878
+ {
5879
+ VALUE sm_out;
5880
+ mat3_t *self;
5881
+ rb_scan_args(argc, argv, "01", &sm_out);
5882
+ self = sm_unwrap_mat3(sm_self, NULL);
5883
+ if (argc == 1) {
5884
+ if (!RTEST(sm_out)) {
5885
+ goto SM_LABEL(skip_output);
5886
+ }{
5887
+ mat3_t *output;
5888
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5889
+ rb_check_frozen(sm_out);
5890
+ output = sm_unwrap_mat3(sm_out, NULL);
5891
+ mat3_transpose (*self, *output);
5892
+ }} else if (argc == 0) {
5893
+ SM_LABEL(skip_output): {
5894
+ mat3_t output;
5895
+ mat3_transpose (*self, output);
5896
+ sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5897
+ rb_obj_call_init(sm_out, 0, 0);
5898
+ }} else {
5899
+ rb_raise(rb_eArgError, "Invalid number of arguments to transpose");
5900
+ }
5901
+ return sm_out;
5902
+ }
5753
5903
 
5754
5904
 
5755
5905
 
@@ -5759,30 +5909,32 @@ static VALUE sm_mat3_length (VALUE self)
5759
5909
  * call-seq:
5760
5910
  * adjoint(output = nil) -> output or new mat3
5761
5911
  */
5762
- static VALUE sm_mat3_adjoint(int argc, VALUE *argv, VALUE sm_self)
5763
- {
5764
- VALUE sm_out;
5765
- mat3_t *self;
5766
- rb_scan_args(argc, argv, "01", &sm_out);
5767
- self = sm_unwrap_mat3(sm_self, NULL);
5768
- if (argc == 1) {
5769
- if (!RTEST(sm_out)) {
5770
- goto SM_LABEL(skip_output);
5771
- }{
5772
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5773
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
5774
- mat3_adjoint (*self, *output);
5775
- }} else if (argc == 0) {
5776
- SM_LABEL(skip_output): {
5777
- mat3_t output;
5778
- mat3_adjoint (*self, output);
5779
- sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5780
- rb_obj_call_init(sm_out, 0, 0);
5781
- }} else {
5782
- rb_raise(rb_eArgError, "Invalid number of arguments to adjoint");
5783
- }
5784
- return sm_out;
5785
- }
5912
+ static VALUE sm_mat3_adjoint(int argc, VALUE *argv, VALUE sm_self)
5913
+ {
5914
+ VALUE sm_out;
5915
+ mat3_t *self;
5916
+ rb_scan_args(argc, argv, "01", &sm_out);
5917
+ self = sm_unwrap_mat3(sm_self, NULL);
5918
+ if (argc == 1) {
5919
+ if (!RTEST(sm_out)) {
5920
+ goto SM_LABEL(skip_output);
5921
+ }{
5922
+ mat3_t *output;
5923
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5924
+ rb_check_frozen(sm_out);
5925
+ output = sm_unwrap_mat3(sm_out, NULL);
5926
+ mat3_adjoint (*self, *output);
5927
+ }} else if (argc == 0) {
5928
+ SM_LABEL(skip_output): {
5929
+ mat3_t output;
5930
+ mat3_adjoint (*self, output);
5931
+ sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5932
+ rb_obj_call_init(sm_out, 0, 0);
5933
+ }} else {
5934
+ rb_raise(rb_eArgError, "Invalid number of arguments to adjoint");
5935
+ }
5936
+ return sm_out;
5937
+ }
5786
5938
 
5787
5939
 
5788
5940
 
@@ -5792,30 +5944,32 @@ static VALUE sm_mat3_length (VALUE self)
5792
5944
  * call-seq:
5793
5945
  * orthogonal(output = nil) -> output or new mat3
5794
5946
  */
5795
- static VALUE sm_mat3_orthogonal(int argc, VALUE *argv, VALUE sm_self)
5796
- {
5797
- VALUE sm_out;
5798
- mat3_t *self;
5799
- rb_scan_args(argc, argv, "01", &sm_out);
5800
- self = sm_unwrap_mat3(sm_self, NULL);
5801
- if (argc == 1) {
5802
- if (!RTEST(sm_out)) {
5803
- goto SM_LABEL(skip_output);
5804
- }{
5805
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5806
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
5807
- mat3_orthogonal (*self, *output);
5808
- }} else if (argc == 0) {
5809
- SM_LABEL(skip_output): {
5810
- mat3_t output;
5811
- mat3_orthogonal (*self, output);
5812
- sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5813
- rb_obj_call_init(sm_out, 0, 0);
5814
- }} else {
5815
- rb_raise(rb_eArgError, "Invalid number of arguments to orthogonal");
5816
- }
5817
- return sm_out;
5818
- }
5947
+ static VALUE sm_mat3_orthogonal(int argc, VALUE *argv, VALUE sm_self)
5948
+ {
5949
+ VALUE sm_out;
5950
+ mat3_t *self;
5951
+ rb_scan_args(argc, argv, "01", &sm_out);
5952
+ self = sm_unwrap_mat3(sm_self, NULL);
5953
+ if (argc == 1) {
5954
+ if (!RTEST(sm_out)) {
5955
+ goto SM_LABEL(skip_output);
5956
+ }{
5957
+ mat3_t *output;
5958
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5959
+ rb_check_frozen(sm_out);
5960
+ output = sm_unwrap_mat3(sm_out, NULL);
5961
+ mat3_orthogonal (*self, *output);
5962
+ }} else if (argc == 0) {
5963
+ SM_LABEL(skip_output): {
5964
+ mat3_t output;
5965
+ mat3_orthogonal (*self, output);
5966
+ sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5967
+ rb_obj_call_init(sm_out, 0, 0);
5968
+ }} else {
5969
+ rb_raise(rb_eArgError, "Invalid number of arguments to orthogonal");
5970
+ }
5971
+ return sm_out;
5972
+ }
5819
5973
 
5820
5974
 
5821
5975
 
@@ -5825,30 +5979,32 @@ static VALUE sm_mat3_length (VALUE self)
5825
5979
  * call-seq:
5826
5980
  * cofactor(output = nil) -> output or new mat3
5827
5981
  */
5828
- static VALUE sm_mat3_cofactor(int argc, VALUE *argv, VALUE sm_self)
5829
- {
5830
- VALUE sm_out;
5831
- mat3_t *self;
5832
- rb_scan_args(argc, argv, "01", &sm_out);
5833
- self = sm_unwrap_mat3(sm_self, NULL);
5834
- if (argc == 1) {
5835
- if (!RTEST(sm_out)) {
5836
- goto SM_LABEL(skip_output);
5837
- }{
5838
- SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5839
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
5840
- mat3_cofactor (*self, *output);
5841
- }} else if (argc == 0) {
5842
- SM_LABEL(skip_output): {
5843
- mat3_t output;
5844
- mat3_cofactor (*self, output);
5845
- sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
5846
- rb_obj_call_init(sm_out, 0, 0);
5847
- }} else {
5848
- rb_raise(rb_eArgError, "Invalid number of arguments to cofactor");
5849
- }
5850
- return sm_out;
5851
- }
5982
+ static VALUE sm_mat3_cofactor(int argc, VALUE *argv, VALUE sm_self)
5983
+ {
5984
+ VALUE sm_out;
5985
+ mat3_t *self;
5986
+ rb_scan_args(argc, argv, "01", &sm_out);
5987
+ self = sm_unwrap_mat3(sm_self, NULL);
5988
+ if (argc == 1) {
5989
+ if (!RTEST(sm_out)) {
5990
+ goto SM_LABEL(skip_output);
5991
+ }{
5992
+ mat3_t *output;
5993
+ SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5994
+ rb_check_frozen(sm_out);
5995
+ output = sm_unwrap_mat3(sm_out, NULL);
5996
+ mat3_cofactor (*self, *output);
5997
+ }} else if (argc == 0) {
5998
+ SM_LABEL(skip_output): {
5999
+ mat3_t output;
6000
+ mat3_cofactor (*self, output);
6001
+ sm_out = sm_wrap_mat3(output, rb_obj_class(sm_self));
6002
+ rb_obj_call_init(sm_out, 0, 0);
6003
+ }} else {
6004
+ rb_raise(rb_eArgError, "Invalid number of arguments to cofactor");
6005
+ }
6006
+ return sm_out;
6007
+ }
5852
6008
 
5853
6009
 
5854
6010
 
@@ -5872,8 +6028,10 @@ static VALUE sm_mat3_multiply(int argc, VALUE *argv, VALUE sm_self)
5872
6028
  if (!RTEST(sm_out)) {
5873
6029
  goto SM_LABEL(skip_output);
5874
6030
  }{
6031
+ mat3_t *output;
5875
6032
  SM_RAISE_IF_NOT_TYPE(sm_out, mat3);
5876
- mat3_t *output = sm_unwrap_mat3(sm_out, NULL);
6033
+ rb_check_frozen(sm_out);
6034
+ output = sm_unwrap_mat3(sm_out, NULL);
5877
6035
  mat3_multiply(*self, *rhs, *output);
5878
6036
  }} else if (argc == 1) {
5879
6037
  SM_LABEL(skip_output): {
@@ -5914,13 +6072,15 @@ static VALUE sm_mat3_rotate_vec3(int argc, VALUE *argv, VALUE sm_self)
5914
6072
  if (!RTEST(sm_out)) {
5915
6073
  goto SM_LABEL(skip_output);
5916
6074
  }{
6075
+ vec3_t *output;
5917
6076
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
5918
6077
  rb_raise(rb_eTypeError,
5919
6078
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
5920
6079
  rb_obj_classname(sm_out));
5921
6080
  return Qnil;
5922
6081
  }
5923
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
6082
+ rb_check_frozen(sm_out);
6083
+ output = sm_unwrap_vec3(sm_out, NULL);
5924
6084
  mat3_rotate_vec3(*self, *rhs, *output);
5925
6085
  }} else if (argc == 1) {
5926
6086
  SM_LABEL(skip_output): {
@@ -5962,13 +6122,15 @@ static VALUE sm_mat3_inv_rotate_vec3(int argc, VALUE *argv, VALUE sm_self)
5962
6122
  if (!RTEST(sm_out)) {
5963
6123
  goto SM_LABEL(skip_output);
5964
6124
  }{
6125
+ vec3_t *output;
5965
6126
  if (!SM_IS_A(sm_out, vec3) && !SM_IS_A(sm_out, vec4) && !SM_IS_A(sm_out, quat)) {
5966
6127
  rb_raise(rb_eTypeError,
5967
6128
  kSM_WANT_THREE_OR_FOUR_FORMAT_LIT,
5968
6129
  rb_obj_classname(sm_out));
5969
6130
  return Qnil;
5970
6131
  }
5971
- vec3_t *output = sm_unwrap_vec3(sm_out, NULL);
6132
+ rb_check_frozen(sm_out);
6133
+ output = sm_unwrap_vec3(sm_out, NULL);
5972
6134
  mat3_inv_rotate_vec3(*self, *rhs, *output);
5973
6135
  }} else if (argc == 1) {
5974
6136
  SM_LABEL(skip_output): {
@@ -6026,6 +6188,7 @@ static VALUE sm_mat3_inverse(int argc, VALUE *argv, VALUE sm_self)
6026
6188
  return Qnil;
6027
6189
  }
6028
6190
 
6191
+ rb_check_frozen(sm_out);
6029
6192
  output = sm_unwrap_mat3(sm_out, NULL);
6030
6193
  if (!mat3_inverse(*self, *output)) {
6031
6194
  return Qnil;
@@ -6087,40 +6250,42 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6087
6250
  mat3_t *self = sm_unwrap_mat3(sm_self, NULL);
6088
6251
  size_t arr_index = 0;
6089
6252
 
6253
+ rb_check_frozen(sm_self);
6254
+
6090
6255
  switch (argc) {
6091
6256
 
6092
6257
  case 0: {
6093
- // Identity (handled in _new)
6258
+ /* Identity (handled in _new) */
6094
6259
  break;
6095
6260
  }
6096
6261
 
6097
- // Copy Mat3 or provided [Numeric..]
6262
+ /* Copy Mat3 or provided [Numeric..] */
6098
6263
  case 1: {
6099
- // Copy Mat3
6264
+ /* Copy Mat3 */
6100
6265
  if (SM_IS_A(argv[0], mat3)) {
6101
6266
  sm_unwrap_mat3(argv[0], *self);
6102
6267
  break;
6103
6268
  }
6104
6269
 
6105
- // Copy Mat4
6270
+ /* Copy Mat4 */
6106
6271
  if (SM_IS_A(argv[0], mat4)) {
6107
6272
  mat4_to_mat3(*sm_unwrap_mat4(argv[0], NULL), *self);
6108
6273
  break;
6109
6274
  }
6110
6275
 
6111
- // Build from Quaternion
6276
+ /* Build from Quaternion */
6112
6277
  if (SM_IS_A(argv[0], quat)) {
6113
6278
  mat3_from_quat(*sm_unwrap_quat(argv[0], NULL), *self);
6114
6279
  break;
6115
6280
  }
6116
6281
 
6117
- // Optional offset into array provided
6282
+ /* Optional offset into array provided */
6118
6283
  if (0) {
6119
6284
  case 2:
6120
6285
  arr_index = NUM2SIZET(argv[1]);
6121
6286
  }
6122
6287
 
6123
- // Array of values
6288
+ /* Array of values */
6124
6289
  if (SM_RB_IS_A(argv[0], rb_cArray)) {
6125
6290
  VALUE arrdata = argv[0];
6126
6291
  const size_t arr_end = arr_index + 9;
@@ -6135,7 +6300,7 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6135
6300
  break;
6136
6301
  }
6137
6302
 
6138
- // Mat3(Vec3, Vec3, Vec3)
6303
+ /* Mat3(Vec3, Vec3, Vec3) */
6139
6304
  case 3: {
6140
6305
  size_t arg_index;
6141
6306
  s_float_t *mat_elem = *self;
@@ -6152,7 +6317,7 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6152
6317
  break;
6153
6318
  }
6154
6319
 
6155
- // Mat3(Numeric m00 .. m16)
6320
+ /* Mat3(Numeric m00 .. m16) */
6156
6321
  case 9: {
6157
6322
  s_float_t *mat_elem = *self;
6158
6323
  VALUE *argv_p = argv;
@@ -6166,7 +6331,7 @@ static VALUE sm_mat3_init(int argc, VALUE *argv, VALUE sm_self)
6166
6331
  rb_raise(rb_eArgError, "Invalid arguments to initialize/set");
6167
6332
  break;
6168
6333
  }
6169
- } // swtich (argc)
6334
+ } /* switch (argc) */
6170
6335
 
6171
6336
  return sm_self;
6172
6337
  }
@@ -6226,6 +6391,7 @@ static VALUE sm_mat3_angle_axis(int argc, VALUE *argv, VALUE self)
6226
6391
  axis = sm_unwrap_vec3(sm_axis, NULL);
6227
6392
 
6228
6393
  if (SM_IS_A(sm_out, mat3)) {
6394
+ rb_check_frozen(sm_out);
6229
6395
  mat3_t *out = sm_unwrap_mat3(sm_out, NULL);
6230
6396
  mat3_rotation(angle, (*axis)[0], (*axis)[1], (*axis)[2], *out);
6231
6397
  } else {
@@ -6274,6 +6440,7 @@ static VALUE sm_mat3_get_row3(int argc, VALUE *argv, VALUE sm_self)
6274
6440
  rb_obj_classname(sm_out));
6275
6441
  return Qnil;
6276
6442
  }
6443
+ rb_check_frozen(sm_out);
6277
6444
  } else {
6278
6445
  goto SM_LABEL(no_output);
6279
6446
  }
@@ -6337,6 +6504,7 @@ static VALUE sm_mat3_get_column3(int argc, VALUE *argv, VALUE sm_self)
6337
6504
  rb_obj_classname(sm_out));
6338
6505
  return Qnil;
6339
6506
  }
6507
+ rb_check_frozen(sm_out);
6340
6508
  } else {
6341
6509
  goto SM_LABEL(no_output);
6342
6510
  }
@@ -6470,6 +6638,7 @@ static VALUE sm_mat3_scale(int argc, VALUE *argv, VALUE sm_self)
6470
6638
  z = rb_num2dbl(sm_z);
6471
6639
 
6472
6640
  if (SM_IS_A(sm_out, mat3)) {
6641
+ rb_check_frozen(sm_out);
6473
6642
  mat3_scale(*self, x, y, z, *sm_unwrap_mat3(sm_out, NULL));
6474
6643
  } else {
6475
6644
  mat3_t out;
@@ -6656,7 +6825,7 @@ void Init_bindings()
6656
6825
  rb_define_method(s_sm_quat_klass, "multiply_quat", sm_quat_multiply, -1);
6657
6826
  rb_define_method(s_sm_quat_klass, "multiply_vec3", sm_quat_multiply_vec3, -1);
6658
6827
  rb_define_method(s_sm_quat_klass, "slerp", sm_quat_slerp, -1);
6659
- // Borrow some functions from vec4
6828
+ /* Borrow some functions from vec4 */
6660
6829
  rb_define_method(s_sm_quat_klass, "copy", sm_vec4_copy, -1);
6661
6830
  rb_define_method(s_sm_quat_klass, "negate", sm_vec4_negate, -1);
6662
6831
  rb_define_method(s_sm_quat_klass, "normalize", sm_vec4_normalize, -1);