MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / normalize

Method normalize

src/lua/LuaVector.cpp:150–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148
149
150int LuaVector::normalize(lua_State* L) {
151 static std::vector<float> data;
152 const int count = lua_gettop(L);
153 data.resize(count + 1); // not using data[0]
154
155 float sum = 0.0f;
156 for (int i = 1; i <= count; i++) {
157 const float v = luaL_checkfloat(L, i);
158 data[i] = v;
159 sum += (v * v);
160 }
161 sum = sqrtf(sum);
162 if (sum == 0.0f) {
163 return count;
164 }
165 lua_checkstack(L, count);
166 const float scale = (1.0f / sum);
167 for (int i = 1; i <= count; i++) {
168 lua_pushfloat(L, data[i] * scale);
169 }
170 return count;
171}
172
173
174//============================================================================//

Callers 15

transformLinearVelMethod · 0.45
setViewMethod · 0.45
makePlaneMethod · 0.45
doUpdateMotionMethod · 0.45
get3DUnitVectorMethod · 0.45
GuidedMissileStrategyMethod · 0.45
updateMethod · 0.45
_predictMethod · 0.45
radarRenderMethod · 0.45
updateMethod · 0.45
radarRenderMethod · 0.45
getDeadReckoningMethod · 0.45

Calls 5

luaL_checkfloatFunction · 0.85
lua_pushfloatFunction · 0.85
lua_gettopFunction · 0.50
lua_checkstackFunction · 0.50
resizeMethod · 0.45

Tested by

no test coverage detected