Title: [138802] trunk/Source/WebCore
Revision
138802
Author
[email protected]
Date
2013-01-04 08:58:06 -0800 (Fri, 04 Jan 2013)

Log Message

[CSS Exclusions] The ExclusionPolygon classes should allow more than one type of "Edge" class
https://bugs.webkit.org/show_bug.cgi?id=106026

Patch by Hans Muller <[email protected]> on 2013-01-04
Reviewed by Dirk Schulze.

Refactored the ExclusionPolygonEdge class to pave the way for a similar
OffsetEdge class. The new VertexPair abstract base class provides the common
state and operations. ExclusionPolygonEdge now extends VertexPair and defines
ExclusionPolygon as a friend, since the ExclusionPolygon constructor initializes
its private state.

* rendering/ExclusionPolygon.cpp:
(WebCore::ExclusionPolygon::ExclusionPolygon): Use ExclusionPolygonEdge accessors instead of direct field access.
(WebCore::getVertexIntersectionVertices): Ditto.
* rendering/ExclusionPolygon.h:
(VertexPair): New abstract base class.
(WebCore::VertexPair::~VertexPair):
(WebCore::VertexPair::minX): This method was defined in ExclusionPolygonEdge.
(WebCore::VertexPair::minY): Ditto.
(WebCore::VertexPair::maxX): Ditto.
(WebCore::VertexPair::maxY): Ditto.
(ExclusionPolygonEdge): Now extends VertexPair.
(WebCore::ExclusionPolygonEdge::previousEdge): Refer to m_ private class fields, instead of public struct fields.
(WebCore::ExclusionPolygonEdge::nextEdge): Ditto.
(WebCore::ExclusionPolygonEdge::polygon): Ditto.
(WebCore::ExclusionPolygonEdge::vertexIndex1): Ditto.
(WebCore::ExclusionPolygonEdge::vertexIndex2): Ditto.
(WebCore::ExclusionPolygonEdge::edgeIndex): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138801 => 138802)


--- trunk/Source/WebCore/ChangeLog	2013-01-04 16:35:37 UTC (rev 138801)
+++ trunk/Source/WebCore/ChangeLog	2013-01-04 16:58:06 UTC (rev 138802)
@@ -1,3 +1,34 @@
+2013-01-04  Hans Muller  <[email protected]>
+
+        [CSS Exclusions] The ExclusionPolygon classes should allow more than one type of "Edge" class
+        https://bugs.webkit.org/show_bug.cgi?id=106026
+
+        Reviewed by Dirk Schulze.
+
+        Refactored the ExclusionPolygonEdge class to pave the way for a similar
+        OffsetEdge class. The new VertexPair abstract base class provides the common
+        state and operations. ExclusionPolygonEdge now extends VertexPair and defines
+        ExclusionPolygon as a friend, since the ExclusionPolygon constructor initializes
+        its private state.
+
+        * rendering/ExclusionPolygon.cpp:
+        (WebCore::ExclusionPolygon::ExclusionPolygon): Use ExclusionPolygonEdge accessors instead of direct field access.
+        (WebCore::getVertexIntersectionVertices): Ditto.
+        * rendering/ExclusionPolygon.h:
+        (VertexPair): New abstract base class.
+        (WebCore::VertexPair::~VertexPair):
+        (WebCore::VertexPair::minX): This method was defined in ExclusionPolygonEdge.
+        (WebCore::VertexPair::minY): Ditto.
+        (WebCore::VertexPair::maxX): Ditto.
+        (WebCore::VertexPair::maxY): Ditto.
+        (ExclusionPolygonEdge): Now extends VertexPair.
+        (WebCore::ExclusionPolygonEdge::previousEdge): Refer to m_ private class fields, instead of public struct fields.
+        (WebCore::ExclusionPolygonEdge::nextEdge): Ditto.
+        (WebCore::ExclusionPolygonEdge::polygon): Ditto.
+        (WebCore::ExclusionPolygonEdge::vertexIndex1): Ditto.
+        (WebCore::ExclusionPolygonEdge::vertexIndex2): Ditto.
+        (WebCore::ExclusionPolygonEdge::edgeIndex): Ditto.
+
 2013-01-04  Steve Block  <[email protected]>
 
         Add 'float FloatPoint::slopeAngleRadians()'

