Skip to content

Commit

Permalink
Clipper2 1.5.2 (#2360)
Browse files Browse the repository at this point in the history
Clipper2_1.5.2

Changes (since Ver 1.5.0)
CPP: tidied file header includes (#940)
CPP: emplace_back() replaces many push_back() (#939)
Fixed typos and broken links (#936)
  • Loading branch information
aismann authored Feb 1, 2025
1 parent 7990ec8 commit cbdef87
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 171 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

## Clipper2
- [![Upstream](https://img.shields.io/github/v/tag/AngusJohnson/Clipper2?label=Upstream)](https://github.com/AngusJohnson/Clipper2)
- Version: 1.5.0
- Version: 1.5.2
- License: BSL-1.0

## ConcurrentQueue
Expand Down
27 changes: 12 additions & 15 deletions 3rdparty/clipper2/include/clipper2/clipper.core.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 12 May 2024 *
* Website : http://www.angusj.com *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : Core Clipper Library structures and functions *
* License : http://www.boost.org/LICENSE_1_0.txt *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/

#ifndef CLIPPER_CORE_H
#define CLIPPER_CORE_H

#include "clipper2/clipper.version.h"
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <optional>
#include "clipper2/clipper.version.h"
#include <cmath>

namespace Clipper2Lib
{
Expand Down Expand Up @@ -331,10 +328,10 @@ namespace Clipper2Lib
{
Path<T> result;
result.reserve(4);
result.push_back(Point<T>(left, top));
result.push_back(Point<T>(right, top));
result.push_back(Point<T>(right, bottom));
result.push_back(Point<T>(left, bottom));
result.emplace_back(left, top);
result.emplace_back(right, top);
result.emplace_back(right, bottom);
result.emplace_back(left, bottom);
return result;
}

Expand Down Expand Up @@ -618,13 +615,13 @@ namespace Clipper2Lib
result.reserve(path.size());
typename Path<T>::const_iterator path_iter = path.cbegin();
Point<T> first_pt = *path_iter++, last_pt = first_pt;
result.push_back(first_pt);
result.emplace_back(first_pt);
for (; path_iter != path.cend(); ++path_iter)
{
if (!NearEqual(*path_iter, last_pt, max_dist_sqrd))
{
last_pt = *path_iter;
result.push_back(last_pt);
result.emplace_back(last_pt);
}
}
if (!is_closed_path) return result;
Expand All @@ -642,7 +639,7 @@ namespace Clipper2Lib
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
paths_citer != paths.cend(); ++paths_citer)
{
result.push_back(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path));
result.emplace_back(std::move(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path)));
}
return result;
}
Expand Down Expand Up @@ -787,7 +784,7 @@ namespace Clipper2Lib
const Point<T>& line1, const Point<T>& line2)
{
//perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²)
//see http://en.wikipedia.org/wiki/Perpendicular_distance
//see https://en.wikipedia.org/wiki/Perpendicular_distance
double a = static_cast<double>(pt.x - line1.x);
double b = static_cast<double>(pt.y - line1.y);
double c = static_cast<double>(line2.x - line1.x);
Expand Down
12 changes: 3 additions & 9 deletions 3rdparty/clipper2/include/clipper2/clipper.engine.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 17 September 2024 *
* Website : http://www.angusj.com *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : This is the main polygon clipping module *
* License : http://www.boost.org/LICENSE_1_0.txt *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/

#ifndef CLIPPER_ENGINE_H
#define CLIPPER_ENGINE_H

#include <cstdlib>
#include <stdint.h> //#541
#include <iostream>
#include "clipper2/clipper.core.h"
#include <queue>
#include <vector>
#include <functional>
#include <numeric>
#include <memory>

#include "clipper2/clipper.core.h"

namespace Clipper2Lib {

struct Scanline;
Expand Down
29 changes: 14 additions & 15 deletions 3rdparty/clipper2/include/clipper2/clipper.export.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 24 January 2025 *
* Website : http://www.angusj.com *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2025 *
* Purpose : This module exports the Clipper2 Library (ie DLL/so) *
* License : http://www.boost.org/LICENSE_1_0.txt *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/


Expand Down Expand Up @@ -53,7 +53,7 @@ _______________________________________________________________
CPaths64 and CPathsD:
These are also arrays of either int64_t or double values that
contain any number of consecutive CPath structures. However,
preceeding the first path is a pair of values. The first value
preceding the first path is a pair of values. The first value
contains the length of the entire array structure (A), and the
second contains the number (ie count) of contained paths (C).
Memory allocation for CPaths64 = A * sizeof(int64_t)
Expand Down Expand Up @@ -112,12 +112,11 @@ the four vertices that define the two segments that are intersecting.
#ifndef CLIPPER2_EXPORT_H
#define CLIPPER2_EXPORT_H

#include <cstdlib>
#include <vector>
#include "clipper2/clipper.core.h"
#include "clipper2/clipper.engine.h"
#include "clipper2/clipper.offset.h"
#include "clipper2/clipper.rectclip.h"
#include <cstdlib>

namespace Clipper2Lib {

Expand Down Expand Up @@ -392,9 +391,9 @@ static Path<T> ConvertCPathToPathT(T* path)
T x = *v++, y = *v++;
#ifdef USINGZ
z_type z = Reinterpret<z_type>(*v++);
result.push_back(Point<T>(x, y, z));
result.emplace_back(x, y, z);
#else
result.push_back(Point<T>(x, y));
result.emplace_back(x, y);
#endif
}
return result;
Expand All @@ -419,12 +418,12 @@ static Paths<T> ConvertCPathsToPathsT(T* paths)
T x = *v++, y = *v++;
#ifdef USINGZ
z_type z = Reinterpret<z_type>(*v++);
path.push_back(Point<T>(x, y, z));
path.emplace_back(x, y, z);
#else
path.push_back(Point<T>(x, y));
path.emplace_back(x, y);
#endif
}
result.push_back(path);
result.emplace_back(std::move(path));
}
return result;
}
Expand All @@ -443,9 +442,9 @@ static Path64 ConvertCPathDToPath64WithScale(const CPathD path, double scale)
double y = *v++ * scale;
#ifdef USINGZ
z_type z = Reinterpret<z_type>(*v++);
result.push_back(Point64(x, y, z));
result.emplace_back(x, y, z);
#else
result.push_back(Point64(x, y));
result.emplace_back(x, y);
#endif
}
return result;
Expand All @@ -471,12 +470,12 @@ static Paths64 ConvertCPathsDToPaths64(const CPathsD paths, double scale)
double y = *v++ * scale;
#ifdef USINGZ
z_type z = Reinterpret<z_type>(*v++);
path.push_back(Point64(x, y, z));
path.emplace_back(x, y, z);
#else
path.push_back(Point64(x, y));
path.emplace_back(x, y);
#endif
}
result.push_back(path);
result.emplace_back(std::move(path));
}
return result;
}
Expand Down
35 changes: 16 additions & 19 deletions 3rdparty/clipper2/include/clipper2/clipper.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 27 April 2024 *
* Website : http://www.angusj.com *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : This module provides a simple interface to the Clipper Library *
* License : http://www.boost.org/LICENSE_1_0.txt *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/

