Method: Snow::Mat4Array#resize!
- Defined in:
- ext/snow-math/snow-math.c
#resize!(sm_new_length) ⇒ Object
Resizes the array to new_length and returns self.
If resizing to a length smaller than the previous length, excess array elements are discarded and the array is truncated. Otherwise, when resizing the array to a greater length than previous, new elements in the array will contain garbage values.
If new_length is equal to self.length, the call does nothing to the array.
Attempting to resize an array to a new length of zero or less will raise a RangeError. Do not try to resize arrays to zero or less. Do not be that person.
call-seq:
resize!(new_length) -> self
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 |
# File 'ext/snow-math/snow-math.c', line 1391 static VALUE sm_mat4_array_resize(VALUE sm_self, VALUE sm_new_length) { size_t new_length; size_t old_length; rb_check_frozen(sm_self); old_length = NUM2SIZET(sm_mathtype_array_length(sm_self)); new_length = NUM2SIZET(sm_new_length); if (old_length == new_length) { /* No change, done */ return sm_self; } else if (new_length < 1) { /* Someone decided to be that person. */ rb_raise(rb_eRangeError, "Cannot resize array to length less than or equal to 0."); return sm_self; } REALLOC_N(RDATA(sm_self)->data, mat4_t, new_length); rb_ivar_set(sm_self, kRB_IVAR_MATHARRAY_LENGTH, sm_new_length); rb_ary_clear(rb_ivar_get(sm_self, kRB_IVAR_MATHARRAY_CACHE)); return sm_self; } |