Browse Source

IntVector2::Length()

Rokas Kupstys 9 years ago
parent
commit
f9aa090c92

+ 2 - 0
Source/Urho3D/AngelScript/MathAPI.cpp

@@ -187,6 +187,8 @@ static void RegisterIntVector2(asIScriptEngine* engine)
     engine->RegisterObjectMethod("IntVector2", "IntVector2 opMul(int) const", asMETHODPR(IntVector2, operator *, (int) const, IntVector2), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntVector2", "IntVector2 opMul(int) const", asMETHODPR(IntVector2, operator *, (int) const, IntVector2), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntVector2", "IntVector2 opDiv(int) const", asMETHODPR(IntVector2, operator /, (int) const, IntVector2), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntVector2", "IntVector2 opDiv(int) const", asMETHODPR(IntVector2, operator /, (int) const, IntVector2), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntVector2", "String ToString() const", asMETHOD(IntVector2, ToString), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntVector2", "String ToString() const", asMETHOD(IntVector2, ToString), asCALL_THISCALL);
+    engine->RegisterObjectMethod("IntVector2", "uint ToHash() const", asMETHOD(IntVector2, ToHash), asCALL_THISCALL);
+    engine->RegisterObjectMethod("IntVector2", "float Length() const", asMETHOD(IntVector2, Length), asCALL_THISCALL);
     engine->RegisterObjectProperty("IntVector2", "int x", offsetof(IntVector2, x_));
     engine->RegisterObjectProperty("IntVector2", "int x", offsetof(IntVector2, x_));
     engine->RegisterObjectProperty("IntVector2", "int y", offsetof(IntVector2, y_));
     engine->RegisterObjectProperty("IntVector2", "int y", offsetof(IntVector2, y_));
     engine->RegisterGlobalFunction("IntVector2 VectorMin(const IntVector2&in, const IntVector2&in)", asFUNCTIONPR(VectorMin, (const IntVector2&, const IntVector2&), IntVector2), asCALL_CDECL);
     engine->RegisterGlobalFunction("IntVector2 VectorMin(const IntVector2&in, const IntVector2&in)", asFUNCTIONPR(VectorMin, (const IntVector2&, const IntVector2&), IntVector2), asCALL_CDECL);

+ 2 - 0
Source/Urho3D/LuaScript/pkgs/Math/Vector2.pkg

@@ -59,6 +59,8 @@ class IntVector2
     IntVector2 operator / (int rhs) const;
     IntVector2 operator / (int rhs) const;
 
 
     String ToString() const;
     String ToString() const;
+    unsigned ToHash() const;
+	float Length() const;
 
 
     int x_ @ x;
     int x_ @ x;
     int y_ @ y;
     int y_ @ y;

+ 3 - 0
Source/Urho3D/Math/Vector2.h

@@ -329,6 +329,9 @@ public:
     /// Return hash value for HashSet & HashMap.
     /// Return hash value for HashSet & HashMap.
     unsigned ToHash() const { return (unsigned)x_ * 31 + (unsigned)y_; }
     unsigned ToHash() const { return (unsigned)x_ * 31 + (unsigned)y_; }
 
 
+    /// Return length.
+    float Length() const { return sqrtf(x_ * x_ + y_ * y_); }
+
     /// X coordinate.
     /// X coordinate.
     int x_;
     int x_;
     /// Y coordinate.
     /// Y coordinate.