tests/auto/qtessellator/testtessellator.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "testtessellator.h"
       
    42 #include <private/qtessellator_p.h>
       
    43 
       
    44 #include "math.h"
       
    45 
       
    46 class TestTessellator : public QTessellator
       
    47 {
       
    48 public:
       
    49     QVector<XTrapezoid> *traps;
       
    50     void addTrap(const Trapezoid &trap);
       
    51 };
       
    52 
       
    53 void TestTessellator::addTrap(const Trapezoid &trap)
       
    54 {
       
    55     XTrapezoid xtrap;
       
    56     xtrap.top = Q27Dot5ToXFixed(trap.top);
       
    57     xtrap.bottom = Q27Dot5ToXFixed(trap.bottom);
       
    58     xtrap.left.p1.x = Q27Dot5ToXFixed(trap.topLeft->x);
       
    59     xtrap.left.p1.y = Q27Dot5ToXFixed(trap.topLeft->y);
       
    60     xtrap.left.p2.x = Q27Dot5ToXFixed(trap.bottomLeft->x);
       
    61     xtrap.left.p2.y = Q27Dot5ToXFixed(trap.bottomLeft->y);
       
    62     xtrap.right.p1.x = Q27Dot5ToXFixed(trap.topRight->x);
       
    63     xtrap.right.p1.y = Q27Dot5ToXFixed(trap.topRight->y);
       
    64     xtrap.right.p2.x = Q27Dot5ToXFixed(trap.bottomRight->x);
       
    65     xtrap.right.p2.y = Q27Dot5ToXFixed(trap.bottomRight->y);
       
    66     traps->append(xtrap);
       
    67 }
       
    68 
       
    69 
       
    70 void test_tesselate_polygon(QVector<XTrapezoid> *traps, const QPointF *points, int nPoints,
       
    71                          bool winding)
       
    72 {
       
    73     TestTessellator t;
       
    74     t.traps = traps;
       
    75     t.setWinding(winding);
       
    76     t.tessellate(points, nPoints);
       
    77 }
       
    78 
       
    79 
       
    80 void test_tessellate_polygon_convex(QVector<XTrapezoid> *traps, const QPointF *points, int nPoints,
       
    81                                    bool winding)
       
    82 {
       
    83     TestTessellator t;
       
    84     t.traps = traps;
       
    85     t.setWinding(winding);
       
    86     t.tessellateConvex(points, nPoints);
       
    87 }
       
    88 
       
    89 
       
    90 void test_tessellate_polygon_rect(QVector<XTrapezoid> *traps, const QPointF *points, int nPoints,
       
    91                                   bool winding)
       
    92 {
       
    93     // 5 points per rect
       
    94     Q_ASSERT(nPoints % 5 == 0);
       
    95 
       
    96     TestTessellator t;
       
    97     t.traps = traps;
       
    98     t.setWinding(winding);
       
    99     for (int i = 0; i < nPoints / 5; ++i) {
       
   100         QPointF rectA = points[5*i];
       
   101         QPointF rectB = points[5*i+1];
       
   102         QPointF rectC = points[5*i+2];
       
   103         QPointF rectD = points[5*i+3];
       
   104 
       
   105         QPointF a = (rectA + rectD) * 0.5;
       
   106         QPointF b = (rectB + rectC) * 0.5;
       
   107 
       
   108         QPointF delta = rectA - rectD;
       
   109 
       
   110         qreal width = sqrt(delta.x() * delta.x() + delta.y() * delta.y());
       
   111 
       
   112         t.tessellateRect(a, b, width);
       
   113     }
       
   114 }