1
0

Merge pull request #3227 from cuberite/NormalizeVectorApi

Normalized Vector3 API to use the same capitalization as everything else
This commit is contained in:
Mattes D 2016-06-12 07:57:47 +02:00 committed by GitHub
commit b403ad4d68
4 changed files with 82 additions and 9 deletions

View File

@ -242,6 +242,10 @@ end
operator_mul = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord multiplied." }, operator_mul = { Params = "number", Return = "Vector3d", Notes = "Returns a new Vector3d with each coord multiplied." },
operator_sub = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the difference between this object and the specified vector." }, operator_sub = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the difference between this object and the specified vector." },
operator_plus = {Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the sum of this vector and the specified vector" }, operator_plus = {Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d containing the sum of this vector and the specified vector" },
abs = { Params = "", Return = "", Notes = "<b>OBSOLETE</b>, use Abs() instead." },
clamp = { Params = "min, max", Return = "", Notes = "<b>OBSOLETE</b>, use Clamp() instead." },
Abs = { Params = "", Return = "", Notes = "Updates each coord to its absolute value." },
Clamp = { Params = "min, max", Return = "", Notes = "Clamps each coord into the specified range." },
Cross = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d that is a {{http://en.wikipedia.org/wiki/Cross_product|cross product}} of this vector and the specified vector." }, Cross = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d that is a {{http://en.wikipedia.org/wiki/Cross_product|cross product}} of this vector and the specified vector." },
Dot = { Params = "Vector3d", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, Dot = { Params = "Vector3d", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." },
Equals = { Params = "Vector3d", Return = "bool", Notes = "Returns true if this vector is exactly equal to the specified vector." }, Equals = { Params = "Vector3d", Return = "bool", Notes = "Returns true if this vector is exactly equal to the specified vector." },
@ -292,6 +296,10 @@ end
}, },
operator_plus = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector sum of this vector and the specified vector." }, operator_plus = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector sum of this vector and the specified vector." },
operator_sub = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector differrence between this vector and the specified vector." }, operator_sub = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the vector differrence between this vector and the specified vector." },
abs = { Params = "", Return = "", Notes = "<b>OBSOLETE</b>, use Abs() instead." },
clamp = { Params = "min, max", Return = "", Notes = "<b>OBSOLETE</b>, use Clamp() instead." },
Abs = { Params = "", Return = "", Notes = "Updates each coord to its absolute value." },
Clamp = { Params = "min, max", Return = "", Notes = "Clamps each coord into the specified range." },
Cross = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the cross product of this vector and the specified vector." }, Cross = { Params = "Vector3f", Return = "Vector3f", Notes = "Returns a new Vector3f object that holds the cross product of this vector and the specified vector." },
Dot = { Params = "Vector3f", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." }, Dot = { Params = "Vector3f", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." },
Equals = { Params = "Vector3f", Return = "bool", Notes = "Returns true if the specified vector is exactly equal to this vector." }, Equals = { Params = "Vector3f", Return = "bool", Notes = "Returns true if the specified vector is exactly equal to this vector." },
@ -325,9 +333,15 @@ end
{ Params = "x, y, z", Return = "Vector3i", Notes = "Creates a new Vector3i object with the specified coords." }, { Params = "x, y, z", Return = "Vector3i", Notes = "Creates a new Vector3i object with the specified coords." },
{ Params = "{{Vector3d}}", Return = "Vector3i", Notes = "Creates a new Vector3i object with coords copied and floor()-ed from the specified {{Vector3d}}." }, { Params = "{{Vector3d}}", Return = "Vector3i", Notes = "Creates a new Vector3i object with coords copied and floor()-ed from the specified {{Vector3d}}." },
}, },
abs = { Params = "", Return = "", Notes = "<b>OBSOLETE</b>, use Abs() instead." },
clamp = { Params = "min, max", Return = "", Notes = "<b>OBSOLETE</b>, use Clamp() instead." },
Abs = { Params = "", Return = "", Notes = "Updates each coord to its absolute value." },
Clamp = { Params = "min, max", Return = "", Notes = "Clamps each coord into the specified range." },
Cross = { Params = "Vector3d", Return = "Vector3d", Notes = "Returns a new Vector3d that is a {{http://en.wikipedia.org/wiki/Cross_product|cross product}} of this vector and the specified vector." },
Dot = { Params = "Vector3d", Return = "number", Notes = "Returns the dot product of this vector and the specified vector." },
Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." }, Equals = { Params = "Vector3i", Return = "bool", Notes = "Returns true if this vector is exactly the same as the specified vector." },
Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." }, Length = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector." },
Move = { Params = "X, Y, Z", Return = "", Notes = "Moves the vector by the specified amount in each axis direction." }, Move = { Params = "x, y, z", Return = "", Notes = "Moves the vector by the specified amount in each axis direction." },
Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" }, Set = { Params = "x, y, z", Return = "", Notes = "Sets all the coords of the vector at once" },
SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." }, SqrLength = { Params = "", Return = "number", Notes = "Returns the (euclidean) length of this vector, squared. This operation is slightly less computationally expensive than Length(), while it conserves some properties of Length(), such as comparison." },
}, },

