[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

kbr at google.com kbr at google.com
Wed Dec 22 12:52:01 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit f0be4084b51fa3757911116c9bb6086a8037b7ce
Author: kbr at google.com <kbr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Aug 31 21:27:30 2010 +0000

    2010-08-31  Kenneth Russell  <kbr at google.com>
    
            Reviewed by Simon Fraser.
    
            Add cross product and arithmetic operations to FloatPoint3D
            https://bugs.webkit.org/show_bug.cgi?id=44970
    
            Added set, move, and scale operations similar to FloatPoint's,
            addition and subtraction operators, length, lengthSquared and
            cross product. These changes have been tested with new code to be
            added later.
    
            * platform/graphics/FloatPoint3D.cpp:
            (WebCore::FloatPoint3D::normalize):
            (WebCore::FloatPoint3D::length):
            * platform/graphics/FloatPoint3D.h:
            (WebCore::FloatPoint3D::set):
            (WebCore::FloatPoint3D::move):
            (WebCore::FloatPoint3D::scale):
            (WebCore::FloatPoint3D::dot):
            (WebCore::FloatPoint3D::cross):
            (WebCore::FloatPoint3D::lengthSquared):
            (WebCore::operator +=):
            (WebCore::operator -=):
            (WebCore::operator+):
            (WebCore::operator-):
            (WebCore::operator*):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66533 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index acba090..f2a11b5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,31 @@
+2010-08-31  Kenneth Russell  <kbr at google.com>
+
+        Reviewed by Simon Fraser.
+
+        Add cross product and arithmetic operations to FloatPoint3D
+        https://bugs.webkit.org/show_bug.cgi?id=44970
+
+        Added set, move, and scale operations similar to FloatPoint's,
+        addition and subtraction operators, length, lengthSquared and
+        cross product. These changes have been tested with new code to be
+        added later.
+
+        * platform/graphics/FloatPoint3D.cpp:
+        (WebCore::FloatPoint3D::normalize):
+        (WebCore::FloatPoint3D::length):
+        * platform/graphics/FloatPoint3D.h:
+        (WebCore::FloatPoint3D::set):
+        (WebCore::FloatPoint3D::move):
+        (WebCore::FloatPoint3D::scale):
+        (WebCore::FloatPoint3D::dot):
+        (WebCore::FloatPoint3D::cross):
+        (WebCore::FloatPoint3D::lengthSquared):
+        (WebCore::operator +=):
+        (WebCore::operator -=):
+        (WebCore::operator+):
+        (WebCore::operator-):
+        (WebCore::operator*):
+
 2010-08-31  Martin Robinson  <mrobinson at igalia.com>
 
         Reviewed by Gustavo Noronha Silva.
diff --git a/WebCore/platform/graphics/FloatPoint3D.cpp b/WebCore/platform/graphics/FloatPoint3D.cpp
index 3d37eea..bb05e7f 100644
--- a/WebCore/platform/graphics/FloatPoint3D.cpp
+++ b/WebCore/platform/graphics/FloatPoint3D.cpp
@@ -21,21 +21,27 @@
 
 #include "config.h"
 
-#include <math.h>
 #include "FloatPoint3D.h"
 
+#include <math.h>
+
 namespace WebCore {
 
 void FloatPoint3D::normalize()
 {
-    float length = sqrtf(m_x * m_x + m_y * m_y + m_z * m_z);
+    float tempLength = length();
 
-    if (length != 0) {
-        m_x /= length;
-        m_y /= length;
-        m_z /= length;
+    if (tempLength) {
+        m_x /= tempLength;
+        m_y /= tempLength;
+        m_z /= tempLength;
     }
 }
 
+float FloatPoint3D::length() const
+{
+    return sqrtf(lengthSquared());
+}
+
 } // namespace WebCore
 
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

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list