Modified: trunk/Source/WebCore/rendering/ExclusionPolygon.cpp (138801 => 138802)


--- trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2013-01-04 16:35:37 UTC (rev 138801)
+++ trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2013-01-04 16:58:06 UTC (rev 138802)
@@ -115,10 +115,10 @@
     do {
         m_boundingBox.extend(vertexAt(vertexIndex1));
         unsigned vertexIndex2 = findNextEdgeVertexIndex(vertexIndex1, clockwise);
-        m_edges[edgeIndex].polygon = this;
-        m_edges[edgeIndex].vertexIndex1 = vertexIndex1;
-        m_edges[edgeIndex].vertexIndex2 = vertexIndex2;
-        m_edges[edgeIndex].edgeIndex = edgeIndex;
+        m_edges[edgeIndex].m_polygon = this;
+        m_edges[edgeIndex].m_vertexIndex1 = vertexIndex1;
+        m_edges[edgeIndex].m_vertexIndex2 = vertexIndex2;
+        m_edges[edgeIndex].m_edgeIndex = edgeIndex;
         edgeIndex++;
         vertexIndex1 = vertexIndex2;
     } while (vertexIndex1);
@@ -127,7 +127,7 @@
         const ExclusionPolygonEdge& firstEdge = m_edges[0];
         const ExclusionPolygonEdge& lastEdge = m_edges[edgeIndex - 1];
         if (areCollinearPoints(lastEdge.vertex1(), lastEdge.vertex2(), firstEdge.vertex2())) {
-            m_edges[0].vertexIndex1 = lastEdge.vertexIndex1;
+            m_edges[0].m_vertexIndex1 = lastEdge.m_vertexIndex1;
             edgeIndex--;
         }
     }
@@ -184,19 +184,19 @@
     if (intersection.type != VertexMinY && intersection.type != VertexMaxY)
         return false;
 
-    ASSERT(intersection.edge && intersection.edge->polygon);
-    const ExclusionPolygon& polygon = *(intersection.edge->polygon);
+    ASSERT(intersection.edge && intersection.edge->polygon());
+    const ExclusionPolygon& polygon = *(intersection.edge->polygon());
     const ExclusionPolygonEdge& thisEdge = *(intersection.edge);
 
     if ((intersection.type == VertexMinY && (thisEdge.vertex1().y() < thisEdge.vertex2().y()))
         || (intersection.type == VertexMaxY && (thisEdge.vertex1().y() > thisEdge.vertex2().y()))) {
-        prevVertex = polygon.vertexAt(thisEdge.previousEdge().vertexIndex1);
-        thisVertex = polygon.vertexAt(thisEdge.vertexIndex1);
-        nextVertex = polygon.vertexAt(thisEdge.vertexIndex2);
+        prevVertex = polygon.vertexAt(thisEdge.previousEdge().vertexIndex1());
+        thisVertex = polygon.vertexAt(thisEdge.vertexIndex1());
+        nextVertex = polygon.vertexAt(thisEdge.vertexIndex2());
     } else {
-        prevVertex = polygon.vertexAt(thisEdge.vertexIndex1);
-        thisVertex = polygon.vertexAt(thisEdge.vertexIndex2);
-        nextVertex = polygon.vertexAt(thisEdge.nextEdge().vertexIndex2);
+        prevVertex = polygon.vertexAt(thisEdge.vertexIndex1());
+        thisVertex = polygon.vertexAt(thisEdge.vertexIndex2());
+        nextVertex = polygon.vertexAt(thisEdge.nextEdge().vertexIndex2());
     }
 
     return true;

Modified: trunk/Source/WebCore/rendering/ExclusionPolygon.h (138801 => 138802)


