SvgPath 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SvgPath --version 0.1.0
                    
NuGet\Install-Package SvgPath -Version 0.1.0
                    
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="SvgPath" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SvgPath" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SvgPath" />
                    
Project file
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 SvgPath --version 0.1.0
                    
#r "nuget: SvgPath, 0.1.0"
                    
#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 SvgPath@0.1.0
                    
#: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=SvgPath&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SvgPath&version=0.1.0
                    
Install as a Cake Tool

SvgPath

SvgPath is an F# library for SVG path parsing, serialization, transforms, curve geometry, intersections, arrangements, Boolean operations, offsets, bands, and strokes. It is a behavior-preserving port of the Gleam svg_path, with F# units of measure added to audit scalar usage.

The package targets .NET 9. Its public API may change while the mechanically faithful port is refined into a more idiomatic F# library.

Install

dotnet add package SvgPath --version 0.1.0
open SvgPath

let result =
    Parse.path "M 0 0 L 20 0 L 20 20 Z"
    |> Result.mapError (sprintf "parse error: %A")
    |> Result.bind (fun path ->
        Offset.path path 2.0<length>
        |> Result.mapError (sprintf "offset error: %A"))
    |> Result.map Serialize.path

Most geometric operations return Result, keeping invalid geometry, numerical failures, and violated topology assumptions explicit.

Numeric and path model

Public geometry uses SVG user-space coordinates, where positive y points down. Positive signed offsets use the visual-left normal. Clockwise and counterclockwise APIs likewise refer to visual SVG orientation.

  • float<length> represents coordinates, distances, radii, and tolerances.
  • float<length^2> represents squared lengths and areas.
  • float<parameter> represents normalized curve parameters.
  • float<degree> and float<radian> represent angles.

Curve parameters are dimensionless mathematically, but nominally measured in F#. Derivatives retain parameter powers such as Point<length / parameter> and Point<length / parameter^2>.

The core model is Point, Segment, Subpath, and Path. Segments may be lines, quadratic or cubic Béziers, or endpoint-form elliptical arcs. Subpaths retain an explicit start and closure flag. Construction checks continuity according to an EndpointPolicy rather than silently changing disconnected geometry.

Parse.path reads SVG path data. Serialize.path writes it, with options for relative commands, precision, whitespace, horizontal/vertical and smooth commands, and command repetition. Empty and zero-length subpaths remain representable; rendering depends on closure and line-cap semantics.

Zero-length closepath behavior

Geometry

Segment, Subpath, and Path expose evaluation, directions, derivatives, bounding boxes, length, splitting, splicing, reversal, linearization, projection, and similarity remapping. Intersections computes intersections and closest-point pairs. Overlaps handles parameter correspondences for coincident portions; Encounters and Cut expose ordered encounters and cuts.

Supporting modules include Bezier, Ellipse, Curvature, Root, Area, WindingField, ConvexHull, SmallestEnclosingCircle, Congruency, BasicShapes, Transform, Degeneracy, Effects, Marker, and Clip.

Arrangements and CSG

Arrangement.build nodes paths into a planar graph while preserving source-to-edge images, directional multiplicities, and cyclic edge orders. ArrangementDrawing provides diagnostics.

Arrangement of overlapping squares

Coincident circle geometry

Csg computes union, intersection, difference, symmetric difference, and nested contours under either SVG fill rule.

Nonzero CSG

Even-odd CSG

Offsets, bands, and strokes

Offset.path constructs a signed single offset. Offset.pathBand constructs the region between two signed offsets and accepts either inner/outer ordering. Offset.pathStroke constructs a stroke through the same curve-fitting and arrangement machinery. Subpath and configurable With variants are provided.

Offset.Options controls fitting tolerance, sampling and refinement depth, joins, tangent healing, stalled-offset handling, and trimming. Offset.defaultOptions supplies the normal policy.

Single-offset trimming

SingleOffsetTrimming.Offside enables closed-subpath trimming by signed offset side. FinalTrimming selects CuspTrimming, InBandTrimming, or NoTrimming. In-band trimming is the default and includes cusp cases.

Single-offset final trimming

Single-offset offside trimming

Band trimming

BandTrimming independently controls InnerCusps, OuterCusps, and the final band-wide InBand pass.

Band cusp trimming

Band in-band trimming

Module map

Area Modules
Core Point, SvgPath, BasicShapes, Inspect
Curves Bezier, Ellipse, Curvature, Root, Trig
Input/output Parse, Serialize, Svg, Format
Editing Affine, Transform, TransformParse, TransformSerialize, Degeneracy, Effects, Marker, Clip
Relationships Intersections, Overlaps, OverlapDetection, Encounters, Cut, Congruency
Topology Area, WindingField, Arrangement, ArrangementDrawing, Csg
Enclosures ConvexHull, SmallestEnclosingCircle
Derived paths Offset, Stroke

Development

dotnet test tests/SvgPath.Tests/SvgPath.Tests.fsproj
scripts/generate-readme-figures
scripts/generate-readme-figures --check

README figures are generated through the public F# API by a non-packable console project. The generated SVGs live under docs/readme; neither the tool nor those assets are part of the SvgPath NuGet package. Every generated SVG starts with a white rectangle covering its complete view box.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.5.0 52 9/7/2026
0.4.0 57 9/6/2026
0.3.0 57 9/5/2026
0.2.0 55 9/5/2026
0.1.0 54 9/4/2026