[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 13:49:29 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 786785b0ab3607d4fc4f7bdf03b1cab177777150
Author: kbr at google.com <kbr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Sep 27 23:07:40 2010 +0000

    2010-09-27  Kenneth Russell  <kbr at google.com>
    
            Reviewed by James Robinson.
    
            Add local triangulation of cubic curve control points
            https://bugs.webkit.org/show_bug.cgi?id=45252
    
            (Re-landing; I neglected to actually add the new files in
            http://trac.webkit.org/changeset/68045 .)
    
            Adding a localized triangulation algorithm which takes as input
            the four control points of a cubic curve segment and provides both
            triangles as well as the ability to walk the interior edges. The
            latter will be used later to fill the interior of shapes bounded
            by these cubic curves, quadratic curves and line segments.
    
            * platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp: Added.
            (WebCore::LoopBlinnLocalTriangulator::Triangle::contains):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::nextVertex):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::indexForVertex):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::makeCounterClockwise):
            (WebCore::LoopBlinnLocalTriangulator::LoopBlinnLocalTriangulator):
            (WebCore::LoopBlinnLocalTriangulator::reset):
            (WebCore::LoopBlinnLocalTriangulator::triangulate):
            (WebCore::LoopBlinnLocalTriangulator::triangulateHelper):
            (WebCore::LoopBlinnLocalTriangulator::addTriangle):
            (WebCore::LoopBlinnLocalTriangulator::addInteriorVertex):
            (WebCore::LoopBlinnLocalTriangulator::isSharedEdge):
            * platform/graphics/gpu/LoopBlinnLocalTriangulator.h: Added.
            (WebCore::LoopBlinnLocalTriangulator::Vertex::Vertex):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::xyCoordinates):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::klmCoordinates):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::set):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::end):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::setEnd):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::marked):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::setMarked):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::interior):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::setInterior):
            (WebCore::LoopBlinnLocalTriangulator::Vertex::resetFlags):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::Triangle):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::getVertex):
            (WebCore::LoopBlinnLocalTriangulator::Triangle::setVertices):
            (WebCore::LoopBlinnLocalTriangulator::getVertex):
            (WebCore::LoopBlinnLocalTriangulator::numberOfTriangles):
            (WebCore::LoopBlinnLocalTriangulator::getTriangle):
            (WebCore::LoopBlinnLocalTriangulator::numberOfInteriorVertices):
            (WebCore::LoopBlinnLocalTriangulator::getInteriorVertex):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68439 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 0277ec5..26eb4b5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,52 @@
+2010-09-27  Kenneth Russell  <kbr at google.com>
+
+        Reviewed by James Robinson.
+
+        Add local triangulation of cubic curve control points
+        https://bugs.webkit.org/show_bug.cgi?id=45252
+
+        (Re-landing; I neglected to actually add the new files in
+        http://trac.webkit.org/changeset/68045 .)
+
+        Adding a localized triangulation algorithm which takes as input
+        the four control points of a cubic curve segment and provides both
+        triangles as well as the ability to walk the interior edges. The
+        latter will be used later to fill the interior of shapes bounded
+        by these cubic curves, quadratic curves and line segments.
+
+        * platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp: Added.
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::contains):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::nextVertex):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::indexForVertex):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::makeCounterClockwise):
+        (WebCore::LoopBlinnLocalTriangulator::LoopBlinnLocalTriangulator):
+        (WebCore::LoopBlinnLocalTriangulator::reset):
+        (WebCore::LoopBlinnLocalTriangulator::triangulate):
+        (WebCore::LoopBlinnLocalTriangulator::triangulateHelper):
+        (WebCore::LoopBlinnLocalTriangulator::addTriangle):
+        (WebCore::LoopBlinnLocalTriangulator::addInteriorVertex):
+        (WebCore::LoopBlinnLocalTriangulator::isSharedEdge):
+        * platform/graphics/gpu/LoopBlinnLocalTriangulator.h: Added.
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::Vertex):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::xyCoordinates):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::klmCoordinates):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::set):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::end):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::setEnd):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::marked):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::setMarked):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::interior):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::setInterior):
+        (WebCore::LoopBlinnLocalTriangulator::Vertex::resetFlags):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::Triangle):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::getVertex):
+        (WebCore::LoopBlinnLocalTriangulator::Triangle::setVertices):
+        (WebCore::LoopBlinnLocalTriangulator::getVertex):
+        (WebCore::LoopBlinnLocalTriangulator::numberOfTriangles):
+        (WebCore::LoopBlinnLocalTriangulator::getTriangle):
+        (WebCore::LoopBlinnLocalTriangulator::numberOfInteriorVertices):
+        (WebCore::LoopBlinnLocalTriangulator::getInteriorVertex):
+
 2010-09-27  Chris Rogers  <crogers at google.com>
 
         Reviewed by Kenneth Russell.
