CavalierContoursSharp 0.4.0-preview
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.0
This package targets .NET Framework 4.0. The package is compatible with this framework or higher.
This is a prerelease version of CavalierContoursSharp.
dotnet add package CavalierContoursSharp --version 0.4.0-preview
NuGet\Install-Package CavalierContoursSharp -Version 0.4.0-preview
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CavalierContoursSharp" Version="0.4.0-preview" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CavalierContoursSharp" Version="0.4.0-preview" />
<PackageReference Include="CavalierContoursSharp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CavalierContoursSharp --version 0.4.0-preview
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CavalierContoursSharp, 0.4.0-preview"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CavalierContoursSharp@0.4.0-preview
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CavalierContoursSharp&version=0.4.0-preview&prerelease
#tool nuget:?package=CavalierContoursSharp&version=0.4.0-preview&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CavalierContoursSharp
C# binding for cavalier_contours, a high-performance 2D polyline/shape library for offsetting, combining, and more. <mcreference link="https://github.com/jbuckmccready/cavalier_contours" index="1">1</mcreference>
Features
- High Performance: Built on the fast Rust cavalier_contours library <mcreference link="https://github.com/jbuckmccready/cavalier_contours" index="1">1</mcreference>
- Polyline Operations: Create, modify, and analyze 2D polylines with arc support
- Boolean Operations: Union (OR), Intersection (AND), Difference (NOT), and XOR operations
- Parallel Offsetting: Generate offset polylines with various join types
- Geometric Queries: Area calculation, path length, winding number, point-in-polygon tests
- Spatial Indexing: AABB (Axis-Aligned Bounding Box) indexing for fast spatial queries
- Memory Safe: Proper resource management with IDisposable pattern
- Cross-Platform: Supports Windows x64 (more platforms coming soon)
Installation
dotnet add package CavalierContoursSharp
Quick Start
Creating a Simple Polyline
using CavalierContoursSharp;
// Create an empty polyline
using var polyline = new Polyline();
// Add vertices
polyline.AddVertex(0, 0);
polyline.AddVertex(10, 0);
polyline.AddVertex(10, 10);
polyline.AddVertex(0, 10);
// Make it closed
polyline.IsClosed = true;
// Get properties
Console.WriteLine($"Area: {polyline.Area}");
Console.WriteLine($"Path Length: {polyline.PathLength}");
Console.WriteLine($"Vertex Count: {polyline.VertexCount}");
Creating Polylines with Arcs
// Create a polyline with arc segments using bulge values
var vertices = new[]
{
new CavcVertex(0, 0, 0), // Straight line to next vertex
new CavcVertex(10, 0, 0.5), // Arc to next vertex (bulge = 0.5)
new CavcVertex(10, 10, 0), // Straight line to next vertex
new CavcVertex(0, 10, 0) // Straight line back to start
};
using var polyline = new Polyline(vertices, true); // true = closed
Boolean Operations
// Create two overlapping squares
using var square1 = new Polyline(new[]
{
new CavcVertex(0, 0),
new CavcVertex(10, 0),
new CavcVertex(10, 10),
new CavcVertex(0, 10)
}, true);
using var square2 = new Polyline(new[]
{
new CavcVertex(5, 5),
new CavcVertex(15, 5),
new CavcVertex(15, 15),
new CavcVertex(5, 15)
}, true);
// Perform boolean operations
var (union, _) = square1.BooleanOperation(square2, BooleanOp.Or);
var (intersection, _) = square1.BooleanOperation(square2, BooleanOp.And);
var (difference, _) = square1.BooleanOperation(square2, BooleanOp.Not);
var (xor, _) = square1.BooleanOperation(square2, BooleanOp.Xor);
// Remember to dispose results
union.Dispose();
intersection.Dispose();
difference.Dispose();
xor.Dispose();
Parallel Offsetting
using var polyline = new Polyline(new[]
{
new CavcVertex(0, 0),
new CavcVertex(10, 0),
new CavcVertex(10, 10),
new CavcVertex(0, 10)
}, true);
// Create offset polylines
using var offsetResults = polyline.ParallelOffset(2.0); // Offset by 2 units
foreach (var offsetPolyline in offsetResults)
{
Console.WriteLine($"Offset polyline area: {offsetPolyline.Area}");
offsetPolyline.Dispose();
}
Geometric Queries
using var polyline = new Polyline(new[]
{
new CavcVertex(0, 0),
new CavcVertex(10, 0),
new CavcVertex(10, 10),
new CavcVertex(0, 10)
}, true);
// Point-in-polygon test
int windingNumber = polyline.GetWindingNumber(5, 5); // Inside: winding number = 1
int windingNumber2 = polyline.GetWindingNumber(15, 15); // Outside: winding number = 0
// Get bounding box
if (polyline.GetExtents(out double minX, out double minY, out double maxX, out double maxY))
{
Console.WriteLine($"Bounds: ({minX}, {minY}) to ({maxX}, {maxY})");
}
// Transform operations
polyline.Scale(2.0); // Scale by factor of 2
polyline.Translate(5, 5); // Move by (5, 5)
polyline.InvertDirection(); // Reverse vertex order
Working with Vertices
using var polyline = new Polyline();
// Add vertices one by one
polyline.AddVertex(0, 0, 0); // x, y, bulge
polyline.AddVertex(10, 0, 0.5); // Arc segment
polyline.AddVertex(10, 10, 0);
// Get and modify vertices
var vertex = polyline.GetVertex(1);
vertex.Bulge = 0.2; // Change arc curvature
polyline.SetVertex(1, vertex);
// Get all vertices
var allVertices = polyline.GetVertices();
// Iterate through vertices
foreach (var v in polyline)
{
Console.WriteLine($"Vertex: ({v.X}, {v.Y}), Bulge: {v.Bulge}");
}
Understanding Bulge Values
Bulge values define arc segments between vertices:
bulge = 0
: Straight line segmentbulge > 0
: Arc curves to the left (counter-clockwise)bulge < 0
: Arc curves to the right (clockwise)bulge = 1
: Perfect semicirclebulge = tan(θ/4)
where θ is the arc's central angle
API Reference
Core Classes
Polyline
: Main class representing a 2D polyline with vertices and arcsCavcVertex
: Structure representing a vertex with X, Y coordinates and bulge valuePolylineList
: Collection of polylines returned by boolean operationsBooleanOp
: Enumeration of boolean operation types (Or, And, Not, Xor)CavcAabbIndex
: Spatial index for fast geometric queries
Key Methods
- Vertex Management:
AddVertex()
,GetVertex()
,SetVertex()
,RemoveVertex()
- Boolean Operations:
BooleanOperation()
- Offsetting:
ParallelOffset()
- Geometric Queries:
GetWindingNumber()
,GetExtents()
,Area
,PathLength
- Transformations:
Scale()
,Translate()
,InvertDirection()
- Spatial Indexing:
CreateAabbIndex()
,CreateApproximateAabbIndex()
Performance Notes
- Always dispose of
Polyline
andPolylineList
objects to free native memory - Use
using
statements for automatic disposal - Boolean operations and offsetting can return multiple result polylines
- AABB indexing significantly speeds up spatial queries for complex polylines
Platform Support
- Windows x64: ✅ Fully supported
- Linux x64: 🚧 Coming soon
- macOS: 🚧 Coming soon
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- cavalier_contours - The original Rust library <mcreference link="https://github.com/jbuckmccready/cavalier_contours" index="1">1</mcreference>
- Interactive Web Demo - Try the library online <mcreference link="https://github.com/jbuckmccready/cavalier_contours_web_demo" index="5">5</mcreference>
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 | net40 is compatible. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- System.Numerics.Vectors (>= 4.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.4.0-preview | 119 | 7/9/2025 |