gwinding.cpp File Reference

(r1785/r751)

#include "camtypes.h"
#include <math.h>
#include "gwinding.h"

Go to the source code of this file.

Functions

INT32 GWSgnMulSubMul (INT32 A, INT32 B, INT32 C, INT32 D)
void DoLine (POINT P)
void FlattenSplit (POINT P0, POINT P1, POINT P2, POINT P3)
void FlattenCurve (POINT P0, POINT P1, POINT P2, POINT P3)
BOOL GWinding (PPOINT pPoints, PBYTE Types, INT32 Length, UINT32 pFlatness, UINT32 &pBottomLeftOffset, POINT &pBottomLeft)

Variables

PPOINT Points
PPOINT StartPoint
POINT BottomLeft
POINT PrevPoint
POINT LastPoint
POINT OldPoint
POINT Prev_Point
POINT Next_Point
INT32 Flags
UINT32 Flatness
UINT32 BottomLeftOffset


Function Documentation

void DoLine POINT  P  ) 
 

Definition at line 164 of file gwinding.cpp.

00165 {
00166     if ( (Flags & 04) && ( OldPoint.x!=LastPoint.x || OldPoint.y!=LastPoint.y ) )
00167     {
00168         PrevPoint = LastPoint ;
00169         Flags &= ~04 ;
00170     }
00171     if (  P.x+P.y >  BottomLeft.x+BottomLeft.y ||
00172          (P.x+P.y == BottomLeft.x+BottomLeft.y &&
00173               P.y >=              BottomLeft.y) )
00174     {
00175         if ( (Flags & 02) && ( P.x!=BottomLeft.x ||
00176                                P.y!=BottomLeft.y ) )
00177         {
00178             Next_Point = P ;
00179             Flags &= ~02 ;
00180         }
00181         Flags |= 04 ;
00182     }
00183     else
00184     {
00185         Prev_Point = PrevPoint ;
00186         BottomLeft = P ;
00187         BottomLeftOffset = Points-StartPoint ; /* Save curve offset */
00188         Flags = 02 ;
00189         PrevPoint = P ;
00190     }
00191     OldPoint = LastPoint ;
00192     LastPoint = P ;
00193 }

void FlattenCurve POINT  P0,
POINT  P1,
POINT  P2,
POINT  P3
 

Definition at line 199 of file gwinding.cpp.

00200 {
00201     UINT32 dx,dy ;
00202     dx = abs(P1.x*3 - P0.x*2 - P3.x) ;
00203     dy = abs(P1.y*3 - P0.y*2 - P3.y) ;
00204     if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
00205         FlattenSplit(P0,P1,P2,P3) ;
00206     else
00207     {
00208         dx = abs(P2.x*3 - P0.x - P3.x*2) ;
00209         dy = abs(P2.y*3 - P0.y - P3.y*2) ;
00210         if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
00211             FlattenSplit(P0,P1,P2,P3) ;
00212         else
00213             DoLine(P3) ;
00214     }
00215 }

void FlattenSplit POINT  P0,
POINT  P1,
POINT  P2,
POINT  P3
 

Definition at line 218 of file gwinding.cpp.

00219 {
00220     POINT L1, L2, M, R1, R2 ;
00221     L1.x = (P0.x + P1.x)/2;
00222     L1.y = (P0.y + P1.y)/2;
00223     L2.x = (P0.x + 2*P1.x + P2.x)/4;
00224     L2.y = (P0.y + 2*P1.y + P2.y)/4;
00225      M.x = (P0.x + 3*P1.x + 3*P2.x + P3.x)/8;
00226      M.y = (P0.y + 3*P1.y + 3*P2.y + P3.y)/8;
00227     R1.x = (P1.x + 2*P2.x + P3.x)/4;
00228     R1.y = (P1.y + 2*P2.y + P3.y)/4;
00229     R2.x = (P2.x + P3.x)/2;
00230     R2.y = (P2.y + P3.y)/2;
00231     FlattenCurve(P0, L1, L2, M) ;
00232     FlattenCurve(M, R1, R2, P3) ;
00233 }

BOOL GWinding PPOINT  pPoints,
PBYTE  Types,
INT32  Length,
UINT32  pFlatness,
UINT32 BottomLeftOffset,
POINT BottomLeft
 