diff --git a/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp b/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp
new file mode 100644
index 0000000..3b73ff6
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "LoopBlinnLocalTriangulator.h"
+
+#include "LoopBlinnMathUtils.h"
+#include <algorithm>
+
+namespace WebCore {
+
+using LoopBlinnMathUtils::approxEqual;
+using LoopBlinnMathUtils::linesIntersect;
+using LoopBlinnMathUtils::pointInTriangle;
+
+bool LoopBlinnLocalTriangulator::Triangle::contains(LoopBlinnLocalTriangulator::Vertex* v)
+{
+    return indexForVertex(v) >= 0;
+}
+
+LoopBlinnLocalTriangulator::Vertex* LoopBlinnLocalTriangulator::Triangle::nextVertex(LoopBlinnLocalTriangulator::Vertex* current, bool traverseCounterClockwise)
+{
+    int index = indexForVertex(current);
+    ASSERT(index >= 0);
+    if (traverseCounterClockwise)
+        ++index;
+    else
+        --index;
+    if (index < 0)
+        index += 3;
+    else
+        index = index % 3;
+    return m_vertices[index];
+}
+
+int LoopBlinnLocalTriangulator::Triangle::indexForVertex(LoopBlinnLocalTriangulator::Vertex* vertex)
+{
+    for (int i = 0; i < 3; ++i)
+        if (m_vertices[i] == vertex)
+            return i;
+    return -1;
+}
+
+void LoopBlinnLocalTriangulator::Triangle::makeCounterClockwise()
+{
+    // Possibly swaps two vertices so that the triangle's vertices are
+    // always specified in counterclockwise order. This orders the
+    // vertices canonically when walking the interior edges from the
+    // start to the end vertex.
+    FloatPoint3D point0(m_vertices[0]->xyCoordinates());
+    FloatPoint3D point1(m_vertices[1]->xyCoordinates());
+    FloatPoint3D point2(m_vertices[2]->xyCoordinates());
+    FloatPoint3D crossProduct = (point1 - point0).cross(point2 - point0);
+    if (crossProduct.z() < 0)
+        std::swap(m_vertices[1], m_vertices[2]);
+}
+
+LoopBlinnLocalTriangulator::LoopBlinnLocalTriangulator()
+{
+    reset();
+}
+
+void LoopBlinnLocalTriangulator::reset()
+{
+    m_numberOfTriangles = 0;
+    m_numberOfInteriorVertices = 0;
+    for (int i = 0; i < 4; ++i) {
+        m_interiorVertices[i] = 0;
+        m_vertices[i].resetFlags();
+    }
+}
+
+void LoopBlinnLocalTriangulator::triangulate(InsideEdgeComputation computeInsideEdges, LoopBlinnConstants::FillSide sideToFill)
+{
+    triangulateHelper(sideToFill);
+
+    if (computeInsideEdges == ComputeInsideEdges) {
+        // We need to compute which vertices describe the path along the
+        // interior portion of the shape, to feed these vertices to the
+        // more general tessellation algorithm. It is possible that we
+        // could determine this directly while producing triangles above.
+        // Here we try to do it generally just by examining the triangles
+        // that have already been produced. We walk around them in a
+        // specific direction determined by which side of the curve is
+        // being filled. We ignore the interior vertex unless it is also
+        // the ending vertex, and skip the edges shared between two
+        // triangles.
+        Vertex* v = &m_vertices[0];
+        addInteriorVertex(v);
+        int numSteps = 0;
+        while (!v->end() && numSteps < 4) {
+            // Find the next vertex according to the above rules
+            bool gotNext = false;
+            for (int i = 0; i < numberOfTriangles() && !gotNext; ++i) {
+                Triangle* tri = getTriangle(i);
+                if (tri->contains(v)) {
+                    Vertex* next = tri->nextVertex(v, sideToFill == LoopBlinnConstants::RightSide);
+                    if (!next->marked() && !isSharedEdge(v, next) && (!next->interior() || next->end())) {
+                        addInteriorVertex(next);
+                        v = next;
+                        // Break out of for loop
+                        gotNext = true;
+                    }
+                }
+            }
+            ++numSteps;
+        }
+        if (!v->end()) {
+            // Something went wrong with the above algorithm; add the last
+            // vertex to the interior vertices anyway. (FIXME: should we
+            // add an assert here and do more extensive testing?)
+            addInteriorVertex(&m_vertices[3]);
+        }
+    }
+}
+
+void LoopBlinnLocalTriangulator::triangulateHelper(LoopBlinnConstants::FillSide sideToFill)
+{
+    reset();
+
+    m_vertices[3].setEnd(true);
+
+    // First test for degenerate cases.
+    for (int i = 0; i < 4; ++i) {
+        for (int j = i + 1; j < 4; ++j) {
+            if (approxEqual(m_vertices[i].xyCoordinates(), m_vertices[j].xyCoordinates())) {
+                // Two of the vertices are coincident, so we can eliminate at
+                // least one triangle. We might be able to eliminate the other
+                // as well, but this seems sufficient to avoid degenerate
+                // triangulations.
+                int indices[3] = { 0 };
+                int index = 0;
+                for (int k = 0; k < 4; ++k)
+                    if (k != j)
+                        indices[index++] = k;
+                addTriangle(&m_vertices[indices[0]],
+                            &m_vertices[indices[1]],
+                            &m_vertices[indices[2]]);
+                return;
+            }
+        }
+    }
+
+    // See whether any of the points are fully contained in the
+    // triangle defined by the other three.
+    for (int i = 0; i < 4; ++i) {
+        int indices[3] = { 0 };
+        int index = 0;
+        for (int j = 0; j < 4; ++j)
+            if (i != j)
+                indices[index++] = j;
+        if (pointInTriangle(m_vertices[i].xyCoordinates(),
+                            m_vertices[indices[0]].xyCoordinates(),
+                            m_vertices[indices[1]].xyCoordinates(),
+                            m_vertices[indices[2]].xyCoordinates())) {
+            // Produce three triangles surrounding this interior vertex.
+            for (int j = 0; j < 3; ++j)
+                addTriangle(&m_vertices[indices[j % 3]],
+                            &m_vertices[indices[(j + 1) % 3]],
+                            &m_vertices[i]);
+            // Mark the interior vertex so we ignore it if trying to trace
+            // the interior edge.
+            m_vertices[i].setInterior(true);
+            return;
+        }
+    }
+
+    // There are only a few permutations of the vertices, ignoring
+    // rotations, which are irrelevant:
+    //
+    //  0--3  0--2  0--3  0--1  0--2  0--1
+    //  |  |  |  |  |  |  |  |  |  |  |  |
+    //  |  |  |  |  |  |  |  |  |  |  |  |
+    //  1--2  1--3  2--1  2--3  3--1  3--2
+    //
+    // Note that three of these are reflections of each other.
+    // Therefore there are only three possible triangulations:
+    //
+    //  0--3  0--2  0--3
+    //  |\ |  |\ |  |\ |
+    //  | \|  | \|  | \|
+    //  1--2  1--3  2--1
+    //
+    // From which we can choose by seeing which of the potential
+    // diagonals intersect. Note that we choose the shortest diagonal
+    // to split the quad.
+    if (linesIntersect(m_vertices[0].xyCoordinates(),
+                       m_vertices[2].xyCoordinates(),
+                       m_vertices[1].xyCoordinates(),
+                       m_vertices[3].xyCoordinates())) {
+        if ((m_vertices[2].xyCoordinates() - m_vertices[0].xyCoordinates()).diagonalLengthSquared() <
+            (m_vertices[3].xyCoordinates() - m_vertices[1].xyCoordinates()).diagonalLengthSquared()) {
+            addTriangle(&m_vertices[0], &m_vertices[1], &m_vertices[2]);
+            addTriangle(&m_vertices[0], &m_vertices[2], &m_vertices[3]);
+        } else {
+            addTriangle(&m_vertices[0], &m_vertices[1], &m_vertices[3]);
+            addTriangle(&m_vertices[1], &m_vertices[2], &m_vertices[3]);
+        }
+    } else if (linesIntersect(m_vertices[0].xyCoordinates(),
+                              m_vertices[3].xyCoordinates(),
+                              m_vertices[1].xyCoordinates(),
+                              m_vertices[2].xyCoordinates())) {
+        if ((m_vertices[3].xyCoordinates() - m_vertices[0].xyCoordinates()).diagonalLengthSquared() <
+            (m_vertices[2].xyCoordinates() - m_vertices[1].xyCoordinates()).diagonalLengthSquared()) {
+            addTriangle(&m_vertices[0], &m_vertices[1], &m_vertices[3]);
+            addTriangle(&m_vertices[0], &m_vertices[3], &m_vertices[2]);
+        } else {
+            addTriangle(&m_vertices[0], &m_vertices[1], &m_vertices[2]);
+            addTriangle(&m_vertices[2], &m_vertices[1], &m_vertices[3]);
+        }
+    } else {
+        // Lines (0->1), (2->3) intersect -- or should, modulo numerical
+        // precision issues
+        if ((m_vertices[1].xyCoordinates() - m_vertices[0].xyCoordinates()).diagonalLengthSquared() <
+            (m_vertices[3].xyCoordinates() - m_vertices[2].xyCoordinates()).diagonalLengthSquared()) {
+            addTriangle(&m_vertices[0], &m_vertices[2], &m_vertices[1]);
+            addTriangle(&m_vertices[0], &m_vertices[1], &m_vertices[3]);
+        } else {
+            addTriangle(&m_vertices[0], &m_vertices[2], &m_vertices[3]);
+            addTriangle(&m_vertices[3], &m_vertices[2], &m_vertices[1]);
+        }
+    }
+}
+
+void LoopBlinnLocalTriangulator::addTriangle(Vertex* v0, Vertex* v1, Vertex* v2)
+{
+    ASSERT(m_numberOfTriangles < 3);
+    m_triangles[m_numberOfTriangles++].setVertices(v0, v1, v2);
+}
+
+void LoopBlinnLocalTriangulator::addInteriorVertex(Vertex* v)
+{
+    ASSERT(m_numberOfInteriorVertices < 4);
+    m_interiorVertices[m_numberOfInteriorVertices++] = v;
+    v->setMarked(true);
+}
+
+bool LoopBlinnLocalTriangulator::isSharedEdge(Vertex* v0, Vertex* v1)
+{
+    bool haveEdge01 = false;
+    bool haveEdge10 = false;
+    for (int i = 0; i < numberOfTriangles(); ++i) {
+        Triangle* tri = getTriangle(i);
+        if (tri->contains(v0) && tri->nextVertex(v0, true) == v1)
+            haveEdge01 = true;
+        if (tri->contains(v1) && tri->nextVertex(v1, true) == v0)
+            haveEdge10 = true;
+    }
+    return haveEdge01 && haveEdge10;
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h b/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h
new file mode 100644
index 0000000..ea3d7e3
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LoopBlinnLocalTriangulator_h
+#define LoopBlinnLocalTriangulator_h
+
+#include "FloatPoint.h"
+#include "FloatPoint3D.h"
+#include "LoopBlinnConstants.h"
+#include <wtf/Assertions.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+// Performs a localized triangulation of the triangle mesh
+// corresponding to the four control point vertices of a cubic curve
+// segment.
+class LoopBlinnLocalTriangulator : public Noncopyable {
+public:
+    // The vertices that the triangulator operates upon, containing both
+    // the position information as well as the cubic texture
+    // coordinates.
+    class Vertex : public Noncopyable {
+    public:
+        Vertex()
+        {
+            resetFlags();
+        }
+
+        const FloatPoint& xyCoordinates() const
+        {
+            return m_xyCoordinates;
+        }
+
+        const FloatPoint3D& klmCoordinates() const
+        {
+            return m_klmCoordinates;
+        }
+
+        // Sets the position and texture coordinates of the vertex.
+        void set(float x, float y,
+                 float k, float l, float m)
+        {
+            m_xyCoordinates.set(x, y);
+            m_klmCoordinates.set(k, l, m);
+        }
+
+        // Flags for walking from the start vertex to the end vertex.
+        bool end()
+        {
+            return m_end;
+        }
+
+        void setEnd(bool end)
+        {
+            m_end = end;
+        }
+
+        bool marked()
+        {
+            return m_marked;
+        }
+
+        void setMarked(bool marked)
+        {
+            m_marked = marked;
+        }
+
+        bool interior()
+        {
+            return m_interior;
+        }
+
+        void setInterior(bool interior)
+        {
+            m_interior = interior;
+        }
+
+        void resetFlags()
+        {
+            m_end = false;
+            m_marked = false;
+            m_interior = false;
+        }
+
+    private:
+        // 2D coordinates of the vertex in the plane.
+        FloatPoint m_xyCoordinates;
+        // Cubic texture coordinates for rendering the curve.
+        FloatPoint3D m_klmCoordinates;
+
+        // Flags for walking from the start vertex to the end vertex.
+        bool m_end;
+        bool m_marked;
+        bool m_interior;
+    };
+
+    // The triangles the Triangulator produces.
+    class Triangle {
+    public:
+        Triangle()
+        {
+            m_vertices[0] = 0;
+            m_vertices[1] = 0;
+            m_vertices[2] = 0;
+        }
+
+        // Gets the vertex at the given index, 0 <= index < 3.
+        Vertex* getVertex(int index)
+        {
+            ASSERT(index >= 0 && index < 3);
+            return m_vertices[index];
+        }
+
+        // Returns true if this triangle contains the given vertex (by
+        // identity, not geometrically).
+        bool contains(Vertex* v);
+
+        // Returns the vertex following the current one in the specified
+        // direction, counterclockwise or clockwise.
+        Vertex* nextVertex(Vertex* current, bool traverseCounterClockwise);
+
+        // Sets the vertices of this triangle, potentially reordering them
+        // to produce a canonical orientation.
+        void setVertices(Vertex* v0,
+                         Vertex* v1,
+                         Vertex* v2)
+        {
+            m_vertices[0] = v0;
+            m_vertices[1] = v1;
+            m_vertices[2] = v2;
+            makeCounterClockwise();
+        }
+
+    private:
+        // Returns the index [0..2] associated with the given vertex, or
+        // -1 if not found.
+        int indexForVertex(Vertex* vertex);
+
+        // Reorders the vertices in this triangle to make them
+        // counterclockwise when viewed in the 2D plane, in order to
+        // achieve a canonical ordering.
+        void makeCounterClockwise();
+
+        // Note: these are raw pointers because they point to the
+        // m_vertices contained in the surrounding triangulator.
+        Vertex* m_vertices[3];
+    };
+
+    LoopBlinnLocalTriangulator();
+
+    // Resets the triangulator's state. After each triangulation and
+    // before the next, call this to re-initialize the internal
+    // vertices' state.
+    void reset();
+
+    // Returns a mutable vertex stored in the triangulator. Use this to
+    // set up the vertices before a triangulation.
+    Vertex* getVertex(int index)
+    {
+        ASSERT(index >= 0 && index < 4);
+        return &m_vertices[index];
+    }
+
+    enum InsideEdgeComputation {
+        ComputeInsideEdges,
+        DontComputeInsideEdges
+    };
+
+    // Once the vertices' contents have been set up, call triangulate()
+    // to recompute the triangles.
+    //
+    // If computeInsideEdges is ComputeInsideEdges, then sideToFill
+    // will be used to determine which side of the cubic curve defined
+    // by the four control points is to be filled.
+    //
+    // The triangulation obeys the following guarantees:
+    //   - If the convex hull is a quadrilateral, then the shortest edge
+    //     will be chosen for the cut into two triangles.
+    //   - If one of the vertices is contained in the triangle spanned
+    //     by the other three, three triangles will be produced.
+    void triangulate(InsideEdgeComputation computeInsideEdges,
+                     LoopBlinnConstants::FillSide sideToFill);
+
+    // Number of triangles computed by triangulate().
+    int numberOfTriangles() const
+    {
+        return m_numberOfTriangles;
+    }
+
+    // Returns the computed triangle at index, 0 <= index < numberOfTriangles().
+    Triangle* getTriangle(int index)
+    {
+        ASSERT(index >= 0 && index < m_numberOfTriangles);
+        return &m_triangles[index];
+    }
+
+    // Number of vertices facing the inside of the shape, if
+    // ComputeInsideEdges was passed when triangulate() was called.
+    int numberOfInteriorVertices() const
+    {
+        return m_numberOfInteriorVertices;
+    }
+
+    // Fetches the given interior vertex, 0 <= index < numberOfInteriorVertices().
+    Vertex* getInteriorVertex(int index)
+    {
+        ASSERT(index >= 0 && index < m_numberOfInteriorVertices);
+        return m_interiorVertices[index];
+    }
+
+private:
+    void triangulateHelper(LoopBlinnConstants::FillSide sideToFill);
+
+    // Adds a triangle to the triangulation.
+    void addTriangle(Vertex* v0, Vertex* v1, Vertex* v2);
+
+    // Adds a vertex to the list of interior vertices.
+    void addInteriorVertex(Vertex* v);
+
+    // Indicates whether the edge between vertex v0 and v1 is shared
+    // between two or more triangles.
+    bool isSharedEdge(Vertex* v0, Vertex* v1);
+
+    // The vertices being triangulated.
+    Vertex m_vertices[4];
+
+    // The vertices corresponding to the edges facing the inside of the
+    // shape, in order from the start vertex to the end vertex. The more
+    // general triangulation algorithm tessellates this interior region.
+    Vertex* m_interiorVertices[4];
+    // The number of interior vertices that are valid for the current
+    // triangulation.
+    int m_numberOfInteriorVertices;
+
+    // There can be at most three triangles computed by this local
+    // algorithm, which occurs when one of the vertices is contained in
+    // the triangle spanned by the other three. Most of the time the
+    // algorithm computes two triangles.
+    Triangle m_triangles[3];
+    int m_numberOfTriangles;
+};
+
+} // namespace WebCore
+
+#endif // LoopBlinnLocalTriangulator_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list