Skip to content

Commit

Permalink
Implement kmVec2Assign
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazade committed Apr 1, 2012
1 parent e25d39d commit af9f66b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kazmath/vec2.c
Expand Up @@ -116,3 +116,18 @@ int kmVec2AreEqual(const kmVec2* p1, const kmVec2* p2)
(p1->y < p2->y + kmEpsilon && p1->y > p2->y - kmEpsilon)
);
}

/**
* Assigns pIn to pOut. Returns pOut. If pIn and pOut are the same
* then nothing happens but pOut is still returned
*/
kmVec2* kmVec2Assign(kmVec2* pOut, const kmVec2* pIn) {
if (pOut == pIn) {
return pOut;
}

pOut->x = pIn->x;
pOut->y = pIn->y;

return pOut;
}
2 changes: 2 additions & 0 deletions kazmath/vec2.h
Expand Up @@ -44,6 +44,7 @@ typedef struct kmVec2 {
#ifdef __cplusplus
extern "C" {
#endif

kmVec2* kmVec2Fill(kmVec2* pOut, kmScalar x, kmScalar y);
kmScalar kmVec2Length(const kmVec2* pIn); ///< Returns the length of the vector
kmScalar kmVec2LengthSq(const kmVec2* pIn); ///< Returns the square of the length of the vector
Expand All @@ -55,6 +56,7 @@ kmVec2* kmVec2Transform(kmVec2* pOut, const kmVec2* pV1, const struct kmMat3* pM
kmVec2* kmVec2TransformCoord(kmVec2* pOut, const kmVec2* pV, const struct kmMat3* pM); ///<Transforms a 2D vector by a given matrix, projecting the result back into w = 1.
kmVec2* kmVec2Scale(kmVec2* pOut, const kmVec2* pIn, const kmScalar s); ///< Scales a vector to length s
int kmVec2AreEqual(const kmVec2* p1, const kmVec2* p2); ///< Returns 1 if both vectors are equal
kmVec2* kmVec2Assign(kmVec2* pOut, const kmVec2* pIn);

#ifdef __cplusplus
}
Expand Down

0 comments on commit af9f66b

Please sign in to comment.