|
|
/************************************************************************
|
|
|
* Author : wcw
|
|
|
* Version : 1.0
|
|
|
* Date : 23 April 2015
|
|
|
* Description: 管理clipper.h中的类,提供外部运算接口
|
|
|
/************************************************************************/
|
|
|
|
|
|
#pragma once
|
|
|
//#include "clipper.h"
|
|
|
|
|
|
class Polygons;
|
|
|
#include <vector>
|
|
|
|
|
|
namespace NClipperLib
|
|
|
{
|
|
|
|
|
|
//布尔运算模式
|
|
|
enum EClipType
|
|
|
{
|
|
|
ectIntersection,
|
|
|
ectUnion,
|
|
|
ectDifference,
|
|
|
ectXor
|
|
|
};
|
|
|
|
|
|
////多边形类型
|
|
|
//enum EPolyType { eptSubject, eptClip };
|
|
|
|
|
|
struct ClipperPoint
|
|
|
{
|
|
|
double x;
|
|
|
double y;
|
|
|
ClipperPoint(){ }
|
|
|
ClipperPoint(double x0,double y0){ x = x0; y = y0;}
|
|
|
};
|
|
|
|
|
|
typedef std::vector<ClipperPoint> ClipperPolygon;
|
|
|
typedef std::vector<ClipperPolygon> ClipperPolygons;
|
|
|
|
|
|
class AFX_EXT_CLASS CClipperHandler
|
|
|
{
|
|
|
public:
|
|
|
CClipperHandler(void);
|
|
|
CClipperHandler(unsigned int n_Prec);
|
|
|
~CClipperHandler(void);
|
|
|
|
|
|
/** @brief 多边形进行布尔运算,结果输入到solution中,eType为运算模式,相交,合并,相减,异或(exclusive or)*/
|
|
|
bool Execute(ClipperPolygons& pPolySubject, ClipperPolygons& pPolyClip, ClipperPolygons& pPolySolution, EClipType eType);
|
|
|
/** @brief 设置精度,即精确到小数点后多少位 */
|
|
|
void SetPrecison(unsigned int nPrec);
|
|
|
/** @brief 获取当前精度*/
|
|
|
int GetPrecison(void) {return m_nPrec; }
|
|
|
|
|
|
/** @获取多边形集最小坐标,失败返回false*/
|
|
|
bool GetMinimumValue(ClipperPolygons& sourcePolygons, double& xmin, double& ymin );
|
|
|
/** @获取多边形集最大坐标,失败返回false*/
|
|
|
bool GetMaximumValue(ClipperPolygons& sourcePolygons, double& xmax, double& ymax );
|
|
|
|
|
|
private:
|
|
|
/** @brief 将ClipperPolygongs多边形集拷贝到目标多边形中,考虑偏移参数和精度 */
|
|
|
bool ClipPolysToPolygons(ClipperPolygons* pSourcePolygons, Polygons* pDestPolygons);
|
|
|
bool PolygonToClipPolys(Polygons* pSourcePolygons, ClipperPolygons* pDestPolygons);
|
|
|
|
|
|
/** @brief 内部执行*/
|
|
|
//bool Execute()
|
|
|
|
|
|
/** @breif 由输入的多边形数据获取内部运算参数 */
|
|
|
bool GetOperationParas();
|
|
|
|
|
|
ClipperPolygons* m_pSubject;
|
|
|
ClipperPolygons* m_pClip;
|
|
|
|
|
|
unsigned int m_nPrec; //精度,表示精确到小数点后的位数 缺省为8
|
|
|
double m_dXOffset;//x方向偏移量
|
|
|
double m_dYOffset;//y方向偏移量
|
|
|
//int m_nXInitOffset; //X初始偏移量
|
|
|
//long64 m_nXScaleOffset; //X放大后偏移量
|
|
|
//int m_nYInitOffset; //Y初始偏移量
|
|
|
//long64 m_nYScaleOffset; //Y放大后偏移量
|
|
|
|
|
|
//double m_dScale ; // 放大比例
|
|
|
//double m_dXOffset; // X偏移量
|
|
|
//double m_dYOffset; // y偏移量
|
|
|
};
|
|
|
|
|
|
} //namespace
|
|
|
|