Module: Snow

Defined in:
lib/snow-math/version.rb,
lib/snow-math/ptr.rb,
lib/snow-math/mat3.rb,
lib/snow-math/mat4.rb,
lib/snow-math/quat.rb,
lib/snow-math/to_a.rb,
lib/snow-math/vec2.rb,
lib/snow-math/vec3.rb,
lib/snow-math/vec4.rb,
lib/snow-math/inspect.rb,
lib/snow-math/marshal.rb,
lib/snow-math/marshal.rb,
lib/snow-math/swizzle.rb,
lib/snow-math/swizzle.rb,
ext/snow-math/snow-math.c

Overview

This file is part of ruby-snowmath. Copyright © 2013 Noel Raymond Cower. All rights reserved. See COPYING for license details.

Defined Under Namespace

Modules: ArrayMarshalSupport, ArraySupport, BaseMarshalSupport, FiddlePointerSupport, InspectSupport, SwizzleSupport Classes: Mat3, Mat3Array, Mat4, Mat4Array, Quat, QuatArray, Vec2, Vec2Array, Vec3, Vec3Array, Vec4, Vec4Array

Constant Summary collapse

SNOW_MATH_VERSION =

snow-math bindings version string.

'1.7.3'
SNOW_MATH_FLOAT_SIZE =
INT2FIX(sizeof(s_float_t))
SNOW_MATH_DEFAULT_FLOAT_EPSILON =
DBL2NUM(S_FLOAT_EPSILON)
DEGREES_TO_RADIANS =
DBL2NUM(S_DEG2RAD)
RADIANS_TO_DEGREES =
DBL2NUM(S_RAD2DEG)

Class Method Summary collapse

Class Method Details

.float_epsilonFloat

Gets the float epsilon for snow-math types. By default, this is 1e-9 for double-precision floats and 1e-6 for single-precision floats.

Returns:

  • (Float)


6755
6756
6757
6758
# File 'ext/snow-math/snow-math.c', line 6755

static VALUE sm_get_float_epsilon(VALUE sm_self)
{
  return DBL2NUM(S_FLOAT_EPSILON);
}

.float_epsilon=(value) ⇒ Object

Sets the float epsilon for snow-math types. If snow-math is compiled to use single-precision floats, changing the epsilon for floats may cause the assigned value to lose precision itself in the cast, resulting in a subtly different epsilon than intended, as Ruby uses double-precision floats, which may lead you to think you’re setting the epsilon to one value when it’s another similar by not equal value.

Just be aware of what you’re doing and the type of float you’ve compiled snow-math to use.



6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
# File 'ext/snow-math/snow-math.c', line 6776

static VALUE sm_set_float_epsilon(VALUE sm_self, VALUE sm_value)
{
  switch (TYPE(sm_value)) {
  case T_FLOAT:
  case T_FIXNUM:
  case T_BIGNUM:
  case T_RATIONAL:
  case T_COMPLEX: {
    S_FLOAT_EPSILON = (s_float_t)NUM2DBL(sm_value);
    break;
  }
  default: {
    VALUE sm_value_s = rb_any_to_s(sm_value);
    if (0) {
      case T_STRING:
      sm_value_s = sm_value;
    }
    S_FLOAT_EPSILON =
      #ifdef USE_FLOAT
      strtof(StringValueCStr(sm_value_s), NULL)
      #else
      strtod(StringValueCStr(sm_value_s), NULL)
      #endif
      ;
  break;
  }
  } /* switch (TYPE(sm_value)) */
  return sm_value;
}