#ifndef CLIPPER_H
#define CLIPPER_H

#include <cstdlib>
#include <type_traits>
#include <vector>

#include "clipper2/clipper.core.h"
#include "clipper2/clipper.engine.h"
#include "clipper2/clipper.offset.h"
#include "clipper2/clipper.minkowski.h"
#include "clipper2/clipper.rectclip.h"
#include <type_traits>

namespace Clipper2Lib {

Expand Down Expand Up @@ -272,14 +269,14 @@ namespace Clipper2Lib {

inline void PolyPathToPaths64(const PolyPath64& polypath, Paths64& paths)
{
paths.push_back(polypath.Polygon());
paths.emplace_back(polypath.Polygon());
for (const auto& child : polypath)
PolyPathToPaths64(*child, paths);
}

inline void PolyPathToPathsD(const PolyPathD& polypath, PathsD& paths)
{
paths.push_back(polypath.Polygon());
paths.emplace_back(polypath.Polygon());
for (const auto& child : polypath)
PolyPathToPathsD(*child, paths);
}
Expand Down Expand Up @@ -348,9 +345,9 @@ namespace Clipper2Lib {
result.reserve(array_size / 2);
for (size_t i = 0; i < array_size; i +=2)
#ifdef USINGZ
result.push_back( U{ an_array[i], an_array[i + 1], 0} );
result.emplace_back( an_array[i], an_array[i + 1], 0 );
#else
result.push_back( U{ an_array[i], an_array[i + 1]} );
result.emplace_back( an_array[i], an_array[i + 1] );
#endif
}

Expand Down Expand Up @@ -518,20 +515,20 @@ namespace Clipper2Lib {
}

prevIt = srcIt++;
dst.push_back(*prevIt);
dst.emplace_back(*prevIt);
for (; srcIt != stop; ++srcIt)
{
if (!IsCollinear(*prevIt, *srcIt, *(srcIt + 1)))
{
prevIt = srcIt;
dst.push_back(*prevIt);
dst.emplace_back(*prevIt);
}
}

if (is_open_path)
dst.push_back(*srcIt);
dst.emplace_back(*srcIt);
else if (!IsCollinear(*prevIt, *stop, dst[0]))
dst.push_back(*stop);
dst.emplace_back(*stop);
else
{
while (dst.size() > 2 &&
Expand Down Expand Up @@ -603,10 +600,10 @@ namespace Clipper2Lib {
double dx = co, dy = si;
Path<T> result;
result.reserve(steps);
result.push_back(Point<T>(center.x + radiusX, static_cast<double>(center.y)));
result.emplace_back(center.x + radiusX, static_cast<double>(center.y));
for (size_t i = 1; i < steps; ++i)
{
result.push_back(Point<T>(center.x + radiusX * dx, center.y + radiusY * dy));
result.emplace_back(center.x + radiusX * dx, center.y + radiusY * dy);
double x = dx * co - dy * si;
dy = dy * co + dx * si;
dx = x;
Expand Down Expand Up @@ -700,7 +697,7 @@ namespace Clipper2Lib {
Path<T> result;
result.reserve(len);
for (typename Path<T>::size_type i = 0; i < len; ++i)
if (!flags[i]) result.push_back(path[i]);
if (!flags[i]) result.emplace_back(path[i]);
return result;
}

Expand All @@ -711,7 +708,7 @@ namespace Clipper2Lib {
Paths<T> result;
result.reserve(paths.size());
for (const auto& path : paths)
result.push_back(SimplifyPath(path, epsilon, isClosedPath));
result.emplace_back(std::move(SimplifyPath(path, epsilon, isClosedPath)));
return result;
}

Expand Down Expand Up @@ -749,7 +746,7 @@ namespace Clipper2Lib {
result.reserve(len);
for (typename Path<T>::size_type i = 0; i < len; ++i)
if (flags[i])
result.push_back(path[i]);
result.emplace_back(path[i]);
return result;
}

Expand Down
21 changes: 9 additions & 12 deletions 3rdparty/clipper2/include/clipper2/clipper.minkowski.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 1 November 2023 *
* Website : http://www.angusj.com *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2023 *
* Purpose : Minkowski Sum and Difference *
* License : http://www.boost.org/LICENSE_1_0.txt *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/

#ifndef CLIPPER_MINKOWSKI_H
#define CLIPPER_MINKOWSKI_H

#include <cstdlib>
#include <vector>
#include <string>
#include "clipper2/clipper.core.h"

namespace Clipper2Lib
Expand All @@ -35,7 +32,7 @@ namespace Clipper2Lib
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [p](const Point64& pt2) {return p + pt2; });
tmp.push_back(path2);
tmp.emplace_back(std::move(path2));
}
}
else
Expand All @@ -45,7 +42,7 @@ namespace Clipper2Lib
Path64 path2(pattern.size());
std::transform(pattern.cbegin(), pattern.cend(),
path2.begin(), [p](const Point64& pt2) {return p - pt2; });
tmp.push_back(path2);
tmp.emplace_back(std::move(path2));
}
}

Expand All @@ -59,14 +56,14 @@ namespace Clipper2Lib
Path64 quad;
quad.reserve(4);
{
quad.push_back(tmp[g][h]);
quad.push_back(tmp[i][h]);
quad.push_back(tmp[i][j]);
quad.push_back(tmp[g][j]);
quad.emplace_back(tmp[g][h]);
quad.emplace_back(tmp[i][h]);
quad.emplace_back(tmp[i][j]);
quad.emplace_back(tmp[g][j]);
};
if (!IsPositive(quad))
std::reverse(quad.begin(), quad.end());
result.push_back(quad);
result.emplace_back(std::move(quad));
h = j;
}
g = i;
Expand Down
Loading

0 comments on commit cbdef87

Please sign in to comment.