Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++ variadic templates for MakePath #398

Closed
wants to merge 1 commit into from

Conversation

jschuh
Copy link
Contributor

@jschuh jschuh commented Feb 5, 2023

This PR adds variadic template functions for MakePath and MakePathD. In addition to being more in keeping with modern C++ style, they allow the compiler to validate the arguments and optimize away most of the runtime initialization code.

I converted over most of the tests, but left one to retain coverage of the existing string-based MakePath and MakePathD.

Should improve performance and reduce errors by moving more of the
initialization to compile time.
{
static_assert(N % 2 == 0, "MakePath requires an even number of arguments");
Path64 result(N / 2);
for (size_t i = 0; i < N; ++i)
Copy link
Owner

@AngusJohnson AngusJohnson Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    Path64 result;                
    result.reserve(N / 2);
#ifdef USINGZ
    for (size_t i = 0; i < N; ++i)
      result.emplace_back(Point64{ list[i], list[++i], 0 });
#else
    for (size_t i = 0; i < N; ++i)
      result.emplace_back(Point64{ list[i], list[++i] });
#endif

AngusJohnson added a commit that referenced this pull request Feb 6, 2023
Fixed InflatePaths to return unchanged paths when delta == 0 (#389)
Minor tweak to detecting "touching" solution polygons
Fixed minor bug in ClipperOffset (#392,#393)
Tidied up error handling in C++
Added error_code param to ScalePath function (C++)
Tweaks to C# CI testing (#388)
Major rewrite of RectClip function (Delphi only so far) (#383)
@AngusJohnson
Copy link
Owner

Hi Justin.
I've just pushed this (with very minor amendments) together with a whole lot of other stuff.
And thank you for the helpful feedback. Cheers A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants