1bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen/* 2bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * Copyright (C) 2010 Google Inc. All rights reserved. 3bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 4bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * Redistribution and use in source and binary forms, with or without 5bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * modification, are permitted provided that the following conditions 6bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * are met: 7bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 8bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 1. Redistributions of source code must retain the above copyright 9bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * notice, this list of conditions and the following disclaimer. 10bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 2. Redistributions in binary form must reproduce the above copyright 11bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * notice, this list of conditions and the following disclaimer in the 12bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * documentation and/or other materials provided with the distribution. 13bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * 14bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen */ 25bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 26bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#ifndef LoopBlinnLocalTriangulator_h 27bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#define LoopBlinnLocalTriangulator_h 28bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 29bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "FloatPoint.h" 30bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "FloatPoint3D.h" 31bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "LoopBlinnConstants.h" 32bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include <wtf/Assertions.h> 3381bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch#include <wtf/Noncopyable.h> 34bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 35bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsennamespace WebCore { 36bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 37bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// Performs a localized triangulation of the triangle mesh 38bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// corresponding to the four control point vertices of a cubic curve 39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// segment. 40ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochclass LoopBlinnLocalTriangulator { 41ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch WTF_MAKE_NONCOPYABLE(LoopBlinnLocalTriangulator); 42bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenpublic: 43bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The vertices that the triangulator operates upon, containing both 44bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // the position information as well as the cubic texture 45bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // coordinates. 46ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch class Vertex { 47ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch WTF_MAKE_NONCOPYABLE(Vertex); 48bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen public: 49bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex() 50bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 51bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen resetFlags(); 52bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 53bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 54bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen const FloatPoint& xyCoordinates() const 55bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 56bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_xyCoordinates; 57bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 58bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 59bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen const FloatPoint3D& klmCoordinates() const 60bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 61bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_klmCoordinates; 62bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 63bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 64bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Sets the position and texture coordinates of the vertex. 65bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void set(float x, float y, 66bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen float k, float l, float m) 67bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 68bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_xyCoordinates.set(x, y); 69bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_klmCoordinates.set(k, l, m); 70bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 71bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 72bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Flags for walking from the start vertex to the end vertex. 73bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool end() 74bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 75bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_end; 76bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 77bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 78bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void setEnd(bool end) 79bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 80bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_end = end; 81bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 82bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 83bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool marked() 84bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 85bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_marked; 86bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 87bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 88bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void setMarked(bool marked) 89bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 90bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_marked = marked; 91bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 92bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 93bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool interior() 94bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 95bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_interior; 96bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 97bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 98bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void setInterior(bool interior) 99bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 100bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_interior = interior; 101bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 102bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 103bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void resetFlags() 104bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 105bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_end = false; 106bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_marked = false; 107bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_interior = false; 108bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 109bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 110bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen private: 111bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // 2D coordinates of the vertex in the plane. 112bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen FloatPoint m_xyCoordinates; 113bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Cubic texture coordinates for rendering the curve. 114bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen FloatPoint3D m_klmCoordinates; 115bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 116bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Flags for walking from the start vertex to the end vertex. 117bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool m_end; 118bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool m_marked; 119bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool m_interior; 120bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen }; 121bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 122bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The triangles the Triangulator produces. 123bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen class Triangle { 124bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen public: 125bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Triangle() 126bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 127bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[0] = 0; 128bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[1] = 0; 129bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[2] = 0; 130bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 131bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 132bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Gets the vertex at the given index, 0 <= index < 3. 133bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* getVertex(int index) 134bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 135bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ASSERT(index >= 0 && index < 3); 136bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_vertices[index]; 137bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 138bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 139bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns true if this triangle contains the given vertex (by 140bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // identity, not geometrically). 141bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool contains(Vertex* v); 142bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 143bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns the vertex following the current one in the specified 144bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // direction, counterclockwise or clockwise. 145bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* nextVertex(Vertex* current, bool traverseCounterClockwise); 146bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 147bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Sets the vertices of this triangle, potentially reordering them 148bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // to produce a canonical orientation. 149bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void setVertices(Vertex* v0, 150bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* v1, 151bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* v2) 152bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 153bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[0] = v0; 154bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[1] = v1; 155bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_vertices[2] = v2; 156bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen makeCounterClockwise(); 157bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 158bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 159bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen private: 160bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns the index [0..2] associated with the given vertex, or 161bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // -1 if not found. 162bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int indexForVertex(Vertex* vertex); 163bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 164bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Reorders the vertices in this triangle to make them 165bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // counterclockwise when viewed in the 2D plane, in order to 166bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // achieve a canonical ordering. 167bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void makeCounterClockwise(); 168bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 169bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Note: these are raw pointers because they point to the 170bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // m_vertices contained in the surrounding triangulator. 171bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* m_vertices[3]; 172bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen }; 173bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 174bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen LoopBlinnLocalTriangulator(); 175bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 176bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Resets the triangulator's state. After each triangulation and 177bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // before the next, call this to re-initialize the internal 178bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // vertices' state. 179bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void reset(); 180bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 181bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns a mutable vertex stored in the triangulator. Use this to 182bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // set up the vertices before a triangulation. 183bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* getVertex(int index) 184bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 185bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ASSERT(index >= 0 && index < 4); 186bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return &m_vertices[index]; 187bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 188bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 189bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen enum InsideEdgeComputation { 190bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ComputeInsideEdges, 191bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen DontComputeInsideEdges 192bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen }; 193bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 194bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Once the vertices' contents have been set up, call triangulate() 195bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // to recompute the triangles. 196bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // 197bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // If computeInsideEdges is ComputeInsideEdges, then sideToFill 198bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // will be used to determine which side of the cubic curve defined 199bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // by the four control points is to be filled. 200bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // 201bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The triangulation obeys the following guarantees: 202bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // - If the convex hull is a quadrilateral, then the shortest edge 203bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // will be chosen for the cut into two triangles. 204bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // - If one of the vertices is contained in the triangle spanned 205bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // by the other three, three triangles will be produced. 206bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void triangulate(InsideEdgeComputation computeInsideEdges, 207bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen LoopBlinnConstants::FillSide sideToFill); 208bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 209bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Number of triangles computed by triangulate(). 210bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int numberOfTriangles() const 211bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 212bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_numberOfTriangles; 213bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 214bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 215bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Returns the computed triangle at index, 0 <= index < numberOfTriangles(). 216bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Triangle* getTriangle(int index) 217bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 218bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ASSERT(index >= 0 && index < m_numberOfTriangles); 219bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return &m_triangles[index]; 220bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 221bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 222bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Number of vertices facing the inside of the shape, if 223bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // ComputeInsideEdges was passed when triangulate() was called. 224bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int numberOfInteriorVertices() const 225bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 226bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_numberOfInteriorVertices; 227bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 228bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 229bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Fetches the given interior vertex, 0 <= index < numberOfInteriorVertices(). 230bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* getInteriorVertex(int index) 231bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen { 232bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ASSERT(index >= 0 && index < m_numberOfInteriorVertices); 233bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen return m_interiorVertices[index]; 234bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen } 235bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 236bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenprivate: 237bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void triangulateHelper(LoopBlinnConstants::FillSide sideToFill); 238bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 239bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Adds a triangle to the triangulation. 240bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void addTriangle(Vertex* v0, Vertex* v1, Vertex* v2); 241bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 242bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Adds a vertex to the list of interior vertices. 243bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void addInteriorVertex(Vertex* v); 244bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 245bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Indicates whether the edge between vertex v0 and v1 is shared 246bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // between two or more triangles. 247bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool isSharedEdge(Vertex* v0, Vertex* v1); 248bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 249bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The vertices being triangulated. 250bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex m_vertices[4]; 251bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 252bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The vertices corresponding to the edges facing the inside of the 253bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // shape, in order from the start vertex to the end vertex. The more 254bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // general triangulation algorithm tessellates this interior region. 255bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Vertex* m_interiorVertices[4]; 256bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // The number of interior vertices that are valid for the current 257bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // triangulation. 258bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_numberOfInteriorVertices; 259bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 260bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // There can be at most three triangles computed by this local 261bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // algorithm, which occurs when one of the vertices is contained in 262bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // the triangle spanned by the other three. Most of the time the 263bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // algorithm computes two triangles. 264bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen Triangle m_triangles[3]; 265bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_numberOfTriangles; 266bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen}; 267bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 268bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen} // namespace WebCore 269bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 270bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#endif // LoopBlinnLocalTriangulator_h 271