--- trunk/Source/WebCore/rendering/ExclusionPolygon.h	2013-01-04 16:35:37 UTC (rev 138801)
+++ trunk/Source/WebCore/rendering/ExclusionPolygon.h	2013-01-04 16:58:06 UTC (rev 138802)
@@ -43,7 +43,7 @@
 
 namespace WebCore {
 
-struct ExclusionPolygonEdge;
+class ExclusionPolygonEdge;
 
 // This class is used by PODIntervalTree for debugging.
 #ifndef NDEBUG
@@ -84,43 +84,59 @@
     bool m_empty;
 };
 
+class VertexPair {
+public:
+    virtual ~VertexPair() { }
+
+    virtual const FloatPoint& vertex1() const = 0;
+    virtual const FloatPoint& vertex2() const = 0;
+
+    float minX() const { return std::min(vertex1().x(), vertex2().x()); }
+    float minY() const { return std::min(vertex1().y(), vertex2().y()); }
+    float maxX() const { return std::max(vertex1().x(), vertex2().x()); }
+    float maxY() const { return std::max(vertex1().y(), vertex2().y()); }
+};
+
 // EdgeIntervalTree nodes store minY, maxY, and a ("UserData") pointer to an ExclusionPolygonEdge. Edge vertex
 // index1 is less than index2, except the last edge, where index2 is 0. When a polygon edge is defined by 3
 // or more colinear vertices, index2 can be the the index of the last colinear vertex.
-struct ExclusionPolygonEdge {
-    const FloatPoint& vertex1() const
+class ExclusionPolygonEdge : public VertexPair {
+    friend class ExclusionPolygon;
+public:
+    virtual const FloatPoint& vertex1() const OVERRIDE
     {
-        ASSERT(polygon);
-        return polygon->vertexAt(vertexIndex1);
+        ASSERT(m_polygon);
+        return m_polygon->vertexAt(m_vertexIndex1);
     }
 
-    const FloatPoint& vertex2() const
+    virtual const FloatPoint& vertex2() const OVERRIDE
     {
-        ASSERT(polygon);
-        return polygon->vertexAt(vertexIndex2);
+        ASSERT(m_polygon);
+        return m_polygon->vertexAt(m_vertexIndex2);
     }
 
     const ExclusionPolygonEdge& previousEdge() const
     {
-        ASSERT(polygon && polygon->numberOfEdges() > 1);
-        return polygon->edgeAt((edgeIndex + polygon->numberOfEdges() - 1) % polygon->numberOfEdges());
+        ASSERT(m_polygon && m_polygon->numberOfEdges() > 1);
+        return m_polygon->edgeAt((m_edgeIndex + m_polygon->numberOfEdges() - 1) % m_polygon->numberOfEdges());
     }
 
     const ExclusionPolygonEdge& nextEdge() const
     {
-        ASSERT(polygon && polygon->numberOfEdges() > 1);
-        return polygon->edgeAt((edgeIndex + 1) % polygon->numberOfEdges());
+        ASSERT(m_polygon && m_polygon->numberOfEdges() > 1);
+        return m_polygon->edgeAt((m_edgeIndex + 1) % m_polygon->numberOfEdges());
     }
 
-    float minX() const { return std::min(vertex1().x(), vertex2().x()); }
-    float minY() const { return std::min(vertex1().y(), vertex2().y()); }
-    float maxX() const { return std::max(vertex1().x(), vertex2().x()); }
-    float maxY() const { return std::max(vertex1().y(), vertex2().y()); }
+    const ExclusionPolygon* polygon() const { return m_polygon; }
+    unsigned vertexIndex1() const { return m_vertexIndex1; }
+    unsigned vertexIndex2() const { return m_vertexIndex2; }
+    unsigned edgeIndex() const { return m_edgeIndex; }
 
-    const ExclusionPolygon* polygon;
-    unsigned vertexIndex1;
-    unsigned vertexIndex2;
-    unsigned edgeIndex;
+private:
+    const ExclusionPolygon* m_polygon;
+    unsigned m_vertexIndex1;
+    unsigned m_vertexIndex2;
+    unsigned m_edgeIndex;
 };
 
 // These structures are used by PODIntervalTree for debugging.1
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to