Klip 2.0.1152
See the version list below for details.
dotnet add package Klip --version 2.0.1152
NuGet\Install-Package Klip -Version 2.0.1152
<PackageReference Include="Klip" Version="2.0.1152" />
<PackageVersion Include="Klip" Version="2.0.1152" />
<PackageReference Include="Klip" />
paket add Klip --version 2.0.1152
#r "nuget: Klip, 2.0.1152"
#:package Klip@2.0.1152
#addin nuget:?package=Klip&version=2.0.1152
#tool nuget:?package=Klip&version=2.0.1152

Klip
Fast and robust polygon clipping.
A partial F# port of Clipper2. This port is derived from the clipper2-ts TypeScript port rather than the original C#.
All original tests pass. There are also some new ones. And it's even a bit faster than clipper2-ts. See bench README.
Why another port?
In short, to use it in F# and be able to compile to JavaScript via Fable So that this code - and a lot of other code using it - runs on .NET as well as in the browser.
Scope
This is a partial port - only what's needed for polygon boolean operations on a single coordinate type:
Polygon boolean ops (intersection, union, difference, XOR) and PolyTree output
like in
clipper2-ts64-bit integer coordinates are represented byfloat(64-bit) so the output is Fable-friendly (no JSbigint) .No scaling of input coordinates, like PathD does in
clipper2-tsto support floating-point input. Instead, users can choose to scale their coordinates before passing them to Klip if they need more precision.No offsetting / inflation, line clipping, rect clipping, Minkowski sums, triangulation, or arbitrary-precision decimal paths
The main convenience API is in Src/Klip.fs, in the Klip.Clipper module. It wraps Clipper64 for the common polygon boolean operations while keeping the lower-level engine available for specialized cases.
Core Types
Original Documentation: https://www.angusj.com/clipper2
All types are still named like the original C# version, where the ..64 suffix indicated 64-bit integers. In Klip the XY coordinates are stored as float, and there is no ..D suffix API that scales floating-point paths to integer paths.
New Generic 'Z Metadata
'Z is the generic type parameter for user-defined metadata that can be attached to vertices. It is optional and defaults to unit if not used.
In the original Clipper2 the optional Z value is always a int64 but in Klip it can be any type.
Path64<'Z>: A single contour. X and Y coordinates are stored in a flat interleavedResizeArray<float>asx0, y0, x1, y1, ....Paths64<'Z>: AResizeArray<Path64<'Z>>, representing multiple contours such as an outer polygon and its holes.PolyTree64<'Z>: A tree output structure that preserves parent-child contour relationships, such as holes inside outer contours.ZCallback64<'Z>: A callback for assigning user-defined'Zmetadata to new vertices created at edge intersections.'Zvalues are metadata, not 3D coordinates.
If you do not use 'Z metadata, use the default no-Z helpers such as Path64.createFrom and Paths64.createSingle; these create Path64<unit> and Paths64<unit> values.
Boolean Operations
Clipper.intersect clip subject: Returns the intersection of the subject and clip paths.Clipper.union clip subject: Returns the union of subject and clip paths.Clipper.unionSelf subject: Resolves self-intersections within a single subject path.Clipper.difference clip subject: Returns the regions of the subject that are not inside the clip region.Clipper.xor clip subject: Returns the regions of subject or clip that are not in both.
Each wrapper also has a Z variant that takes a ZCallback64<'Z> as the first argument:
Clipper.intersectZ zCallback clip subjectClipper.unionZ zCallback clip subjectClipper.unionSelfZ zCallback subjectClipper.differenceZ zCallback clip subjectClipper.xorZ zCallback clip subject
Use the general functions when you need a custom ClipType, FillRule, ZCallback64, or PolyTree64 output:
Clipper.booleanOp (clipType, subject, clip, fillRule, zCallback): Performs a boolean operation and returnsPaths64<'Z>.Clipper.booleanOpWithPolyTree (clipType, subject, clip, polyTree, fillRule, zCallback): Writes the result into aPolyTree64<'Z>so hierarchy is preserved.Clipper.polyTreeToPaths64 polyTree: Flattens aPolyTree64<'Z>back intoPaths64<'Z>.
open Klip
let subject =
Paths64.createSingle [ 0.0; 0.0; 10.0; 0.0; 10.0; 10.0; 0.0; 10.0 ]
let clip =
Paths64.createSingle [ 5.0; 5.0; 15.0; 5.0; 15.0; 15.0; 5.0; 15.0 ]
let union = Clipper.union clip subject
let intersection = Clipper.intersect clip subject
let nonZeroDifference =
Clipper.booleanOp (ClipType.Difference, subject, clip, FillRule.NonZero, None)
Building
for .NET
dotnet build
for JS
cd Test
npm install
npm run build # F# → JavaScript via Fable, then vite build
npm run buildts # F# → TypeScript via Fable, then tsc and vite build
npm test # vitest --run
The compiled TypeScript ends up in _dist/Klip.mjs and is what the test
suite imports.
Performance
On .NET ist about the same as CLipper2 C#, but with more allocations.
In JavaScript it's about 15% faster than clipper2-ts, but 40% slower than clipper2-wasm.
See Test/bench/README.md
and Test/README.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
### Changed
- MAJOR API refactor and renaming
### Added
- Testa and benchmarks