@@ -57,9 +57,6 @@ typedef int64_t** CPaths64;
5757typedef double * CPathD;
5858typedef double ** CPathsD;
5959
60- typedef struct CRect64 { int64_t val[4 ]; } CRect64;
61- typedef struct CRectD { double val[4 ]; } CRectD;
62-
6360typedef struct CPolyPath64 {
6461 CPath64 polygon;
6562 uint32_t is_hole;
@@ -76,6 +73,34 @@ typedef struct CPolyPathD {
7673}
7774CPolyTreeD;
7875
76+ template <typename T>
77+ struct CRect {
78+ T left;
79+ T top;
80+ T right;
81+ T bottom;
82+ };
83+
84+ typedef CRect<int64_t > CRect64;
85+ typedef CRect<double > CRectD;
86+
87+ template <typename T>
88+ inline bool CRectIsEmpty (const CRect<T>& rect)
89+ {
90+ return (rect.right <= rect.left ) || (rect.bottom <= rect.top );
91+ }
92+
93+ template <typename T>
94+ inline Rect<T> CRectToRect (const CRect<T>& rect)
95+ {
96+ Rect<T> result;
97+ result.left = rect.left ;
98+ result.top = rect.top ;
99+ result.right = rect.right ;
100+ result.bottom = rect.bottom ;
101+ return result;
102+ }
103+
79104inline CPath64 CreateCPath64 (size_t cnt1, size_t cnt2);
80105inline CPath64 CreateCPath64 (const Path64& p);
81106inline CPaths64 CreateCPaths64 (const Paths64& pp);
@@ -99,6 +124,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale);
99124
100125#define EXTERN_DLL_EXPORT extern " C" __declspec(dllexport)
101126
127+
102128EXTERN_DLL_EXPORT const char * Version ()
103129{
104130 return CLIPPER2_VERSION;
@@ -258,7 +284,7 @@ EXTERN_DLL_EXPORT int BooleanOpPtD(uint8_t cliptype,
258284 return 0 ;
259285}
260286
261- EXTERN_DLL_EXPORT CPaths64 InflatePaths64 (const CPaths64 paths,
287+ EXTERN_DLL_EXPORT CPaths64 InflatePaths64 (const CPaths64 paths,
262288 double delta, uint8_t jt, uint8_t et, double miter_limit = 2.0 ,
263289 double arc_tolerance = 0.0 , bool reverse_solution = false )
264290{
@@ -272,7 +298,7 @@ EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
272298 return CreateCPaths64 (result);
273299}
274300
275- EXTERN_DLL_EXPORT CPathsD InflatePathsD (const CPathsD paths,
301+ EXTERN_DLL_EXPORT CPathsD InflatePathsD (const CPathsD paths,
276302 double delta, uint8_t jt, uint8_t et,
277303 double precision = 2 , double miter_limit = 2.0 ,
278304 double arc_tolerance = 0.0 , bool reverse_solution = false )
@@ -286,20 +312,23 @@ EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
286312 return CreateCPathsD (result, 1 /scale);
287313}
288314
289- EXTERN_DLL_EXPORT CPaths64 RectClip64 (const Rect64 rect,
315+ EXTERN_DLL_EXPORT CPaths64 RectClip64 (const CRect64& rect,
290316 const CPaths64 paths)
291317{
292- if (rect.IsEmpty () || !paths) return nullptr ;
293- class RectClip rc (rect);
318+ log (rect.left );
319+ log (rect.right );
320+ if (CRectIsEmpty (rect) || !paths) return nullptr ;
321+ Rect64 r64 = CRectToRect (rect);
322+ class RectClip rc (r64);
294323 Paths64 pp = ConvertCPaths64 (paths);
295324 Paths64 result;
296325 result.reserve (pp.size ());
297326 for (const Path64& p : pp)
298327 {
299328 Rect64 pathRec = Bounds (p);
300- if (!rect .Intersects (pathRec)) continue ;
329+ if (!r64 .Intersects (pathRec)) continue ;
301330
302- if (rect .Contains (pathRec))
331+ if (r64 .Contains (pathRec))
303332 result.push_back (p);
304333 else
305334 {
@@ -310,15 +339,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClip64(const Rect64 rect,
310339 return CreateCPaths64 (result);
311340}
312341
313- EXTERN_DLL_EXPORT CPathsD RectClipD (const RectD rect,
342+ EXTERN_DLL_EXPORT CPathsD RectClipD (const CRectD& rect,
314343 const CPathsD paths, int precision = 2 )
315344{
316- if (rect. IsEmpty ( ) || !paths) return nullptr ;
345+ if (CRectIsEmpty (rect ) || !paths) return nullptr ;
317346 if (precision < -8 || precision > 8 ) return nullptr ;
318347 const double scale = std::pow (10 , precision);
319- Rect64 r = ScaleRect<int64_t , double >(rect, scale);
348+ Rect64 r = ScaleRect<int64_t , double >(CRectToRect ( rect) , scale);
320349 Paths64 pp = ConvertCPathsD (paths, scale);
321-
322350 class RectClip rc (r);
323351 Paths64 result;
324352 result.reserve (pp.size ());
@@ -338,21 +366,22 @@ EXTERN_DLL_EXPORT CPathsD RectClipD(const RectD rect,
338366 return CreateCPathsD (result, 1 /scale);
339367}
340368
341- EXTERN_DLL_EXPORT CPaths64 RectClipLines64 (const Rect64 rect,
369+ EXTERN_DLL_EXPORT CPaths64 RectClipLines64 (const CRect64& rect,
342370 const CPaths64 paths)
343371{
344- if (rect.IsEmpty () || !paths) return nullptr ;
345- class RectClipLines rcl (rect);
372+ if (CRectIsEmpty (rect) || !paths) return nullptr ;
373+ Rect64 r = CRectToRect (rect);
374+ class RectClipLines rcl (r);
346375 Paths64 pp = ConvertCPaths64 (paths);
347376 Paths64 result;
348377 result.reserve (pp.size ());
349378
350379 for (const Path64& p : pp)
351380 {
352381 Rect64 pathRec = Bounds (p);
353- if (!rect .Intersects (pathRec)) continue ;
382+ if (!r .Intersects (pathRec)) continue ;
354383
355- if (rect .Contains (pathRec))
384+ if (r .Contains (pathRec))
356385 result.push_back (p);
357386 else
358387 {
@@ -364,14 +393,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const Rect64 rect,
364393 return CreateCPaths64 (result);
365394}
366395
367- EXTERN_DLL_EXPORT CPathsD RectClipLinesD (const RectD rect,
396+ EXTERN_DLL_EXPORT CPathsD RectClipLinesD (const CRectD& rect,
368397 const CPathsD paths, int precision = 2 )
369398{
370399 Paths64 result;
371- if (rect. IsEmpty ( ) || !paths) return nullptr ;
400+ if (CRectIsEmpty (rect ) || !paths) return nullptr ;
372401 if (precision < -8 || precision > 8 ) return nullptr ;
373402 const double scale = std::pow (10 , precision);
374- Rect64 r = ScaleRect<int64_t , double >(rect, scale);
403+ Rect64 r = ScaleRect<int64_t , double >(CRectToRect ( rect) , scale);
375404 class RectClipLines rcl (r);
376405 Paths64 pp = ConvertCPathsD (paths, scale);
377406
@@ -692,7 +721,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale)
692721 result->polygon = nullptr ;
693722 result->is_hole = false ;
694723 size_t child_cnt = pt.Count ();
695- result->child_count = child_cnt;
724+ result->child_count = static_cast < uint32_t >( child_cnt) ;
696725 result->childs = nullptr ;
697726 if (!child_cnt) return result;
698727 result->childs = new CPolyPathD[child_cnt];
0 commit comments