#pragma once #ifndef VHACD_VECTOR_INL #define VHACD_VECTOR_INL namespace VHACD { template inline Vec3 operator*(T lhs, const Vec3 & rhs) { return Vec3(lhs * rhs.X(), lhs * rhs.Y(), lhs * rhs.Z()); } template inline T & Vec3::X() { return m_data[0]; } template inline T & Vec3::Y() { return m_data[1]; } template inline T & Vec3::Z() { return m_data[2]; } template inline const T & Vec3::X() const { return m_data[0]; } template inline const T & Vec3::Y() const { return m_data[1]; } template inline const T & Vec3::Z() const { return m_data[2]; } template inline void Vec3::Normalize() { T n = sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]); if (n != 0.0) (*this) /= n; } template inline T Vec3::GetNorm() const { return sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]); } template inline void Vec3::operator= (const Vec3 & rhs) { this->m_data[0] = rhs.m_data[0]; this->m_data[1] = rhs.m_data[1]; this->m_data[2] = rhs.m_data[2]; } template inline void Vec3::operator+=(const Vec3 & rhs) { this->m_data[0] += rhs.m_data[0]; this->m_data[1] += rhs.m_data[1]; this->m_data[2] += rhs.m_data[2]; } template inline void Vec3::operator-=(const Vec3 & rhs) { this->m_data[0] -= rhs.m_data[0]; this->m_data[1] -= rhs.m_data[1]; this->m_data[2] -= rhs.m_data[2]; } template inline void Vec3::operator-=(T a) { this->m_data[0] -= a; this->m_data[1] -= a; this->m_data[2] -= a; } template inline void Vec3::operator+=(T a) { this->m_data[0] += a; this->m_data[1] += a; this->m_data[2] += a; } template inline void Vec3::operator/=(T a) { this->m_data[0] /= a; this->m_data[1] /= a; this->m_data[2] /= a; } template inline void Vec3::operator*=(T a) { this->m_data[0] *= a; this->m_data[1] *= a; this->m_data[2] *= a; } template inline Vec3 Vec3::operator^ (const Vec3 & rhs) const { return Vec3(m_data[1] * rhs.m_data[2] - m_data[2] * rhs.m_data[1], m_data[2] * rhs.m_data[0] - m_data[0] * rhs.m_data[2], m_data[0] * rhs.m_data[1] - m_data[1] * rhs.m_data[0]); } template inline T Vec3::operator*(const Vec3 & rhs) const { return (m_data[0] * rhs.m_data[0] + m_data[1] * rhs.m_data[1] + m_data[2] * rhs.m_data[2]); } template inline Vec3 Vec3::operator+(const Vec3 & rhs) const { return Vec3(m_data[0] + rhs.m_data[0],m_data[1] + rhs.m_data[1],m_data[2] + rhs.m_data[2]); } template inline Vec3 Vec3::operator-(const Vec3 & rhs) const { return Vec3(m_data[0] - rhs.m_data[0],m_data[1] - rhs.m_data[1],m_data[2] - rhs.m_data[2]) ; } template inline Vec3 Vec3::operator-() const { return Vec3(-m_data[0],-m_data[1],-m_data[2]) ; } template inline Vec3 Vec3::operator*(T rhs) const { return Vec3(rhs * this->m_data[0], rhs * this->m_data[1], rhs * this->m_data[2]); } template inline Vec3 Vec3::operator/ (T rhs) const { return Vec3(m_data[0] / rhs, m_data[1] / rhs, m_data[2] / rhs); } template inline Vec3::Vec3(T a) { m_data[0] = m_data[1] = m_data[2] = a; } template inline Vec3::Vec3(T x, T y, T z) { m_data[0] = x; m_data[1] = y; m_data[2] = z; } template inline Vec3::Vec3(const Vec3 & rhs) { m_data[0] = rhs.m_data[0]; m_data[1] = rhs.m_data[1]; m_data[2] = rhs.m_data[2]; } template inline Vec3::~Vec3(void){}; template inline Vec3::Vec3() {} template inline const bool Colinear(const Vec3 & a, const Vec3 & b, const Vec3 & c) { return ((c.Z() - a.Z()) * (b.Y() - a.Y()) - (b.Z() - a.Z()) * (c.Y() - a.Y()) == 0.0 /*EPS*/) && ((b.Z() - a.Z()) * (c.X() - a.X()) - (b.X() - a.X()) * (c.Z() - a.Z()) == 0.0 /*EPS*/) && ((b.X() - a.X()) * (c.Y() - a.Y()) - (b.Y() - a.Y()) * (c.X() - a.X()) == 0.0 /*EPS*/); } template inline const T ComputeVolume4(const Vec3 & a, const Vec3 & b, const Vec3 & c, const Vec3 & d) { return (a-d) * ((b-d) ^ (c-d)); } template inline bool Vec3::operator<(const Vec3 & rhs) const { if (X() == rhs[0]) { if (Y() == rhs[1]) { return (Z() inline bool Vec3::operator>(const Vec3 & rhs) const { if (X() == rhs[0]) { if (Y() == rhs[1]) { return (Z()>rhs[2]); } return (Y()>rhs[1]); } return (X()>rhs[0]); } template inline Vec2 operator*(T lhs, const Vec2 & rhs) { return Vec2(lhs * rhs.X(), lhs * rhs.Y()); } template inline T & Vec2::X() { return m_data[0]; } template inline T & Vec2::Y() { return m_data[1]; } template inline const T & Vec2::X() const { return m_data[0]; } template inline const T & Vec2::Y() const { return m_data[1]; } template inline void Vec2::Normalize() { T n = sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]); if (n != 0.0) (*this) /= n; } template inline T Vec2::GetNorm() const { return sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]); } template inline void Vec2::operator= (const Vec2 & rhs) { this->m_data[0] = rhs.m_data[0]; this->m_data[1] = rhs.m_data[1]; } template inline void Vec2::operator+=(const Vec2 & rhs) { this->m_data[0] += rhs.m_data[0]; this->m_data[1] += rhs.m_data[1]; } template inline void Vec2::operator-=(const Vec2 & rhs) { this->m_data[0] -= rhs.m_data[0]; this->m_data[1] -= rhs.m_data[1]; } template inline void Vec2::operator-=(T a) { this->m_data[0] -= a; this->m_data[1] -= a; } template inline void Vec2::operator+=(T a) { this->m_data[0] += a; this->m_data[1] += a; } template inline void Vec2::operator/=(T a) { this->m_data[0] /= a; this->m_data[1] /= a; } template inline void Vec2::operator*=(T a) { this->m_data[0] *= a; this->m_data[1] *= a; } template inline T Vec2::operator^ (const Vec2 & rhs) const { return m_data[0] * rhs.m_data[1] - m_data[1] * rhs.m_data[0]; } template inline T Vec2::operator*(const Vec2 & rhs) const { return (m_data[0] * rhs.m_data[0] + m_data[1] * rhs.m_data[1]); } template inline Vec2 Vec2::operator+(const Vec2 & rhs) const { return Vec2(m_data[0] + rhs.m_data[0],m_data[1] + rhs.m_data[1]); } template inline Vec2 Vec2::operator-(const Vec2 & rhs) const { return Vec2(m_data[0] - rhs.m_data[0],m_data[1] - rhs.m_data[1]); } template inline Vec2 Vec2::operator-() const { return Vec2(-m_data[0],-m_data[1]) ; } template inline Vec2 Vec2::operator*(T rhs) const { return Vec2(rhs * this->m_data[0], rhs * this->m_data[1]); } template inline Vec2 Vec2::operator/ (T rhs) const { return Vec2(m_data[0] / rhs, m_data[1] / rhs); } template inline Vec2::Vec2(T a) { m_data[0] = m_data[1] = a; } template inline Vec2::Vec2(T x, T y) { m_data[0] = x; m_data[1] = y; } template inline Vec2::Vec2(const Vec2 & rhs) { m_data[0] = rhs.m_data[0]; m_data[1] = rhs.m_data[1]; } template inline Vec2::~Vec2(void){}; template inline Vec2::Vec2() {} /* InsideTriangle decides if a point P is Inside of the triangle defined by A, B, C. */ template inline const bool InsideTriangle(const Vec2 & a, const Vec2 & b, const Vec2 & c, const Vec2 & p) { T ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; T cCROSSap, bCROSScp, aCROSSbp; ax = c.X() - b.X(); ay = c.Y() - b.Y(); bx = a.X() - c.X(); by = a.Y() - c.Y(); cx = b.X() - a.X(); cy = b.Y() - a.Y(); apx= p.X() - a.X(); apy= p.Y() - a.Y(); bpx= p.X() - b.X(); bpy= p.Y() - b.Y(); cpx= p.X() - c.X(); cpy= p.Y() - c.Y(); aCROSSbp = ax*bpy - ay*bpx; cCROSSap = cx*apy - cy*apx; bCROSScp = bx*cpy - by*cpx; return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0)); } } #endif //VHACD_VECTOR_INL