rough-go is a native Go compatibility port of the
Rough.js 4.6.6 rendering surface used by D2. It creates
the same ordered drawing operations and SVG path descriptions without a
JavaScript runtime.
The compatibility target is Rough.js 4.6.6 at commit
56a2762171b1294d643501e8d14f120db6b27bd7. The port covers D2's generator
methods (line, rectangle, ellipse, linearPath, polygon, and SVG
path) and the solid and zigzag option profiles D2 emits. Other public methods
remain available for source compatibility, but arbitrary expert Rough.js
options outside that profile are not an exact compatibility contract.
package main
import (
"fmt"
rough "github.com/d2lang/rough-go"
)
func main() {
g := rough.NewGenerator(nil)
d := g.Rectangle(0, 0, 120, 60, &rough.Options{
Fill: rough.String("#f6d32d"),
Seed: rough.Float64(1),
})
for _, path := range g.ToPaths(d) {
fmt.Println(path.D)
}
}Pointer-valued option fields preserve the JavaScript distinction between an omitted option and an explicit zero. Rough.js 4.6.6's new dash, multi-stroke, vertex-preservation, fixed-decimal, and fill-roughness options are represented.
The regular suite is pure Go:
go test ./...
go test -race ./...
go vet ./...The optional differential suite runs the Go port against the pristine Rough.js 4.6.6 browser bundle. Node.js is used only by the test oracle; the library has no JavaScript dependency.
ROUGH_GO_ROUGH_JS=/absolute/path/to/rough-4.6.6.js go test ./...The release gate includes 1,000 deterministic randomized D2-profile calls and D2's full sketch SVG suite. Every rough-generated SVG path in that suite matches official Rough.js 4.6.6 after D2's normal six-decimal serialization.