Skip to content

Commit

Permalink
Minor code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusJohnson committed Oct 30, 2023
1 parent 07be562 commit 01a3555
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
34 changes: 3 additions & 31 deletions CPP/Clipper2Lib/include/clipper2/clipper.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <algorithm>
#include <climits>
#include <numeric>
#include "clipper2/clipper.version.h"
#include "clipper.version.h"

namespace Clipper2Lib
{
Expand Down Expand Up @@ -244,19 +244,13 @@ namespace Clipper2Lib
T right;
T bottom;

Rect() :
left(0),
top(0),
right(0),
bottom(0) {}

Rect(T l, T t, T r, T b) :
left(l),
top(t),
right(r),
bottom(b) {}

Rect(bool is_valid)
Rect(bool is_valid = true)
{
if (is_valid)
{
Expand Down Expand Up @@ -322,9 +316,7 @@ namespace Clipper2Lib
}

friend std::ostream& operator<<(std::ostream& os, const Rect<T>& rect) {
os << "("
<< rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom
<< ")";
os << "(" << rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom << ") ";
return os;
}
};
Expand Down Expand Up @@ -502,26 +494,6 @@ namespace Clipper2Lib
return result;
}

inline PathD Path64ToPathD(const Path64& path)
{
return TransformPath<double, int64_t>(path);
}

inline PathsD Paths64ToPathsD(const Paths64& paths)
{
return TransformPaths<double, int64_t>(paths);
}

inline Path64 PathDToPath64(const PathD& path)
{
return TransformPath<int64_t, double>(path);
}

inline Paths64 PathsDToPaths64(const PathsD& paths)
{
return TransformPaths<int64_t, double>(paths);
}

template<typename T>
inline double Sqr(T val)
{
Expand Down
12 changes: 6 additions & 6 deletions CPP/Clipper2Lib/include/clipper2/clipper.export.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ static Paths64 ConvertCPathsDToPaths64(const CPathsD paths, double scale)
template <typename T>
static void CreateCPolyPath(const PolyPath64* pp, T*& v, T scale)
{
*v++ = (T)pp->Polygon().size();
*v++ = (T)pp->Count();
*v++ = static_cast<T>(pp->Polygon().size());
*v++ = static_cast<T>(pp->Count());
for (const Point64& pt : pp->Polygon())
{
*v++ = (T)(pt.x * scale);
*v++ = (T)(pt.y * scale);
*v++ = static_cast<T>(pt.x * scale);
*v++ = static_cast<T>(pt.y * scale);
}
for (size_t i = 0; i < pp->Count(); ++i)
CreateCPolyPath(pp->Child(i), v, scale);
Expand All @@ -343,8 +343,8 @@ static T* CreateCPolyTree(const PolyTree64& tree, T scale)
T* result = new T[array_len];
T* v = result;

*v++ = (T)array_len;
*v++ = (T)tree.Count();
*v++ = static_cast<T>(array_len);
*v++ = static_cast<T>(tree.Count());
for (size_t i = 0; i < tree.Count(); ++i)
CreateCPolyPath(tree.Child(i), v, scale);
return result;
Expand Down
13 changes: 7 additions & 6 deletions CPP/Examples/Inflate/Inflate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@ void DoSimpleShapes()

FillRule fr2 = FillRule::EvenOdd;
SvgWriter svg2;

op1.push_back(MakePath({ 80,60, 20,20, 180,20, 180,70, 25,150, 20,180, 180,180 }));
op2 = InflatePaths(op1, 20, JoinType::Miter, EndType::Square, 3);
SvgAddOpenSubject(svg2, op1, fr2, false);
SvgAddSolution(svg2, Paths64ToPathsD(op2), fr2, false);
SvgAddSolution(svg2, TransformPaths<double, int64_t>(op2), fr2, false);
SvgAddCaption(svg2, "Miter Joins; Square Ends", 20, 210);

op1 = TranslatePaths<int64_t>(op1, 210, 0);
op2 = InflatePaths(op1, 20, JoinType::Square, EndType::Square);
SvgAddOpenSubject(svg2, op1, fr2, false);
SvgAddSolution(svg2, Paths64ToPathsD(op2), fr2, false);
SvgAddSolution(svg2, TransformPaths<double, int64_t>(op2), fr2, false);
SvgAddCaption(svg2, "Square Joins; Square Ends", 230, 210);

op1 = TranslatePaths<int64_t>(op1, 210, 0);
op2 = InflatePaths(op1, 20, JoinType::Bevel, EndType::Butt, 3);
SvgAddOpenSubject(svg2, op1, fr2, false);
SvgAddSolution(svg2, Paths64ToPathsD(op2), fr2, false);
SvgAddSolution(svg2, TransformPaths<double, int64_t>(op2), fr2, false);
SvgAddCaption(svg2, "Bevel Joins; Butt Ends", 440, 210);

op1 = TranslatePaths<int64_t>(op1, 210, 0);
op2 = InflatePaths(op1, 20, JoinType::Round, EndType::Round);
SvgAddOpenSubject(svg2, op1, fr2, false);
SvgAddSolution(svg2, Paths64ToPathsD(op2), fr2, false);
SvgAddSolution(svg2, TransformPaths<double, int64_t>(op2), fr2, false);
SvgAddCaption(svg2, "Round Joins; Round Ends", 650, 210);

SvgSaveToFile(svg2, "open_paths.svg", 800, 600, 20);
Expand Down Expand Up @@ -80,9 +81,9 @@ void DoSimpleShapes()
co.Execute(20, p);
pp.insert(pp.end(), p.begin(), p.end());

FillRule fr = FillRule::EvenOdd;
FillRule fr3 = FillRule::EvenOdd;
SvgWriter svg;
SvgAddSolution(svg, Paths64ToPathsD(pp), fr, false);
SvgAddSolution(svg, TransformPaths<double, int64_t>(pp), fr3, false);
SvgSaveToFile(svg, "solution_off.svg", 800, 600, 20);
System("solution_off.svg");
}
Expand Down

0 comments on commit 01a3555

Please sign in to comment.