From 5ddde30071f639962dd557c453f2ad01f8f0fd00 Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Wed, 8 Sep 2010 12:18:00 +0100 Subject: Merge WebKit at r66666 : Initial merge by git. Change-Id: I57dedeb49859adc9c539e760f0e749768c66626f --- WebCore/platform/graphics/FloatPoint3D.h | 72 +++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'WebCore/platform/graphics/FloatPoint3D.h') 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 -- cgit v1.1