fuzzclip.cpp File Reference

(r1785/r751)

#include "camtypes.h"
#include "fuzzclip.h"

Go to the source code of this file.

Classes

struct  GRECT

Defines

#define oo   00
#define bl   01
#define br   02
#define tl   03
#define tr   04
#define pp   05
#define ee   06
#define xx   07

Functions

BOOL IsMove (CONST BYTE Type)
BOOL IsntMove (CONST BYTE Type)
BOOL IsLine (CONST BYTE Type)
BOOL IsCurve (CONST BYTE Type)
BOOL IsntCurve (CONST BYTE Type)
void GenLine (INT32 X, INT32 Y, BOOL Merge=TRUE)
void GenCurve (POINT &P1, POINT &P2, POINT &P3)
void GenLine (POINT &P, BOOL F=TRUE)
void GenLineToBelowLeft ()
void GenLineToBelowRight ()
void GenLineToAboveLeft ()
void GenLineToAboveRight ()
INT32 GetSector (POINT &P)
void ClipLine (POINT &Start, POINT &End)
void SplitCurve (POINT &P0, POINT &P1, POINT &P2, POINT &P3)
void ClipCurve (POINT &C0, POINT &C1, POINT &C2, POINT &C3)
size_t FuzzyClip (PPOINT IPoints, PBYTE ITypes, size_t ILength, BOOL IsClosed, RECT *InnerRect, RECT *OuterRect, PPOINT pOPoints, PBYTE pOTypes, size_t pOMaxLength)
 Note that InnerRect should be slightly larger than the window for which the clipping is being performed. This ensures that any slight errors won't be visible at the window edges. Note also that OuterRect must be over 3 times the width of InnerRect, with InnerRect centred within it. No errors should occur as the path is expected to be in a legal state.

Variables

static CONST BYTE CaseTable [25][25]
static CONST DWORD Region [25]
static INT32 LastSector
static GRECTIRect
static GRECTORect
static POINT LastPoint
static PPOINT OPoints
static PBYTE OTypes
static size_t OMaxLength
static size_t OLength
static BOOL OFirstPoint
static UINT32 Index
static UINT32 LastIndex
static BOOL SameLine


Define Documentation

#define bl   01
 

Definition at line 141 of file fuzzclip.cpp.

#define br   02
 

Definition at line 142 of file fuzzclip.cpp.

#define ee   06
 

Definition at line 146 of file fuzzclip.cpp.

#define oo   00
 

Definition at line 140 of file fuzzclip.cpp.

#define pp   05
 

Definition at line 145 of file fuzzclip.cpp.

#define tl   03
 

Definition at line 143 of file fuzzclip.cpp.

#define tr   04
 

Definition at line 144 of file fuzzclip.cpp.

#define xx   07
 

Definition at line 147 of file fuzzclip.cpp.


Function Documentation

void ClipCurve POINT C0,
POINT C1,
POINT C2,
POINT C3
 

Definition at line 390 of file fuzzclip.cpp.

00391 {
00392     INT32 C1Sector  = GetSector( C1 ) ;
00393     INT32 C2Sector  = GetSector( C2 ) ;
00394     INT32 ThisSector    = GetSector( C3 ) ;
00395 //  if ( ( ( C1Sector==LastSector || C1Sector==ThisSector ) &&
00396 //         ( C2Sector==LastSector || C2Sector==ThisSector ) ) ||
00397 //       ( Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector] ) )
00398     INT32 RegionUnion = Region[LastSector] & Region[C1Sector] & Region[C2Sector] & Region[ThisSector];
00399     if ( ( RegionUnion & 0x0ff ) ||
00400          ( (RegionUnion & 0x300) && (LastSector!=ThisSector || LastSector==12) ) ||
00401          ( (C1Sector==LastSector || C1Sector==ThisSector) && (C2Sector==LastSector || C2Sector==ThisSector) ) )
00402     {
00403         switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] )
00404         {
00405         case 01 : GenLineToBelowLeft()  ; break ;
00406         case 02 : GenLineToBelowRight() ; break ;
00407         case 03 : GenLineToAboveLeft()  ; break ;
00408         case 04 : GenLineToAboveRight() ; break ;
00409         case 05 : GenLine(C0,FALSE) ;
00410                   GenCurve(C1,C2,C3)    ; break ;
00411         case 06 : if ( OFirstPoint )
00412                       GenLine(C0,FALSE) ;
00413                   GenCurve(C1,C2,C3)    ; break ;
00414         case 07 : SplitCurve(C0,C1,C2,C3) ; return ;
00415         case 10 : GenLineToBelowLeft()  ; GenLineToBelowRight() ; break ;
00416         case 11 : GenLineToBelowLeft()  ; GenLineToAboveLeft()  ; break ;
00417         case 12 : GenLineToBelowRight() ; GenLineToAboveRight() ; break ;
00418         case 13 : GenLineToBelowRight() ; GenLineToBelowLeft()  ; break ;
00419         case 14 : GenLineToAboveLeft()  ; GenLineToAboveRight() ; break ;
00420         case 15 : GenLineToAboveLeft()  ; GenLineToBelowLeft()  ; break ;
00421         case 16 : GenLineToAboveRight() ; GenLineToBelowRight() ; break ;
00422         case 17 : GenLineToAboveRight() ; GenLineToAboveLeft()  ; break ;
00423         }
00424         LastSector = ThisSector ;
00425     }
00426     else
00427         SplitCurve(C0,C1,C2,C3) ;
00428 }

