Method: Snow::Vec3Array#store
- Defined in:
- ext/snow-math/snow-math.c
#store(sm_index, sm_value) ⇒ Object Also known as: []=
Stores a Vec3 at the given index. If the provided Vec3 is a member of the array and stored at the index, then no copy is done, otherwise the Vec3 is copied to the array.
call-seq: store(index, value) -> value
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'ext/snow-math/snow-math.c', line 525 static VALUE sm_vec3_array_store(VALUE sm_self, VALUE sm_index, VALUE sm_value) { vec3_t *arr; vec3_t *value; size_t length = NUM2SIZET(sm_mathtype_array_length(sm_self)); size_t index = NUM2SIZET(sm_index); rb_check_frozen(sm_self); if (index >= length) { rb_raise(rb_eRangeError, "Index %zu out of bounds for array with length %zu", index, length); } else if (!SM_IS_A(sm_value, vec3) && !SM_IS_A(sm_value, vec4) && !SM_IS_A(sm_value, quat)) { rb_raise(rb_eTypeError, "Invalid value to store: expected Vec3, Vec4, or Quat, got %s", rb_obj_classname(sm_value)); } Data_Get_Struct(sm_self, vec3_t, arr); value = sm_unwrap_vec3(sm_value, NULL); if (value == &arr[index]) { /* The object's part of the array, don't bother copying */ return sm_value; } vec3_copy(*value, arr[index]); return sm_value; } |