View File

@ -340,6 +340,49 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
template <typename T>
int tolua_Vector3_Abs(lua_State * a_LuaState)
{
// Retrieve the params, including self:
cLuaState L(a_LuaState);
Vector3<T> * self;
if (!L.GetStackValues(1, self))
{
tolua_error(a_LuaState, "invalid 'self' in function 'Vector3<T>:Abs'", nullptr);
return 0;
}
// Absolutize the vector:
self->Abs();
return 0;
}
template <typename T>
int tolua_Vector3_Clamp(lua_State * a_LuaState)
{
// Retrieve the params, including self:
cLuaState L(a_LuaState);
Vector3<T> * self;
T min, max;
if (!L.GetStackValues(1, self, min, max))
{
tolua_error(a_LuaState, "invalid parameters for function 'Vector3<T>:Clamp', expected a Vector3 and two numbers", nullptr);
return 0;
}
// Clamp the vector:
self->Clamp(min, max);
return 0;
}
void DeprecatedBindings::Bind(lua_State * tolua_S) void DeprecatedBindings::Bind(lua_State * tolua_S)
{ {
tolua_beginmodule(tolua_S, nullptr); tolua_beginmodule(tolua_S, nullptr);
@ -359,6 +402,21 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines); tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "Vector3i");
tolua_function(tolua_S,"abs", tolua_Vector3_Abs<int>);
tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<int>);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "Vector3f");
tolua_function(tolua_S,"abs", tolua_Vector3_Abs<float>);
tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<float>);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "Vector3d");
tolua_function(tolua_S,"abs", tolua_Vector3_Abs<double>);
tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<double>);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
} }

View File

@ -445,7 +445,7 @@ void GetLargeAppleTreeBranch(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Bra
return; return;
} }
Direction -= a_Direction; Direction -= a_Direction;
Direction.clamp(-1.0, 1.0); Direction.Clamp(-1.0, 1.0);
a_LogBlocks.push_back(sSetBlock(FloorC(CurrentPos.x), FloorC(CurrentPos.y), FloorC(CurrentPos.z), E_BLOCK_LOG, GetLogMetaFromDirection(E_META_LOG_APPLE, Direction))); a_LogBlocks.push_back(sSetBlock(FloorC(CurrentPos.x), FloorC(CurrentPos.y), FloorC(CurrentPos.z), E_BLOCK_LOG, GetLogMetaFromDirection(E_META_LOG_APPLE, Direction)));
} }
} }
@ -456,7 +456,7 @@ void GetLargeAppleTreeBranch(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Bra
NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction) NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction)
{ {
a_Direction.abs(); a_Direction.Abs();
if ((a_Direction.y > a_Direction.x) && (a_Direction.y > a_Direction.z)) if ((a_Direction.y > a_Direction.x) && (a_Direction.y > a_Direction.z))
{ {

View File

@ -107,19 +107,20 @@ public:
return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z; return x * a_Rhs.x + y * a_Rhs.y + z * a_Rhs.z;
} }
inline void abs() /** Updates each coord to its absolute value */
inline void Abs()
{ {
x = (x < 0) ? -x : x; x = (x < 0) ? -x : x;
y = (y < 0) ? -y : y; y = (y < 0) ? -y : y;
z = (z < 0) ? -z : z; z = (z < 0) ? -z : z;
} }
// We can't use a capital letter, because we wouldn't be able to call the normal Clamp function. /** Clamps each coord into the specified range. */
inline void clamp(T a_Min, T a_Max) inline void Clamp(T a_Min, T a_Max)
{ {
x = Clamp(x, a_Min, a_Max); x = ::Clamp(x, a_Min, a_Max);
y = Clamp(y, a_Min, a_Max); y = ::Clamp(y, a_Min, a_Max);
z = Clamp(z, a_Min, a_Max); z = ::Clamp(z, a_Min, a_Max);
} }
inline Vector3<T> Cross(const Vector3<T> & a_Rhs) const inline Vector3<T> Cross(const Vector3<T> & a_Rhs) const