Projects / 01
ocurves
Native Odin curve geometry for vector renderers: shapes whose pixel coverage is computed exactly on the CPU and the GPU, and booleans of filled contours that keep their curves.
- Odin
- MIT
- core: only
- CPU and GPU (GLSL)
Where it came from
ocurves was ovg's curves package and its curves.slang shader through ovg v0.0.42, and its history before v0.0.1 is in ovg's repository. curves.glsl replaced the Slang shader in v0.0.18, once ovg and o3d compiled their shaders with oksl. ovg fills its paths, glyphs, strokes and markers with it, o3d its curved shapes and text in 3D, andonimite keeps one path type on it.
By the numbers
- worst coverage error
- 0.18/255
- an '&' at 22 px against 16,384 samples a pixel; 4× MSAA's worst is 74/255
- a pixel's coverage
- 92 ns
- one thread; the '&' at 620 px builds in 10.4 µs, linear in its 106 pieces
- GPU against CPU
- 1/255
- curves.glsl in ovg's SDL_GPU backend (Vulkan) against the same shader in its software backend (oksl's CPU runner): 16 of 484 pixels differ, by 1
- wrong in 32,000 boolean results
- 0
- ovg's bool_suite, seeds 1 and 7, 2,000 cases each with their divides
ocurves' demo/bake at v0.0.7 (whose library is v0.0.6's), as committed in demo/media/bake.json and re-run 2026-10-28: the same counts and errors, times within 1.5%. -o:speed on one thread of a Ryzen 9 9900X3D; the GPU side on an RX 9070 XT (Vulkan, RADV); the build is the median of 201 runs and each boolean of 51. The GPU row re-run 2026-11-17 at ocurves v0.0.18 with ovg v0.0.82, oglyph v0.0.14, oksl v0.0.28 and oicut v0.0.29: the same pixels as bake.json. glsl_test: ocurves v0.0.19 with oksl v0.0.28, re-run 2026-11-17 (worst coverage 7.15e-7, zoomed in 9x). Fuzzing: ovg v0.0.52's tools/bool_suite.
What's in it
01Shapes as curves
A Builder takes contours (lines, quadratics, cubics; open or closed) and writes the shape as one block of 32-bit words: quadratic pieces, each monotone in x and y, cut into the columns of a grid of cells, each cell listing its pieces and the winding number to its right. It is built in time linear in the pieces: the '&' at 620 px, 63 segments, is 106 pieces in 7 × 9 cells, built in 10.4 µs.
02Exact coverage
A pixel's coverage is the area of its footprint inside the shape, in closed form (Green's theorem) over the pieces in the cells it touches plus the backdrop over its rows: exact under any affine footprint, or from a 3D footprint's Jacobian, and a pixel costs the pieces near it, not the shape's size. winding, mean coverage and fade for shapes smaller than a pixel, bounds, hairlines and markers read the same words.
03The GPU twin
curves.glsl has the same reads in GLSL ES 3.0, shipped as the string curves.GLSL for a host to put ahead of its shader, as oksl compiles it: it binds nothing and reads any number of shapes from one buffer of words. ovg's SDL_GPU backend draws with it, and its software backend runs the same shader on oksl's CPU runner: the '&' differs between the two by at most 1/255, in 16 of 484 pixels. Against curves.odin itself, glsl_test runs curves.glsl on oksl's CPU runner over 96 random shapes under six pixel maps (589,824 pixels, in CI on Linux and macOS): coverage within 7.2e-7, hairlines, markers and windings exact. curves.slang, the Slang twin it replaced in v0.0.18, measured 1/255 against ocurves' Odin coverage too.
04Contours
Lines and cubics in one flat table: every contour's start point and its segments' points, each segment's kind and a row per contour, neighbours sharing their end point by index. Copied by range, read in order as the cubics they are, with a contour's winding at a point and its signed area.
05Booleans that keep their curves
Union, difference, intersection and xor of any number of operands, each with its fill rule, and bool_divide's every face with the operands it lies inside. Each output segment is a range of an input line or cubic, cut where the operands meet, and the scratch records where each came from: a circle and an S give 27 of union's 29 segments as cubics, in 33 µs.
06One arrangement, bounded
Every operand's pieces are arranged once in f64: cut wherever two come within 8 f32 ulps of the largest coordinate, cut points merged into vertices, faces walked with each face's winding per operand. Output contours never cross and are grouped by region, outline first. A budget bounds the work against degenerate input: every glyph of Bitstream Vera Sans (264) and Adwaita Sans (2,915), simplified, takes at most 268 and 8,549 of its 4,000,000.
07No allocation once warm
Every table is the caller's: a Bool_Scratch kept warm allocates nothing, and a shape's words are one block the caller owns.
08One format for both
FORMAT numbers the layout the CPU writes and curves.glsl reads. A shader compiled from curves.GLSL at load always matches the words from the same package; a renderer that commits shaders compiled ahead of time asserts the FORMAT they were compiled against equals curves.FORMAT, so it refuses to build against an ocurves its shaders would misread.
What it doesn't do
- Coverage is exact per contour: where contours overlap inside one pixel under non-zero, the overlap counts twice. Simplify them with a boolean first and it's exact.
- For coverage, cubics become quadratics within a tolerance (1/4096 of the cubic's size by default); the booleans keep the original cubics.
- Booleans work in f64 and merge points within 8 f32 ulps of the largest coordinate, so shapes closer than that fuse; output vertices are rounded to f32.
- Degenerate input past the budget is an error, not a hang.
- Shaders compiled ahead of time against one FORMAT must be rebuilt when it changes.
- No stroking, dashing or text layout: those are ovg's.
Use it
import cv "deps:ocurves" // -collection:deps=.. (the directory holding ocurves)
b: cv.Builder
defer cv.builder_destroy(&b)
cv.move_to(&b, {0, 0})
cv.line_to(&b, {0, 10})
cv.quad_to(&b, {10, 10}, {10, 0})
cv.close(&b)
words, origin, extent, ok := cv.build(&b)
defer delete(words)
// The coverage of a pixel at p (source units) with sides of 1 unit: shape
// units are the source's divided by extent, starting at origin.
p := [2]f32{4.5, 4.5}
cov := cv.coverage(words, (p - origin) / extent, {1, 1} / extent, .Non_Zero)odin test . -vet -strict-style # 30 tests
sh demo/fetch.sh # Adwaita Sans, SHA-256 pinned
odin run demo/bake -collection:deps=.. -o:speed -- demo/media/bake.json
# in ovg (v0.0.52), beside ocurves:
odin build tools/bool_suite -collection:deps=.. -o:speed -out:bool_suite
./bool_suite -seed:1 -cases:2000 && ./bool_suite -seed:7 -cases:2000The family
- ocurves
Curve geometry: exact pixel coverage, and booleans that keep their curves
- ovg
2D vector graphics: paths, SVG, Lottie, text, filters
- oglyph
Fonts and OpenType text shaping, checked against HarfBuzz
- oicut
Video, audio and image codecs with no FFmpeg
- oksl
SkSL and Shadertoy shaders to SPIR-V, MSL and CPU
- o3d
3D in three.js terms, on the GPU or the CPU
- ottis
Text to speech with a time for every word
- odawg
Music from songs as data: synths, sampled instruments, an 808, a 909 and a 303, mixed and mastered
- onimite
Videos from Lua scripts, written by you or your coding agent