void ClipLine POINT Start,
POINT End
 

Definition at line 352 of file fuzzclip.cpp.

00353 {
00354     INT32 ThisSector = GetSector( End ) ;
00355     switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] )
00356     {
00357     case 01 : GenLineToBelowLeft()  ; break ;
00358     case 02 : GenLineToBelowRight() ; break ;
00359     case 03 : GenLineToAboveLeft()  ; break ;
00360     case 04 : GenLineToAboveRight() ; break ;
00361     case 05 : GenLine(Start)        ;
00362               GenLine(End)          ; break ;
00363     case 06 : if ( OFirstPoint )
00364                   GenLine(Start) ;
00365               GenLine(End)          ; break ;
00366     case 07 :
00367         POINT Middle ;
00368         Middle.x = (Start.x+End.x) >> 1 ;
00369         Middle.y = (Start.y+End.y) >> 1 ;
00370         ClipLine( Start,Middle ) ;
00371         ClipLine( Middle,End ) ;
00372         return ;
00373     case 10 : GenLineToBelowLeft()  ; GenLineToBelowRight() ; break ;
00374     case 11 : GenLineToBelowLeft()  ; GenLineToAboveLeft()  ; break ;
00375     case 12 : GenLineToBelowRight() ; GenLineToAboveRight() ; break ;
00376     case 13 : GenLineToBelowRight() ; GenLineToBelowLeft()  ; break ;
00377     case 14 : GenLineToAboveLeft()  ; GenLineToAboveRight() ; break ;
00378     case 15 : GenLineToAboveLeft()  ; GenLineToBelowLeft()  ; break ;
00379     case 16 : GenLineToAboveRight() ; GenLineToBelowRight() ; break ;
00380     case 17 : GenLineToAboveRight() ; GenLineToAboveLeft()  ; break ;
00381     }
00382     LastSector = ThisSector ;
00383 }

size_t FuzzyClip PPOINT  IPoints,
PBYTE  ITypes,
size_t  ILength,
BOOL  IsClosed,
RECT InnerRect,
RECT OuterRect,
PPOINT  pOPoints,
PBYTE  pOTypes,
size_t  pOMaxLength
 

Note that InnerRect should be slightly larger than the window for which the clipping is being performed. This ensures that any slight errors won't be visible at the window edges. Note also that OuterRect must be over 3 times the width of InnerRect, with InnerRect centred within it. No errors should occur as the path is expected to be in a legal state.

Parameters:
IPoints,ITypes,ILength - Source path [INPUTS] IsClosed - Source path and output path should be closed. InnerRect - Inner rectangle to which to clip. OuterRect - Outer rectangle to which to clip.
pOPoints,pOTypes - Outut path. [OUTPUTS] pOMaxLength - Maximum length of output path.
Returns:
Returns the length of the path, or -1 if an error occurs. (ie output path not large enough).

Definition at line 450 of file fuzzclip.cpp.