BOOL GWinding( PPOINT pPoints, Path PBYTE Types, UINT32 Length, UINT32 pFlatness, Flatness UINT32 &BottomLeftOffset, Offset to bottom left point. POINT &BottomLeft Bottom left most point. ) ;

This call returns information about the winding of a path. The boolean result indicates a clockwise or anticlockwise winding at the bottom left most point. This point is returned and also the offset to either this point or the offset to the curve that contains this point.

No errors should occur as the path is expected to be in a legal state.

Definition at line 237 of file gwinding.cpp.

00245 {
00246     Flatness = pFlatness*27/2 ;
00247     StartPoint = Points = pPoints ;
00248     BottomLeft = PrevPoint = LastPoint = *Points++ ; Types++ ; --Length ;
00249     BottomLeftOffset = 0 ;
00250     Flags = 03 ;
00251     while ( Length>0 )
00252     {
00253         if ( (*Types & PT_MOVETO)==PT_LINETO )
00254         {
00255             DoLine( Points[0] ) ;
00256             Points++ ; Types++ ; --Length ;
00257         }
00258         else /* Curve */
00259         {
00260             FlattenCurve( Points[-1],Points[0],Points[1],Points[2] ) ;
00261             Points+=3 ; Types+=3 ; Length-=3 ;
00262         }
00263     }
00264     if ( BottomLeft.x!=LastPoint.x || BottomLeft.y!=LastPoint.y )
00265         PrevPoint = LastPoint ;
00266     if ( Flags & 01 )
00267         Prev_Point = PrevPoint ;
00268     else if ( Flags & 02 )
00269         Next_Point = *StartPoint ;
00270     pBottomLeftOffset = BottomLeftOffset ;
00271     pBottomLeft = BottomLeft ;
00272     INT32 Sgn = GWSgnMulSubMul( Next_Point.x-BottomLeft.x, Prev_Point.y-BottomLeft.y,
00273                              Prev_Point.x-BottomLeft.x, Next_Point.y-BottomLeft.y ) ;
00274     if ( Sgn )
00275         return Sgn<0 ;
00276     Sgn = Next_Point.x-Prev_Point.x ;
00277     if ( Sgn )
00278         return Sgn<0 ;
00279     Sgn = Prev_Point.y-Next_Point.y ;
00280     return Sgn<0 ;
00281 }

INT32 GWSgnMulSubMul INT32  A,
INT32  B,
INT32  C,
INT32  D
 

Definition at line 117 of file gwinding.cpp.

00118 {
00119 #if defined(__WXMSW__)
00120     UINT32 temp ;
00121     __asm {
00122         mov     eax,A
00123         imul    B
00124         mov     ebx,eax
00125         mov     ecx,edx
00126         mov     eax,C
00127         imul    D
00128         sub     ebx,eax
00129         sbb     ecx,edx
00130         jne     returnecx
00131         or      ecx,ebx
00132         jns     returnecx
00133             not     ecx
00134 returnecx:
00135         mov     temp,ecx
00136     }
00137     return temp;
00138 #else
00139     XLONG X = (XLONG)A*B-(XLONG)C*D;
00140     return X>0 ? 1 : X<0 ? -1 : 0 ;
00141 #endif
00142 }


Variable Documentation

POINT BottomLeft
 

Definition at line 149 of file gwinding.cpp.

UINT32 BottomLeftOffset
 

Definition at line 160 of file gwinding.cpp.

INT32 Flags
 

Definition at line 157 of file gwinding.cpp.

UINT32 Flatness
 

Definition at line 159 of file gwinding.cpp.

POINT LastPoint
 

Definition at line 151 of file gwinding.cpp.

POINT Next_Point
 

Definition at line 155 of file gwinding.cpp.

POINT OldPoint
 

Definition at line 152 of file gwinding.cpp.

PPOINT Points
 

Definition at line 146 of file gwinding.cpp.

POINT Prev_Point
 

Definition at line 154 of file gwinding.cpp.

POINT PrevPoint
 

Definition at line 150 of file gwinding.cpp.

PPOINT StartPoint
 

Definition at line 147 of file gwinding.cpp.


Generated on Sat Nov 10 03:49:11 2007 for Camelot by  doxygen 1.4.4