MCPcopy Create free account
hub / github.com/defold/defold / Length

Function Length

engine/script/src/script_vmath.cpp:1912–1936  ·  view source on GitHub ↗

calculates the length of a vector or quaternion * * Returns the length of the supplied vector or quaternion. * * If you are comparing the lengths of vectors or quaternions, you should compare * the length squared instead as it is slightly more efficient to calculate * (it eliminates a square root calculation). * * @name vmath.length * @param v [type:vec

Source from the content-addressed store, hash-verified

1910 * ```
1911 */
1912 static int Length(lua_State* L)
1913 {
1914 void* argument = 0;
1915 const ScriptUserType type = CheckUserData(L, 1, &argument);
1916 if (type == SCRIPT_TYPE_VECTOR3)
1917 {
1918 Vector3* v = (Vector3*)argument;
1919 lua_pushnumber(L, dmVMath::Length(*v));
1920 }
1921 else if (type == SCRIPT_TYPE_VECTOR4)
1922 {
1923 Vector4* v = (Vector4*)argument;
1924 lua_pushnumber(L, dmVMath::Length(*v));
1925 }
1926 else if (type == SCRIPT_TYPE_QUAT)
1927 {
1928 Quat* value = (Quat*)argument;
1929 lua_pushnumber(L, dmVMath::Length(*value));
1930 }
1931 else
1932 {
1933 return luaL_error(L, "%s.%s accepts (%s|%s|%s) as argument.", SCRIPT_LIB_NAME, "length", SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_TYPE_NAME_VECTOR4, SCRIPT_TYPE_NAME_QUAT);
1934 }
1935 return 1;
1936 }
1937
1938 /*# normalizes a vector
1939 *

Callers 4

DiffVector3Function · 0.50
DiffVector4Function · 0.50
DiffQuatFunction · 0.50
NormalizeMethod · 0.50

Calls 3

CheckUserDataFunction · 0.85
lua_pushnumberFunction · 0.85
luaL_errorFunction · 0.85

Tested by 3

DiffVector3Function · 0.40
DiffVector4Function · 0.40
DiffQuatFunction · 0.40