00461 {
00462     IRect       = (GRECT*) InnerRect ;
00463     ORect       = (GRECT*) OuterRect ;
00464     OPoints     = pOPoints ;
00465     OTypes      = pOTypes ;
00466     OMaxLength  = pOMaxLength ;
00467     OLength     = 0 ;
00468 
00469     if ( ILength <= 0 )
00470         return 0 ;
00471 
00472     try {
00473 
00474         Index = 0 ;
00475         while ( Index<ILength )
00476         {
00477             OFirstPoint = TRUE ;
00478             POINT StartPoint = IPoints[Index++] ;
00479             LastSector = GetSector( StartPoint ) ;
00480             LastPoint = StartPoint ;
00481             while ( Index<ILength && (IsLine(ITypes[Index]) || IsCurve(ITypes[Index])) )
00482             {
00483                 if ( IsLine(ITypes[Index]) )
00484                 {
00485                     ClipLine( LastPoint,IPoints[Index] ) ;
00486                     LastPoint = IPoints[Index++] ;
00487                 }
00488                 else
00489                 {
00490                     ClipCurve( LastPoint,IPoints[Index],IPoints[Index+1],IPoints[Index+2] ) ;
00491                     LastPoint = IPoints[Index+2] ;
00492                     Index += 3 ;
00493                 }
00494             }
00495             if ( IsClosed || (ITypes[Index-1] & PT_CLOSEFIGURE) )
00496             {
00497                 ClipLine( LastPoint,StartPoint ) ;
00498                 if ( !OFirstPoint )
00499                     *(OTypes-1) |= PT_CLOSEFIGURE ;
00500             }
00501             if ( !OFirstPoint && IsMove(*(OTypes-1)) )
00502             {
00503                 OTypes-- ;
00504                 OPoints-- ;
00505                 OLength-- ;
00506             }
00507         }
00508 
00509     } catch ( INT32 ) {
00510         OLength = (size_t)-1 ;
00511     }
00512 
00513     return OLength ;
00514 }

void GenCurve POINT P1,
POINT P2,
POINT P3
 

Definition at line 282 of file fuzzclip.cpp.

00283 {
00284     if ( (OLength+=3) > OMaxLength )
00285         throw 1 ;
00286     *OTypes++ = PT_BEZIERTO ; *OPoints++ = P1 ;
00287     *OTypes++ = PT_BEZIERTO ; *OPoints++ = P2 ;
00288     *OTypes++ = PT_BEZIERTO ; *OPoints++ = P3 ;
00289     SameLine = FALSE ;
00290     LastIndex = INT32_MAX ;
00291 }

void GenLine POINT P,
BOOL  F = TRUE
[inline]
 

Definition at line 294 of file fuzzclip.cpp.

00294 { GenLine( P.x,P.y,F ) ; } ;

void GenLine INT32  X,
INT32  Y,
BOOL  Merge = TRUE
 

Definition at line 248 of file fuzzclip.cpp.

00249 {
00250     if ( OFirstPoint )
00251     {
00252         OFirstPoint = FALSE ;
00253         if ( ++OLength > OMaxLength )
00254             throw 1 ;
00255         *OTypes++ = PT_MOVETO ;
00256         OPoints->x = X ;
00257         OPoints->y = Y ;
00258         OPoints++ ;
00259         SameLine = FALSE ;
00260         LastIndex = Merge?Index:INT32_MAX ;
00261     }
00262     else if ( Merge && SameLine && LastIndex==Index )
00263     {
00264         (OPoints-1)->x = X ;
00265         (OPoints-1)->y = Y ;
00266     }
00267     else if ( (OPoints-1)->x != X ||
00268               (OPoints-1)->y != Y )
00269     {
00270         if ( ++OLength > OMaxLength )
00271             throw 1 ;
00272         *OTypes++ = PT_LINETO ;
00273         OPoints->x = X ;
00274         OPoints->y = Y ;
00275         OPoints++ ;
00276         SameLine = Merge && (LastIndex==Index) ;
00277         LastIndex = Merge?Index:INT32_MAX ;
00278     }
00279 }

void GenLineToAboveLeft  )  [inline]
 

Definition at line 299 of file fuzzclip.cpp.

00299 { GenLine( IRect->lx,IRect->hy,FALSE ) ; } ;

void GenLineToAboveRight  )  [inline]
 

Definition at line 300 of file fuzzclip.cpp.

00300 { GenLine( IRect->hx,IRect->hy,FALSE ) ; } ;

void GenLineToBelowLeft  )  [inline]
 

Definition at line 297 of file fuzzclip.cpp.

00297 { GenLine( IRect->lx,IRect->ly,FALSE ) ; } ;

void GenLineToBelowRight  )  [inline]
 

Definition at line 298 of file fuzzclip.cpp.

00298 { GenLine( IRect->hx,IRect->ly,FALSE ) ; } ;

INT32 GetSector POINT P  ) 
 

Definition at line 324 of file fuzzclip.cpp.

