Skip to content

Path2d offset, stroke, and intersection operations#2390

Merged
andrewfb merged 5 commits intocinder:masterfrom
andrewfb:pathmath5_rebase
Dec 26, 2025
Merged

Path2d offset, stroke, and intersection operations#2390
andrewfb merged 5 commits intocinder:masterfrom
andrewfb:pathmath5_rebase

Conversation

@andrewfb
Copy link
Collaborator

Summary

Adds path offsetting, stroking, and intersection detection to Path2d and Shape2d.

  • Path offset: Generate parallel curves at a specified distance with configurable join styles (bevel/miter/round) - calcOffset() function
  • Path stroke: Expand paths into filled stroke shapes with configurable caps (butt/square/round) and joins - calcStroke() function
  • Dash patterns: Apply dash patterns to paths via calcDashed()
  • Intersection detection: findIntersections() between two paths, findSelfIntersections() and removeSelfIntersections()
  • CinderMath additions: Numerically stable polynomial solvers, line-bezier intersections, and bezier evaluation utilities

Includes BezierOffset sample demonstrating the new APIs with interactive controls for all parameters.
image

Here's a video of the sample in action:
https://vimeo.com/1147501490

The real heavy lifting for this code was done by Raph Levien, and is described in this blog article, and his implementation in the Kurbo library is the foundation of this Cinder implementation.

Adds numerically stable quadratic and cubic polynomial solvers (citardauq
and Blinn's method), ITP root-finding algorithm, line-bezier intersection
functions, bezier evaluation/subdivision helpers, and arc length utilities
for path offsetting and stroke operations.
Adds findIntersections() for detecting intersections between two paths,
findSelfIntersections() with sweep-and-prune spatial indexing for efficient
self-intersection detection, and removeSelfIntersections() for planar graph
decomposition. Also adds isCoincident() for detecting overlapping paths.
Implements offset() for parallel curve generation with join styles
(bevel/miter/round), stroke() for expanding paths into filled stroke
shapes with configurable caps and joins, and calcDashed() for dash
pattern application. Adds StrokeStyle class for configuring stroke
parameters. Shape2d gains matching offset/stroke/calcDashed methods
that operate on all contours.

Uses tolerance-based arc-to-cubic subdivision for round joins and caps.
Interactive sample demonstrating path offset and stroke APIs with
configurable join styles, cap styles, miter limits, and tolerances.
Supports multiple shapes, preset shapes including glyphs, shape-to-shape
intersection display, and tangent visualization.
@andrewfb andrewfb merged commit a5bbe9e into cinder:master Dec 26, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant