common/math: added minor math functions.

This commit is contained in:
Hermet Park 2024-06-06 16:16:00 +09:00 committed by Hermet Park
parent bda93d99d9
commit 1b9e6ef5a2
2 changed files with 16 additions and 2 deletions

View file

@ -111,3 +111,11 @@ void operator*=(Point& pt, const Matrix& m)
pt.x = tx;
pt.y = ty;
}
Point operator*(const Point& pt, const Matrix& m)
{
auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13;
auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23;
return {tx, ty};
}

View file

@ -152,9 +152,9 @@ static inline void operator*=(Matrix& lhs, const Matrix& rhs)
}
static inline void mathLog(Matrix* m)
static inline void mathLog(const Matrix& m)
{
TVGLOG("MATH", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m->e11, m->e12, m->e13, m->e21, m->e22, m->e23, m->e31, m->e32, m->e33);
TVGLOG("COMMON", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m.e11, m.e12, m.e13, m.e21, m.e22, m.e23, m.e31, m.e32, m.e33);
}
@ -163,6 +163,7 @@ static inline void mathLog(Matrix* m)
/************************************************************************/
void operator*=(Point& pt, const Matrix& m);
Point operator*(const Point& pt, const Matrix& m);
static inline bool mathZero(const Point& p)
@ -231,6 +232,11 @@ static inline Point operator/(const Point& lhs, const float rhs)
}
static inline void mathLog(const Point& pt)
{
TVGLOG("COMMON", "Point: [%f %f]", pt.x, pt.y);
}
/************************************************************************/
/* Interpolation functions */
/************************************************************************/