diff options
author | Kristian Monsen <kristianm@google.com> | 2010-09-08 12:18:00 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-09-11 12:08:58 +0100 |
commit | 5ddde30071f639962dd557c453f2ad01f8f0fd00 (patch) | |
tree | 775803c4ab35af50aa5f5472cd1fb95fe9d5152d /WebCore/platform/graphics/FloatPoint3D.h | |
parent | 3e63d9b33b753ca86d0765d1b3d711114ba9e34f (diff) | |
download | external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.zip external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.tar.gz external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.tar.bz2 |
Merge WebKit at r66666 : Initial merge by git.
Change-Id: I57dedeb49859adc9c539e760f0e749768c66626f
Diffstat (limited to 'WebCore/platform/graphics/FloatPoint3D.h')
-rw-r--r-- | WebCore/platform/graphics/FloatPoint3D.h | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/WebCore/platform/graphics/FloatPoint3D.h b/WebCore/platform/graphics/FloatPoint3D.h index d10e3c1..9ee548d 100644 --- a/WebCore/platform/graphics/FloatPoint3D.h +++ b/WebCore/platform/graphics/FloatPoint3D.h @@ -65,15 +65,85 @@ public: float z() const { return m_z; } void setZ(float z) { m_z = z; } + void set(float x, float y, float z) + { + m_x = x; + m_y = y; + m_z = z; + } + void move(float dx, float dy, float dz) + { + m_x += dx; + m_y += dy; + m_z += dz; + } + void scale(float sx, float sy, float sz) + { + m_x *= sx; + m_y *= sy; + m_z *= sz; + } void normalize(); + float dot(const FloatPoint3D& a) const + { + return m_x * a.x() + m_y * a.y() + m_z * a.z(); + } + + // Sets this FloatPoint3D to the cross product of the passed two. + // It is safe for "this" to be the same as either or both of the + // arguments. + void cross(const FloatPoint3D& a, const FloatPoint3D& b) + { + float x = a.y() * b.z() - a.z() * b.y(); + float y = a.z() * b.x() - a.x() * b.z(); + float z = a.x() * b.y() - a.y() * b.x(); + m_x = x; + m_y = y; + m_z = z; + } + + // Convenience function returning "this cross point" as a + // stack-allocated result. + FloatPoint3D cross(const FloatPoint3D& point) const + { + FloatPoint3D result; + result.cross(*this, point); + return result; + } + + float length() const; + float lengthSquared() const { return this->dot(*this); } + private: float m_x; float m_y; float m_z; }; +inline FloatPoint3D& operator +=(FloatPoint3D& a, const FloatPoint3D& b) +{ + a.move(b.x(), b.y(), b.z()); + return a; +} + +inline FloatPoint3D& operator -=(FloatPoint3D& a, const FloatPoint3D& b) +{ + a.move(-b.x(), -b.y(), -b.z()); + return a; +} + +inline FloatPoint3D operator+(const FloatPoint3D& a, const FloatPoint3D& b) +{ + return FloatPoint3D(a.x() + b.x(), a.y() + b.y(), a.z() + b.z()); +} + +inline FloatPoint3D operator-(const FloatPoint3D& a, const FloatPoint3D& b) +{ + return FloatPoint3D(a.x() - b.x(), a.y() - b.y(), a.z() - b.z()); +} + inline bool operator==(const FloatPoint3D& a, const FloatPoint3D& b) { return a.x() == b.x() && a.y() == b.y() && a.z() == b.z(); @@ -87,7 +157,7 @@ inline bool operator!=(const FloatPoint3D& a, const FloatPoint3D& b) inline float operator*(const FloatPoint3D& a, const FloatPoint3D& b) { // dot product - return a.x() * b.x() + a.y() * b.y() + a.z() * b.z(); + return a.dot(b); } } // namespace WebCore |