// How to process Windows Region Data
//#include "CheckInc.h"
#include "windows.h"
typedef struct _tag_DSCR_PNT
{
  long x;
  long iFrom;
  long iTo;
  bool bRightFrom;
  bool bRightTo;
  bool bProc;
} DSCR_INP_PNT;

typedef struct _tag_DSCR_SEGMENT
{
  long y;
  DSCR_INP_PNT pntL;
  DSCR_INP_PNT pntR;
} DSCR_SEGMENT;

typedef struct _tag_DSCR_START
{
  long iDscr;
  bool bRight;
} DSCR_START;

typedef struct _tag_DSCR_POLY
{
  long nmbPnt;
  long indPnt;
} DSCR_POLY;

typedef struct _tag_DSCR_POINT
{
  long x;
  long y;
  long iNext;
  long iPrev;
} DSCR_OUT_PNT;

typedef struct _tag_POLY_INFO
{
  POINT min;
  POINT max;
  int nmbYmax;
  bool bExtrn;
  bool bCollap;
  int nmbHoles;
  bool bProc;
  int nxtExt;
  int nxtInt;
  int iBegPnt;
} POLY_INFO;

typedef enum
{
  PNT_MAIN    = 1,
  PNT_DELETED = 2,
} MSK_PNT;

typedef enum
{
  CRS_LEFT_LESS_RIGHT_LESS,
  CRS_LEFT_LESS_RIGHT_INSIDE,
  CRS_LEFT_LESS_RIGHT_MORE,
  CRS_LEFT_INSIDE_RIGHT_MORE,
  CRS_LEFT_MORE_RIGHT_MORE,
  CRS_LEFT_INSIDE_RIGHT_INSIDE,
} TYPE_CROSSES;

typedef enum
{
  SCAN_EMPTY,
  SCAN_FIRST_LINE,
  SCAN_OTHER_LINES,
} SOST_SCAN; 

class CRastrTool
{
public:
  CRastrTool();
  ~CRastrTool();
  void NewLine() { m_bNewLine = true; }
  bool Split();
  bool AddDscrSeg(long Y, long xLeft, long xRight);
  bool GetPolyPolygon(int *pPolys, int **ppListPoly, long **ppListXYCoords, int *pTotalCoords);
  void Reset();

private:
  static TYPE_CROSSES GetTypeCrs(long x1, long y1, long x2, long y2);
  void ProcScan();
  void AddStart(long iDscr, bool bRight); // For left side of cuts
  bool TryToDelete(long iPnt);
  long AddPoly();
  long AddPoint(long x, long y, long iPrev);
  void AddPoint(long iPnt);

  static bool CalcDirect(long x1, long y1, long x2, long y2, long x3, long y3);

  SOST_SCAN m_sostScan;
  bool m_bNewLine;
  DSCR_SEGMENT *m_pDscrSeg;
  long m_nmbDscrSeg;
  long m_iBegDscr1;
  long m_iBegDscr2;
  long m_iBegDscr3;
  DSCR_START *m_pStarts;
  int m_nmbStarts;
  DSCR_OUT_PNT *m_pPoints;
  int m_nmbPoints;
  DSCR_POLY *m_pPolys;
  int m_nmbPolys;
  long *m_pOutPnt;
  int *m_pOutPolys;
  POLY_INFO *m_pInfoPolyList;
};
bool  RgnData2Poly (LPRGNDATA pRgnData, CRastrTool *pRastrTool);