gmould.cpp

Go to the documentation of this file.
00001 // $Id: gmould.cpp 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 #include "camtypes.h"
00100 #include "moldshap.h"
00101 #include "gmould.h"
00102 
00103 CC_IMPLEMENT_DYNAMIC(GMould, CCObject)
00104 
00105 
00106 //
00107 // GMould.cpp
00108 //
00110 
00111 GMould::GMould()
00112 {
00113     SrcBBox.left   = 0;
00114     SrcBBox.top    = 1;
00115     SrcBBox.right  = 1;
00116     SrcBBox.bottom = 0;
00117 
00118     MinX = MinY = 0;
00119     MaxX = MaxY = 1;
00120     Width = Depth = 1;
00121 
00122     Tolerance = 0.0;    
00123 }
00124 
00125 
00126 BOOL GMould::Define( POINT *P, RECT *pBBox, DWORD pTolerance )
00127 {
00128     SrcBBox.left    = pBBox->left ;
00129     SrcBBox.top     = pBBox->top ;
00130     SrcBBox.right   = pBBox->right ;
00131     SrcBBox.bottom  = pBBox->bottom ;
00132 
00133     if (!Redefine( P ))
00134         return FALSE;
00135 
00136     Tolerance = CalcTolerance( pTolerance ) ;
00137 
00138     return TRUE;
00139 }
00140 
00141 DocRect GMould::GetBoundingRect()
00142 {
00143     DocRect Rect;
00144     Rect.lo.x = MinX;
00145     Rect.lo.y = MinY;
00146     Rect.hi.x = MaxX;
00147     Rect.hi.y = MaxY;
00148     return Rect;
00149 }
00150 
00151 
00153 
00154 double GMould::CalcTolerance( DWORD pTolerance )
00155 {
00156 //  INT32 x, y ;
00157 //  x = (INT32)( ((float)Tolerance*0x10000000)/Width  ) ;
00158 //  y = (INT32)( ((float)Tolerance*0x10000000)/Depth ) ;
00159     if ( pTolerance==0 )
00160         return 0.0 ;
00161 
00162     double x, y ;
00163 
00164     x = (double) pTolerance/Width ;
00165     y = (double) pTolerance/Depth ;
00166 
00167     return 16*(x+y+2*max(x,y)) ;
00168 }
00169 
00171 
00172 void GMould::FitPoint( POINT a, POINT& b )
00173 {
00174     DPOINT t ;
00175     ScaleSrc    ( a, t ) ;
00176     Transform   ( t, t ) ;
00177     InverseScale( t, b ) ;
00178 }
00179 
00180 void GMould::FitPoint( DPOINT a, POINT& b )
00181 {
00182     DPOINT t ;
00183     Transform   ( a, t ) ;
00184     InverseScale( t, b ) ;
00185 }
00186 
00187 
00188 
00189 BOOL GMould::GenCurve( DPOINT C2, DPOINT C4, 
00190                        DPOINT P0, DPOINT P2, DPOINT P4, DPOINT P6,
00191                        DPOINT T0, DPOINT T2, DPOINT T4, DPOINT T6 )
00192 {
00193     if ( Tolerance > 0 )
00194     {
00195         double T ;
00196         DPOINT D ;
00197         DPOINT P1, P3, P5 ;
00198         DPOINT T1, T3, T5 ;
00199         DPOINT N1, N3, N5 ;
00200         P1.x = (125*P0.x+75*C2.x+15*C4.x +    P6.x)/216 ;
00201         P1.y = (125*P0.y+75*C2.y+15*C4.y +    P6.y)/216 ;
00202         P3.x = (    P0.x+3*(C2.x+   C4.x)+    P6.x)/8 ;
00203         P3.y = (    P0.y+3*(C2.y+   C4.y)+    P6.y)/8 ;
00204         P5.x = (    P0.x+15*C2.x+75*C4.x +125*P6.x)/216 ;
00205         P5.y = (    P0.y+15*C2.y+75*C4.y +125*P6.y)/216 ;
00206         Transform( P1, T1 ) ;
00207         Transform( P3, T3 ) ;
00208         Transform( P5, T5 ) ;
00209         N3.x = -T0.x+9*(T2.x+T4.x)-T6.x ;
00210         N3.y = -T0.y+9*(T2.y+T4.y)-T6.y ;
00211         D.x = fabs(16*T3.x-N3.x) ;
00212         D.y = fabs(16*T3.y-N3.y) ;
00213         T = D.x+D.y+2*max(D.x,D.y) ;
00214         if ( T<=Tolerance )
00215         {
00216             N1.x = 5*(T0.x-T4.x)+15*T2.x+T6.x ;
00217             N1.y = 5*(T0.y-T4.y)+15*T2.y+T6.y ;
00218             D.x = fabs(16*T1.x-N1.x) ;
00219             D.y = fabs(16*T1.y-N1.y) ;
00220             T = D.x+D.y+2*max(D.x,D.y) ;
00221             if ( T<=Tolerance )
00222             {
00223                 N5.x = T0.x+15*T4.x+5*(T6.x-T2.x) ;
00224                 N5.y = T0.y+15*T4.y+5*(T6.y-T2.y) ;
00225                 D.x = fabs(16*T5.x-N5.x) ;
00226                 D.y = fabs(16*T5.y-N5.y) ;
00227                 T = D.x+D.y+2*max(D.x,D.y) ;
00228             }
00229         }
00230         if ( T>Tolerance )
00231         {
00232             DPOINT CL1, CL2, CR1, CR2 ;
00233             CL1.x = (P0.x+C2.x)/2 ;
00234             CL1.y = (P0.y+C2.y)/2 ;
00235             CL2.x = (P0.x+2*C2.x+C4.x)/4 ;
00236             CL2.y = (P0.y+2*C2.y+C4.y)/4 ;
00237             CR1.x = (C2.x+2*C4.x+P6.x)/4 ;
00238             CR1.y = (C2.y+2*C4.y+P6.y)/4 ;
00239             CR2.x = (C4.x+P6.x)/2 ;
00240             CR2.y = (C4.y+P6.y)/2 ;
00241             return GenCurve( CL1, CL2, P0, P1, P2, P3, T0, T1, T2, T3 ) &&
00242                    GenCurve( CR1, CR2, P3, P4, P5, P6, T3, T4, T5, T6 ) ;
00243         }           
00244     }
00245     if ( OLength <= 3 ) return FALSE ;
00246     OLength -= 3 ;
00247     DPOINT N2, N4 ;
00248     N2.x = (-5*T0.x+18*T2.x- 9*T4.x+2*T6.x)/6 ;
00249     N2.y = (-5*T0.y+18*T2.y- 9*T4.y+2*T6.y)/6 ;
00250     N4.x = ( 2*T0.x- 9*T2.x+18*T4.x-5*T6.x)/6 ;
00251     N4.y = ( 2*T0.y- 9*T2.y+18*T4.y-5*T6.y)/6 ;
00252     InverseScale( N2, *OPoints++ ) ; *OTypes++ = PT_BEZIERTO ;
00253     InverseScale( N4, *OPoints++ ) ; *OTypes++ = PT_BEZIERTO ;
00254     InverseScale( T6, *OPoints++ ) ; *OTypes++ = PT_BEZIERTO ;
00255     return TRUE ;
00256 }
00257 
00259 
00260 void GMould::ScaleSrc( POINT a, DPOINT& b )
00261 {
00262     b.x = (double)(a.x-SrcBBox.left  )/(SrcBBox.right-SrcBBox.left  ) ;
00263     b.y = (double)(a.y-SrcBBox.bottom)/(SrcBBox.top  -SrcBBox.bottom) ;
00264 }
00265 
00266 void GMould::Scale( POINT a, DPOINT& b )
00267 {
00268     b.x = (double)(a.x-MinX)/Width ;
00269     b.y = (double)(a.y-MinY)/Depth ;
00270 }
00271 
00272 void GMould::InverseScale( DPOINT a, POINT& b )
00273 {
00274     b.x = MinX+(INT32)(Width*a.x) ;
00275     b.y = MinY+(INT32)(Depth*a.y) ;
00276 }
00277 
00280 
00281 /*
00282 void GMould::PlotTile(
00283                     void* pData,
00284                     void PlotTriangle(
00285                         void* pData,
00286                         CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00287                         CONST POINT *Point0, CONST POINT *Point1, CONST POINT *Point2
00288                     ),
00289                     CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00290                     CONST INT32 Tolerance
00291                 )
00292 {
00293     POINT PointX ;
00294     PointX.x = PointB->x+PointC->x-PointA->x ;
00295     PointX.y = PointB->y+PointC->y-PointA->y ;
00296     POINT q00,q01,q10,q11 ;
00297     FitPoint( *PointA, q00 ) ;
00298     FitPoint( *PointB, q10 ) ;
00299     FitPoint(  PointX, q11 ) ;
00300     FitPoint( *PointC, q01 ) ;
00301     PlotTile(
00302         pData, PlotTriangle,
00303         Tolerance,
00304         0,0,0,
00305         *PointA, *PointB, PointX, *PointC,
00306         q00, q10, q11, q01,
00307         FALSE, FALSE, FALSE, FALSE
00308     ) ;
00309 }
00310 
00311 
00312 
00313 void GMould::PlotTile(
00314                     void* pData,
00315                     void PlotTriangle(
00316                         void* pData,
00317                         CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00318                         CONST POINT *Point0, CONST POINT *Point1, CONST POINT *Point2
00319                     ),
00320                     CONST INT32 Tolerance,
00321                     INT32 i, INT32 j, INT32 s,
00322                     POINT p00, POINT p10, POINT p11, POINT p01,
00323                     POINT q00, POINT q10, POINT q11, POINT q01,
00324                     BOOL f00_10, BOOL f10_11, BOOL f01_11, BOOL f00_01
00325                 )
00326 {
00327     POINT a,b ;
00328     if ( s!=6 )
00329     {
00330         if ( !f00_10 )
00331         {
00332             a.x = (2*p00.x+p10.x)/3 ; a.y = (2*p00.y+p10.y)/3 ; FitPoint( a, a ) ;
00333             b.x = (2*q00.x+q10.x)/3 ; b.y = (2*q00.y+q10.y)/3 ;
00334             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00335             {
00336                 a.x = (p00.x+2*p10.x)/3 ; a.y = (p00.y+2*p10.y)/3 ; FitPoint( a, a ) ;
00337                 b.x = (q00.x+2*q10.x)/3 ; b.y = (q00.y+2*q10.y)/3 ;
00338                 f00_10 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00339             }
00340         }
00341         if ( !f10_11 )
00342         {
00343             a.x = (2*p10.x+p11.x)/3 ; a.y = (2*p10.y+p11.y)/3 ; FitPoint( a, a ) ;
00344             b.x = (2*q10.x+q11.x)/3 ; b.y = (2*q10.y+q11.y)/3 ;
00345             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00346             {
00347                 a.x = (p10.x+2*p11.x)/3 ; a.y = (p10.y+2*p11.y)/3 ; FitPoint( a, a ) ;
00348                 b.x = (q10.x+2*q11.x)/3 ; b.y = (q10.y+2*q11.y)/3 ;
00349                 f10_11 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00350             }
00351         }
00352         if ( !f01_11 )
00353         {
00354             a.x = (2*p01.x+p11.x)/3 ; a.y = (2*p01.y+p11.y)/3 ; FitPoint( a, a ) ;
00355             b.x = (2*q01.x+q11.x)/3 ; b.y = (2*q01.y+q11.y)/3 ;
00356             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00357             {
00358                 a.x = (p01.x+2*p11.x)/3 ; a.y = (p01.y+2*p11.y)/3 ; FitPoint( a, a ) ;
00359                 b.x = (q01.x+2*q11.x)/3 ; b.y = (q01.y+2*q11.y)/3 ;
00360                 f01_11 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00361             }
00362         }
00363         if ( !f00_01 )
00364         {
00365             a.x = (2*p00.x+p01.x)/3 ; a.y = (2*p00.y+p01.y)/3 ; FitPoint( a, a ) ;
00366             b.x = (2*q00.x+q01.x)/3 ; b.y = (2*q00.y+q01.y)/3 ;
00367             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00368             {
00369                 a.x = (p00.x+2*p01.x)/3 ; a.y = (p00.y+2*p01.y)/3 ; FitPoint( a, a ) ;
00370                 b.x = (q00.x+2*q01.x)/3 ; b.y = (q00.y+2*q01.y)/3 ;
00371                 f00_01 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00372             }
00373         }
00374     }
00375     if ( s==6 || (f00_10 && f10_11 && f01_11 && f00_01) )
00376         PlotTriangles( pData, PlotTriangle, i,j,s, q00, q10, q11, q01 ) ;
00377     else
00378     {
00379         POINT p00_10, p10_11, p01_11, p00_01, p ;
00380         POINT q00_10, q10_11, q01_11, q00_01, q ;
00381         p00_10.x = (p00.x+p10.x)/2 ; p00_10.y = (p00.y+p10.y)/2 ;
00382         p10_11.x = (p10.x+p11.x)/2 ; p10_11.y = (p10.y+p11.y)/2 ;
00383         p01_11.x = (p01.x+p11.x)/2 ; p01_11.y = (p01.y+p11.y)/2 ;
00384         p00_01.x = (p00.x+p01.x)/2 ; p00_01.y = (p00.y+p01.y)/2 ;
00385         p.x      = (p00.x+p11.x)/2 ; p.y      = (p00.y+p11.y)/2 ;
00386         if ( f00_10 ) { q00_10.x = (q00.x+q10.x)/2 ; q00_10.y = (q00.y+q10.y)/2 ; } else FitPoint( p00_10, q00_10 ) ;
00387         if ( f10_11 ) { q10_11.x = (q10.x+q11.x)/2 ; q10_11.y = (q10.y+q11.y)/2 ; } else FitPoint( p10_11, q10_11 ) ;
00388         if ( f01_11 ) { q01_11.x = (q01.x+q11.x)/2 ; q01_11.y = (q01.y+q11.y)/2 ; } else FitPoint( p01_11, q01_11 ) ;
00389         if ( f00_01 ) { q00_01.x = (q00.x+q01.x)/2 ; q00_01.y = (q00.y+q01.y)/2 ; } else FitPoint( p00_01, q00_01 ) ;
00390         FitPoint( p, q ) ;
00391         i <<= 1 ;
00392         j <<= 1 ;
00393         s++ ;
00394         PlotTile(
00395             pData, PlotTriangle, Tolerance, i,j,s,
00396             p00, p00_10, p, p00_01,
00397             q00, q00_10, q, q00_01,
00398             f00_10, FALSE, FALSE, f00_01
00399         ) ;
00400         PlotTile(
00401             pData, PlotTriangle, Tolerance, i+1,j,s,
00402             p00_10, p10, p10_11, p,
00403             q00_10, q10, q10_11, q,
00404             f00_10, f10_11, FALSE, FALSE
00405         ) ;
00406         PlotTile(
00407             pData, PlotTriangle, Tolerance, i,j+1,s,
00408             p00_01, p, p01_11, p01,
00409             q00_01, q, q01_11, q01,
00410             FALSE, FALSE, f01_11, f00_01
00411         ) ;
00412         PlotTile(
00413             pData, PlotTriangle, Tolerance, i+1,j+1,s,
00414             p, p10_11, p11, p01_11,
00415             q, q10_11, q11, q01_11,
00416             FALSE, f10_11, f01_11, FALSE
00417         ) ;
00418     }
00419 }
00420 
00422 
00423 void GMould::PlotTile4(
00424                     void* pData,
00425                     void PlotTriangle(
00426                         void* pData,
00427                         CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00428                         CONST POINT *Point0, CONST POINT *Point1, CONST POINT *Point2
00429                     ),
00430                     CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC, CONST POINT *PointD,
00431                     CONST INT32 Tolerance
00432                 )
00433 {
00434     POINT PerspectivePoints[4] ;
00435     PerspectivePoints[0] = *PointA ;
00436     PerspectivePoints[1] = *PointB ;
00437     PerspectivePoints[2] = *PointC ;
00438     PerspectivePoints[3] = *PointD ;
00439     RECT BBox = { 0,0,1,1 } ;
00440     GPerspective Per ;
00441     Per.Define( PerspectivePoints, &BBox, 0 ) ;
00442 
00443     POINT p00,p01,p10,p11 ;
00444     POINT q00,q01,q10,q11 ;
00445     DPOINT a ;
00446     a.x = 0.0 ; a.y = 0.0 ; Per.FitPoint( a, p00 ) ; FitPoint( p00, q00 ) ;
00447     a.x = 1.0 ; a.y = 0.0 ; Per.FitPoint( a, p10 ) ; FitPoint( p10, q10 ) ;
00448     a.x = 1.0 ; a.y = 1.0 ; Per.FitPoint( a, p11 ) ; FitPoint( p11, q11 ) ;
00449     a.x = 0.0 ; a.y = 1.0 ; Per.FitPoint( a, p01 ) ; FitPoint( p01, q01 ) ;
00450 
00451     PlotTile4(
00452         pData, PlotTriangle,
00453         Tolerance,
00454         &Per,
00455         0,0,0,
00456         p00, p10, p11, p01,
00457         q00, q10, q11, q01,
00458         FALSE, FALSE, FALSE, FALSE
00459     ) ;
00460 }
00461 
00462 
00463 
00464 void GMould::PlotTile4(
00465                     void* pData,
00466                     void PlotTriangle(
00467                         void* pData,
00468                         CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00469                         CONST POINT *Point0, CONST POINT *Point1, CONST POINT *Point2
00470                     ),
00471                     CONST INT32 Tolerance,
00472                     GPerspective* Per,
00473                     INT32 i, INT32 j, INT32 s,
00474                     POINT p00, POINT p10, POINT p11, POINT p01,
00475                     POINT q00, POINT q10, POINT q11, POINT q01,
00476                     BOOL f00_10, BOOL f10_11, BOOL f01_11, BOOL f00_01
00477                 )
00478 {
00479     DPOINT A ;
00480     POINT a,b ;
00481     double S = 1.0/(1<<s) ;
00482     double I = S*i ;
00483     double J = S*j ;
00484     double S12 = S/2.0 ;
00485     double S13 = S/3.0 ;
00486     double S23 = S13*2.0 ;
00487     if ( s!=6 )
00488     {
00489         if ( !f00_10 )
00490         {
00491             A.x = I+S13 ; A.y = J ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00492             b.x = (2*q00.x+q10.x)/3 ; b.y = (2*q00.y+q10.y)/3 ;
00493             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00494             {
00495                 A.x = I+S23 ; A.y = J ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00496                 b.x = (q00.x+2*q10.x)/3 ; b.y = (q00.y+2*q10.y)/3 ;
00497                 f00_10 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00498             }
00499         }
00500         if ( !f10_11 )
00501         {
00502             A.x = I+S ; A.y = J+S13 ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00503             b.x = (2*q10.x+q11.x)/3 ; b.y = (2*q10.y+q11.y)/3 ;
00504             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00505             {
00506                 A.x = I+S ; A.y = J+S23 ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00507                 b.x = (q10.x+2*q11.x)/3 ; b.y = (q10.y+2*q11.y)/3 ;
00508                 f10_11 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00509             }
00510         }
00511         if ( !f01_11 )
00512         {
00513             A.x = I+S13 ; A.y = J+S ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00514             b.x = (2*q01.x+q11.x)/3 ; b.y = (2*q01.y+q11.y)/3 ;
00515             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00516             {
00517                 A.x = I+S23 ; A.y = J+S ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00518                 b.x = (q01.x+2*q11.x)/3 ; b.y = (q01.y+2*q11.y)/3 ;
00519                 f01_11 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00520             }
00521         }
00522         if ( !f00_01 )
00523         {
00524             A.x = I ; A.y = J+S13 ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00525             b.x = (2*q00.x+q01.x)/3 ; b.y = (2*q00.y+q01.y)/3 ;
00526             if ( abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance )
00527             {
00528                 A.x = I ; A.y = J+S23 ; Per->FitPoint( A,a ) ; FitPoint( a,a ) ;
00529                 b.x = (q00.x+2*q01.x)/3 ; b.y = (q00.y+2*q01.y)/3 ;
00530                 f00_01 = abs(a.x-b.x)<=Tolerance && abs(a.y-b.y)<=Tolerance ;
00531             }
00532         }
00533     }
00534     if ( s==6 || (f00_10 && f10_11 && f01_11 && f00_01) )
00535         PlotTriangles( pData, PlotTriangle, i,j,s, q00, q10, q11, q01 ) ;
00536     else
00537     {
00538         POINT p00_10, p10_11, p01_11, p00_01, p ;
00539         POINT q00_10, q10_11, q01_11, q00_01, q ;
00540         A.x = I+S12 ; A.y = J     ; Per->FitPoint( A,p00_10 ) ;
00541         A.x = I+S   ; A.y = J+S12 ; Per->FitPoint( A,p10_11 ) ;
00542         A.x = I+S12 ; A.y = J+S   ; Per->FitPoint( A,p01_11 ) ;
00543         A.x = I     ; A.y = J+S12 ; Per->FitPoint( A,p00_01 ) ;
00544         A.x = I+S12 ; A.y = J+S12 ; Per->FitPoint( A,p ) ;
00545         if ( f00_10 ) { q00_10.x = (q00.x+q10.x)/2 ; q00_10.y = (q00.y+q10.y)/2 ; } else FitPoint( p00_10, q00_10 ) ;
00546         if ( f10_11 ) { q10_11.x = (q10.x+q11.x)/2 ; q10_11.y = (q10.y+q11.y)/2 ; } else FitPoint( p10_11, q10_11 ) ;
00547         if ( f01_11 ) { q01_11.x = (q01.x+q11.x)/2 ; q01_11.y = (q01.y+q11.y)/2 ; } else FitPoint( p01_11, q01_11 ) ;
00548         if ( f00_01 ) { q00_01.x = (q00.x+q01.x)/2 ; q00_01.y = (q00.y+q01.y)/2 ; } else FitPoint( p00_01, q00_01 ) ;
00549         FitPoint( p, q ) ;
00550         i <<= 1 ;
00551         j <<= 1 ;
00552         s++ ;
00553         PlotTile4(
00554             pData, PlotTriangle, Tolerance, Per, i,j,s,
00555             p00, p00_10, p, p00_01,
00556             q00, q00_10, q, q00_01,
00557             f00_10, FALSE, FALSE, f00_01
00558         ) ;
00559         PlotTile4(
00560             pData, PlotTriangle, Tolerance, Per, i+1,j,s,
00561             p00_10, p10, p10_11, p,
00562             q00_10, q10, q10_11, q,
00563             f00_10, f10_11, FALSE, FALSE
00564         ) ;
00565         PlotTile4(
00566             pData, PlotTriangle, Tolerance, Per, i,j+1,s,
00567             p00_01, p, p01_11, p01,
00568             q00_01, q, q01_11, q01,
00569             FALSE, FALSE, f01_11, f00_01
00570         ) ;
00571         PlotTile4(
00572             pData, PlotTriangle, Tolerance, Per, i+1,j+1,s,
00573             p, p10_11, p11, p01_11,
00574             q, q10_11, q11, q01_11,
00575             FALSE, f10_11, f01_11, FALSE
00576         ) ;
00577     }
00578 }
00579 
00581 
00582 void GMould::PlotTriangles(
00583                     void* pData,
00584                     void PlotTriangle(
00585                         void* pData,
00586                         CONST POINT *PointA, CONST POINT *PointB, CONST POINT *PointC,
00587                         CONST POINT *Point0, CONST POINT *Point1, CONST POINT *Point2
00588                     ),
00589                     INT32 i, INT32 j, INT32 s,
00590                     POINT q00, POINT q10, POINT q11, POINT q01
00591                 )
00592 {
00593     POINT a,b,c ;
00594     if ( (i^j) & 1 )
00595     {
00596         a.x = q00.x-i*(q10.x-q00.x)-j*(q01.x-q00.x) ;
00597         a.y = q00.y-i*(q10.y-q00.y)-j*(q01.y-q00.y) ;
00598         b.x = a.x+(q10.x-q00.x << s) ; b.y = a.y+(q10.y-q00.y << s) ;
00599         c.x = a.x+(q01.x-q00.x << s) ; c.y = a.y+(q01.y-q00.y << s) ;
00600         PlotTriangle( pData, &a,&b,&c, &q00,&q01,&q10 ) ;
00601         a.x = q11.x-(i+1)*(q11.x-q01.x)-(j+1)*(q11.x-q10.x) ;
00602         a.y = q11.y-(i+1)*(q11.y-q01.y)-(j+1)*(q11.y-q10.y) ;
00603         b.x = a.x+(q11.x-q01.x << s) ; b.y = a.y+(q11.y-q01.y << s) ;
00604         c.x = a.x+(q11.x-q10.x << s) ; c.y = a.y+(q11.y-q10.y << s) ;
00605         PlotTriangle( pData, &a,&b,&c, &q11,&q01,&q10 ) ;
00606     }
00607     else
00608     {
00609         a.x = q00.x-i*(q11.x-q01.x)-j*(q01.x-q00.x) ;
00610         a.y = q00.y-i*(q11.y-q01.y)-j*(q01.y-q00.y) ;
00611         b.x = a.x+(q11.x-q01.x << s) ; b.y = a.y+(q11.y-q01.y << s) ;
00612         c.x = a.x+(q01.x-q00.x << s) ; c.y = a.y+(q01.y-q00.y << s) ;
00613         PlotTriangle( pData, &a,&b,&c, &q00,&q01,&q11 ) ;
00614         a.x = q00.x-i*(q10.x-q00.x)-j*(q11.x-q10.x) ;
00615         a.y = q00.y-i*(q10.y-q00.y)-j*(q11.y-q10.y) ;
00616         b.x = a.x+(q10.x-q00.x << s) ; b.y = a.y+(q10.y-q00.y << s) ;
00617         c.x = a.x+(q11.x-q10.x << s) ; c.y = a.y+(q11.y-q10.y << s) ;
00618         PlotTriangle( pData, &a,&b,&c, &q00,&q10,&q11 ) ;
00619     }
00620 }
00621 
00623 */

Generated on Sat Nov 10 03:45:27 2007 for Camelot by  doxygen 1.4.4