Repository navigation
ClipperOffset ClampToRange
Home › clipper.offset.h › ClipperOffset › ClipperOffset.ClampToRange
bool ClampToRange() const;
void ClampToRange(bool clamp_to_range);ClampToRange is false by default. In that case an offset that can't be built within the coordinate range fails, Execute returns no paths and ErrorCode() returns 64 (range error). Set it to true if you want such an offset clamped instead.
When it's set, a delta from Execute or from the delta callback that is infinite, or at least MAX_COORD (261 − 1) in magnitude, keeps its sign and takes the largest magnitude below MAX_COORD. Input and offset points (miter points included) have each out-of-range coordinate clamped to the nearest limit, and ErrorCode() stays 0. The one exception is a NaN delta. There is no magnitude to clamp, so it still fails with a range error.
This setting also caps round joins, round end caps and a single point's circle at 220 steps per full circle. Please note that the cap applies to every offset, including ones that would have succeeded with the default.
Execute reads the setting each time it runs, so it also applies to paths you added earlier. This means that after a range error you can turn it on and call Execute again with the same paths. Turning it back off makes Execute reject out-of-range input again.
Caution: A clamped point can cut across the region where an edge left the coordinate range. The result will stay in range but can differ in shape from the true offset. A capped arc can also be coarser than ArcTolerance asks for.
By default a single point's circle that fits can still fail when double precision rounds one of its points to ±261. With this set, the circle is built again. For a centre coordinate beyond 253 in magnitude, each offset is rounded before it is added, and otherwise the sum is rounded.
InflatePaths always uses the default. To clamp, use a ClipperOffset directly.
ClipperOffset offsetter;
offsetter.ClampToRange(true);
offsetter.AddPaths(subject, JoinType::Miter, EndType::Polygon);
Paths64 solution;
offsetter.Execute(delta, solution); // never fails for range unless delta is NaNCopyright © 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
Classes
Data types and structure definitions
- ClipType
- EndType
- FillRule
- JoinType
- Path64
- PathD
- Paths64
- PathsD
- Point64
- PointD
- PointInPolygonResult
- Rect64
- RectD
- ZCallback64
- ZCallbackD
Static Functions
- Area
- BooleanOp
- Difference
- InflatePaths
- Intersect
- IsPositive
- MakePath
- MinkowskiDiff
- MinkowskiSum
- PointInPolygon
- PolyTreeToPaths64
- PolyTreeToPathsD
- RectClip
- RectClipLines
- std::reverse
- SimplifyPaths
- TranslatePath
- TrimCollinear
- Union
- Xor
Topics