#ifndef CLIPPER_CORE_H
#define CLIPPER_CORE_H
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include "clipper2/clipper.version.h"
#define CLIPPER2_THROW(exception) …
namespace Clipper2Lib
{
#if (defined(__cpp_exceptions) && __cpp_exceptions) || (defined(__EXCEPTIONS) && __EXCEPTIONS)
class Clipper2Exception : public std::exception {
public:
explicit Clipper2Exception(const char* description) :
m_descr(description) {}
virtual const char* what() const throw() override { return m_descr.c_str(); }
private:
std::string m_descr;
};
static const char* precision_error =
"Precision exceeds the permitted range";
static const char* range_error =
"Values exceed permitted range";
static const char* scale_error =
"Invalid scale (either 0 or too large)";
static const char* non_pair_error =
"There must be 2 values for each coordinate";
static const char* undefined_error =
"There is an undefined error in Clipper2";
#endif
const int precision_error_i = …;
const int scale_error_i = …;
const int non_pair_error_i = …;
const int undefined_error_i = …;
const int range_error_i = …;
#ifndef PI
static const double PI = …;
#endif
#ifdef CLIPPER2_MAX_PRECISION
const int MAX_DECIMAL_PRECISION = CLIPPER2_MAX_PRECISION;
#else
const int MAX_DECIMAL_PRECISION = …;
#endif
static const int64_t MAX_COORD = …;
static const int64_t MIN_COORD = …;
static const int64_t INVALID = …;
const double max_coord = …;
const double min_coord = …;
static const double MAX_DBL = …;
static void DoError(int error_code)
{ … }
enum class FillRule { … };
template <typename T>
struct Point { … };
Point64;
PointD;
Path;
Paths;
Path64;
PathD;
Paths64;
PathsD;
static const Point64 InvalidPoint64 = …;
static const PointD InvalidPointD = …;
template <typename T>
struct Rect;
Rect64;
RectD;
template <typename T>
struct Rect { … };
template <typename T1, typename T2>
inline Rect<T1> ScaleRect(const Rect<T2>& rect, double scale)
{ … }
static const Rect64 InvalidRect64 = …;
static const RectD InvalidRectD = …;
template <typename T>
Rect<T> GetBounds(const Path<T>& path)
{ … }
template <typename T>
Rect<T> GetBounds(const Paths<T>& paths)
{ … }
template <typename T>
std::ostream& operator << (std::ostream& outstream, const Path<T>& path)
{ … }
template <typename T>
std::ostream& operator << (std::ostream& outstream, const Paths<T>& paths)
{ … }
template <typename T1, typename T2>
inline Path<T1> ScalePath(const Path<T2>& path,
double scale_x, double scale_y, int& error_code)
{ … }
template <typename T1, typename T2>
inline Path<T1> ScalePath(const Path<T2>& path,
double scale, int& error_code)
{ … }
template <typename T1, typename T2>
inline Paths<T1> ScalePaths(const Paths<T2>& paths,
double scale_x, double scale_y, int& error_code)
{ … }
template <typename T1, typename T2>
inline Paths<T1> ScalePaths(const Paths<T2>& paths,
double scale, int& error_code)
{ … }
template <typename T1, typename T2>
inline Path<T1> TransformPath(const Path<T2>& path)
{ … }
template <typename T1, typename T2>
inline Paths<T1> TransformPaths(const Paths<T2>& paths)
{ … }
template<typename T>
inline double Sqr(T val)
{ … }
template<typename T>
inline bool NearEqual(const Point<T>& p1,
const Point<T>& p2, double max_dist_sqrd)
{ … }
template<typename T>
inline Path<T> StripNearEqual(const Path<T>& path,
double max_dist_sqrd, bool is_closed_path)
{ … }
template<typename T>
inline Paths<T> StripNearEqual(const Paths<T>& paths,
double max_dist_sqrd, bool is_closed_path)
{ … }
template<typename T>
inline void StripDuplicates( Path<T>& path, bool is_closed_path)
{ … }
template<typename T>
inline void StripDuplicates( Paths<T>& paths, bool is_closed_path)
{ … }
inline void CheckPrecision(int& precision, int& error_code)
{ … }
inline void CheckPrecision(int& precision)
{ … }
template <typename T>
inline double CrossProduct(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3) { … }
template <typename T>
inline double CrossProduct(const Point<T>& vec1, const Point<T>& vec2)
{ … }
template <typename T>
inline double DotProduct(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3) { … }
template <typename T>
inline double DotProduct(const Point<T>& vec1, const Point<T>& vec2)
{ … }
template <typename T>
inline double DistanceSqr(const Point<T> pt1, const Point<T> pt2)
{ … }
template <typename T>
inline double DistanceFromLineSqrd(const Point<T>& pt, const Point<T>& ln1, const Point<T>& ln2)
{ … }
template <typename T>
inline double Area(const Path<T>& path)
{ … }
template <typename T>
inline double Area(const Paths<T>& paths)
{ … }
template <typename T>
inline bool IsPositive(const Path<T>& poly)
{ … }
inline bool GetIntersectPoint(const Point64& ln1a, const Point64& ln1b,
const Point64& ln2a, const Point64& ln2b, Point64& ip)
{ … }
inline bool SegmentsIntersect(const Point64& seg1a, const Point64& seg1b,
const Point64& seg2a, const Point64& seg2b, bool inclusive = false)
{ … }
template<typename T>
inline Point<T> GetClosestPointOnSegment(const Point<T>& offPt,
const Point<T>& seg1, const Point<T>& seg2)
{ … }
enum class PointInPolygonResult { … };
template <typename T>
inline PointInPolygonResult PointInPolygon(const Point<T>& pt, const Path<T>& polygon)
{ … }
}
#endif