Skip to content

Commit

Permalink
Added MinkowskiSum64 & MinkowskiDiff64 to clipper.export.h. (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusJohnson committed May 14, 2024
1 parent f95f4b3 commit efde1c9
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions CPP/Clipper2Lib/include/clipper2/clipper.export.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 14 February 2024 *
* Date : 14 May 2024 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : This module exports the Clipper2 Library (ie DLL/so) *
Expand Down Expand Up @@ -61,7 +61,8 @@ ____________________________________________________________
As mentioned above, the very first CPolyPath structure is just a container
that owns (both directly and indirectly) every other CPolyPath in the tree.
Since this first CPolyPath has no path, instead of a path length, its very
first value will contain the total length of the CPolytree array.
first value will contain the total length of the CPolytree array (not its
total bytes length).
Again, all theses exported structures (CPaths64, CPathsD, CPolyTree64 &
CPolyTreeD) are arrays of either type int64_t or double, and the first
Expand Down Expand Up @@ -272,6 +273,23 @@ CPathsD CreateCPathsDFromPaths64(const Paths64& paths, double scale)
return result;
}

template <typename T>
static Path<T> ConvertCPath(T* path)
{
Path<T> result;
if (!path) return result;
T* v = path;
size_t cnt = static_cast<size_t>(*v);
v += 2; // skip 0 value
path.reserve(cnt);
for (size_t j = 0; j < cnt; ++j)
{
T x = *v++, y = *v++;
path.push_back(Point<T>(x, y));
}
return result;
}

template <typename T>
static Paths<T> ConvertCPaths(T* paths)
{
Expand Down Expand Up @@ -561,6 +579,22 @@ EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
return CreateCPathsDFromPaths64(result, 1 / scale);
}

EXTERN_DLL_EXPORT CPaths64 MinkowskiSum64(const CPath64& cpattern, const CPath64& cpath, bool is_closed)
{
Path64 path = ConvertCPath(cpath);
Path64 pattern = ConvertCPath(cpattern);
Paths64 solution = MinkowskiSum(pattern, path, is_closed);
return CreateCPaths(solution);
}

EXTERN_DLL_EXPORT CPaths64 MinkowskiDiff64(const CPath64& cpattern, const CPath64& cpath, bool is_closed)
{
Path64 path = ConvertCPath(cpath);
Path64 pattern = ConvertCPath(cpattern);
Paths64 solution = MinkowskiDiff(pattern, path, is_closed);
return CreateCPaths(solution);
}

} // end Clipper2Lib namespace

#endif // CLIPPER2_EXPORT_H

0 comments on commit efde1c9

Please sign in to comment.