00325 {
00326     INT32 Sector = 12 ;
00327     if ( P.x < IRect->lx )
00328         if ( P.x < ORect->lx )
00329             Sector -= 2 ;
00330         else
00331             Sector-- ;
00332     else if ( P.x > IRect->hx )
00333         if ( P.x > ORect->hx )
00334             Sector += 2 ;
00335         else
00336             Sector++ ;
00337     if ( P.y < IRect->ly )
00338         if ( P.y < ORect->ly )
00339             Sector -= 2*5 ;
00340         else
00341             Sector -= 5 ;
00342     else if ( P.y > IRect->hy )
00343         if ( P.y > ORect->hy )
00344             Sector += 2*5 ;
00345         else
00346             Sector += 5 ;
00347     return Sector ;
00348 }

BOOL IsCurve CONST BYTE  Type  )  [inline]
 

Definition at line 233 of file fuzzclip.cpp.

00234 {
00235     return (Type & PT_MOVETO)==PT_BEZIERTO ;
00236 }

BOOL IsLine CONST BYTE  Type  )  [inline]
 

Definition at line 228 of file fuzzclip.cpp.

00229 {
00230     return (Type & PT_MOVETO)==PT_LINETO ;
00231 }

BOOL IsMove CONST BYTE  Type  )  [inline]
 

Definition at line 218 of file fuzzclip.cpp.

00219 {
00220     return (Type & PT_MOVETO)==PT_MOVETO ;
00221 }

BOOL IsntCurve CONST BYTE  Type  )  [inline]
 

Definition at line 238 of file fuzzclip.cpp.

00239 {
00240     return (Type & PT_MOVETO)!=PT_BEZIERTO ;
00241 }

BOOL IsntMove CONST BYTE  Type  )  [inline]
 

Definition at line 223 of file fuzzclip.cpp.

00224 {
00225     return (Type & PT_MOVETO)!=PT_MOVETO ;
00226 }

void SplitCurve POINT P0,
POINT P1,
POINT P2,
POINT P3
 

Definition at line 431 of file fuzzclip.cpp.

00432 {
00433     POINT L1, L2, M, R1, R2 ;
00434     L1.x = (P0.x + P1.x)/2;
00435     L1.y = (P0.y + P1.y)/2;
00436     L2.x = (P0.x + 2*P1.x + P2.x)/4;
00437     L2.y = (P0.y + 2*P1.y + P2.y)/4;
00438      M.x = (P0.x + 3*P1.x + 3*P2.x + P3.x)/8;
00439      M.y = (P0.y + 3*P1.y + 3*P2.y + P3.y)/8;
00440     R1.x = (P1.x + 2*P2.x + P3.x)/4;
00441     R1.y = (P1.y + 2*P2.y + P3.y)/4;
00442     R2.x = (P2.x + P3.x)/2;
00443     R2.y = (P2.y + P3.y)/2;
00444     ClipCurve( P0,L1,L2, M ) ;
00445     ClipCurve(  M,R1,R2,P3 ) ;
00446 }


Variable Documentation

CONST BYTE CaseTable[25][25] [static]
 

Definition at line 149 of file fuzzclip.cpp.

UINT32 Index [static]
 

Definition at line 212 of file fuzzclip.cpp.

GRECT* IRect [static]
 

Definition at line 201 of file fuzzclip.cpp.

UINT32 LastIndex [static]
 

Definition at line 213 of file fuzzclip.cpp.

POINT LastPoint [static]
 

Definition at line 204 of file fuzzclip.cpp.

INT32 LastSector [static]
 

Definition at line 199 of file fuzzclip.cpp.

BOOL OFirstPoint [static]
 

Definition at line 210 of file fuzzclip.cpp.

size_t OLength [static]
 

Definition at line 209 of file fuzzclip.cpp.

size_t OMaxLength [static]
 

Definition at line 208 of file fuzzclip.cpp.

PPOINT OPoints [static]
 

Definition at line 206 of file fuzzclip.cpp.

GRECT* ORect [static]
 

Definition at line 202 of file fuzzclip.cpp.

PBYTE OTypes [static]
 

Definition at line 207 of file fuzzclip.cpp.

CONST DWORD Region[25] [static]
 

Initial value:

 {
    0x003,0x001,0x001,0x001,0x005,
    0x002,0x030,0x110,0x050,0x004,
    0x002,0x220,0x300,0x240,0x004,
    0x002,0x0a0,0x180,0x0c0,0x004,
    0x00a,0x008,0x008,0x008,0x00c
}

Definition at line 191 of file fuzzclip.cpp.

BOOL SameLine [static]
 

Definition at line 214 of file fuzzclip.cpp.


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