Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rough-go

rough-go is a native Go port of Rough.js 4.0.4. It creates the same ordered drawing operations and SVG path descriptions without a JavaScript runtime.

The compatibility target is the exact Rough.js implementation embedded by D2: version 4.0.4 at commit 35302b8f1119ad004b4550f9a4d4162d3d845b0a. Later Rough.js releases have behavior-changing renderer and option changes, so they are not the oracle for this module.

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)
	}
}

The full generator surface is ported: line, rectangle, ellipse, circle, linear path, polygon, arc, curve, SVG path, every 4.0.4 fill style, operation serialization, and ToPaths conversion. Pointer-valued option fields preserve the JavaScript distinction between an omitted option and an explicit zero.

Compatibility tests

The regular suite is pure Go:

go test ./...
go test -race ./...
go vet ./...

The optional differential suite runs the Go port against a frozen Rough.js 4.0.4 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.0.4.js go test ./...

Rough.js 4.0.4 did not ship automated tests. Accordingly, rough-go uses source-shaped unit tests, deterministic randomized differential tests, and D2's existing exact sketch SVG goldens.

License

MIT. See LICENSE and NOTICE.

About

Native Go port of Rough.js 4.0.4

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages