Repository navigation
Clipper64 ZCallback
Home › clipper.engine.h › Clipper64 › Clipper64.ZCallback
void SetZCallback( ZCallback64 cb);This property is only exposed when the pre-processor directive USINGZ has been defined. If this is the case, an int64_t Z member will be included in the definitions of both the Point64 and PointD classes. (This Z member is for user defined data and has nothing to do with 3D clipping.)
While most vertices in clipping solutions will correspond to input (subject and clip) vertices, there will also be new vertices wherever these segments intersect. This callback facilitates assigning user-defined Z values at these intersections. To aid the user in determining appropriate Z values, the function receives the vertices at both ends of the intersecting segments (ie four vertices). Subject vertices will be listed before clip vertices in the callback's parameter list.
In the following examples, use the Z callback to flag intersections (Z = 1) and differentiate them from non-intersection vertices (default Z = 0).
Example:
using namespace Clipper2Lib;
// option1 - static callback function
static void myZCB(const Point64& e1bot, const Point64& e1top,
const Point64& e2bot, const Point64& e2top, Point64& pt)
{
pt.z = 1;
}
// option2 - class member callback function
class MyClass {
public:
void myZCB(const Point64& e1bot, const Point64& e1top,
const Point64& e2bot, const Point64& e2top, Point64& pt)
{
pt.z = 1;
}
};
int main()
{
PathsD subject, clip, solution;
//fill subject and clip paths here
subject.push_back(MakePath(
{100, 50, 10, 79, 65, 2, 65, 98, 10, 21}));
//option 1: static function assignment
Clipper64 c = Clipper64;
c.SetZCallback(myZCB);
/*
// option 2: class member function assignment
MyClass mc;
Clipper64 c = Clipper64;
c.SetZCallback(
std::bind(&MyClass::myZCB, mc, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, std::placeholders::_5));
*/
c.Execute(ClipType::Union, FillRule::NonZero, solution);
// display result
SvgWriter svg;
SvgAddSubject(svg, subject, FillRule::NonZero);
SvgAddSolution(svg, solution, FillRule::NonZero, true);
// draw a red circle around any intersections
for (const auto& sol_path : solution)
{
if (sol_path.empty()) continue;
PathsD ellipses;
const double r = 3.0;
for (const Point64& pt : sol_path)
if (pt.z) ellipses.push_back(
Ellipse(RectD(pt.x - r, pt.y - r, pt.x + r, pt.y + r), 11));
svg.AddPaths(ellipses, false,
FillRule::NonZero, 0x20FF0000, 0xFFFF0000, 1, false);
}
SvgSaveToFile(svg, "usingz_64.svg", 600, 600, 20);
}
Copyright © 2010-2025 Angus Johnson. Clipper2 is distributed under the Boost Software License.
Headers
- clipper.h
- clipper.core.h
- clipper.engine.h
- clipper.export.h
- clipper.minkowski.h
- clipper.offset.h
- clipper.rectclip.h
- clipper.triangulation.h
Classes
Data types and structure definitions
- ClipType
- EndType
- FillRule
- JoinType
- Path64
- PathD
- Paths64
- PathsD
- Point64
- PointD
- PointInPolygonResult
- Rect64
- RectD
- TriangulateResult
- ZCallback64
- ZCallbackD
Static Functions
- Area
- BooleanOp
- Difference
- InflatePaths
- Intersect
- IsPositive
- MakePath
- MinkowskiDiff
- MinkowskiSum
- PointInPolygon
- PolyTreeToPaths64
- PolyTreeToPathsD
- RectClip
- RectClipLines
- ReversePath
- SimplifyPaths
- TranslatePath
- Triangulate
- TrimCollinear
- Union
- XOR
Topics