Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: ci

on: [push, pull_request]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- uses: actions/setup-node@v6
with:
node-version: 24
- name: Fetch frozen Rough.js oracle
run: |
curl --fail --location --silent --show-error \
https://registry.npmjs.org/roughjs/-/roughjs-4.0.4.tgz \
--output "$RUNNER_TEMP/roughjs-4.0.4.tgz"
mkdir "$RUNNER_TEMP/roughjs-4.0.4"
tar -xzf "$RUNNER_TEMP/roughjs-4.0.4.tgz" \
-C "$RUNNER_TEMP/roughjs-4.0.4"
echo "21f8682b994c6063e9605a19f50a6bd9f3b0901cbff4db2326b3f85308e29b7f $RUNNER_TEMP/roughjs-4.0.4/package/bundled/rough.js" \
| sha256sum --check
- name: Test
env:
ROUGH_GO_ROUGH_JS: ${{ runner.temp }}/roughjs-4.0.4/package/bundled/rough.js
ROUGH_GO_DIFFERENTIAL_CALLS: "1000"
run: go test ./...
- run: go test -race ./...
- run: go vet ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage.out
*.test
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2019 Preet Shihn
Copyright (c) 2026 rough-go contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rough-go is a Go port of Rough.js 4.0.4.

Upstream source:
Project: Rough.js
Version: 4.0.4
Commit: 35302b8f1119ad004b4550f9a4d4162d3d845b0a
Repository: https://github.com/rough-stuff/rough
License: MIT
Copyright (c) 2019 Preet Shihn

Compatibility is measured against the Rough.js bundle embedded by D2, whose
SHA-256 is 5601a7c6046815613316d882ffbaede24261bfec295e3502ae7539abb1814820.
The pristine Rough.js 4.0.4 browser bundle has SHA-256
21f8682b994c6063e9605a19f50a6bd9f3b0901cbff4db2326b3f85308e29b7f.

No Rough.js JavaScript is linked into or executed by rough-go. The Go source is
a translation and remains available under the MIT license in LICENSE.
23 changes: 23 additions & 0 deletions PROVENANCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Source provenance

rough-go is a source-shaped Go translation of Rough.js 4.0.4.

| Source | Version / commit | License | Relevant files |
| --- | --- | --- | --- |
| Rough.js | 4.0.4 / `35302b8f1119ad004b4550f9a4d4162d3d845b0a` | MIT | `src/core.ts`, `geometry.ts`, `math.ts`, `path.ts`, `renderer.ts`, `generator.ts`, `rough.ts`, `canvas.ts`, `svg.ts`, and `src/fillers/*.ts` |

The pristine npm browser bundle has SHA-256
`21f8682b994c6063e9605a19f50a6bd9f3b0901cbff4db2326b3f85308e29b7f`.
The npm tarball has SHA-1 `31db3cc9654e7012a5d5701c6234f7601a14d720`
and integrity
`sha512-rXmMGcALUlYIFKBbn9aWuxznPKOtnx9bouVC407/uneUNx0mT/4Mo2Z4TUieoCOT+rWmHnOQqVT1FvoN+L3baA==`.

D2's frozen oracle bundle has SHA-256
`5601a7c6046815613316d882ffbaede24261bfec295e3502ae7539abb1814820`.
D2 reformatted and unwrapped the browser bundle, replaced deprecated regular
expression statics with local matches, and replaced exponentiation syntax with
`Math.pow`. Its later quoted-string typo correction is behaviorally inert. The
layout and renderer algorithms remain Rough.js 4.0.4.

Every translated Go source file carries an SPDX MIT identifier and the upstream
copyright attribution. The complete applicable license is in `LICENSE`.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# rough-go

`rough-go` is a native Go port of [Rough.js](https://roughjs.com/) 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.

```go
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:

```sh
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.

```sh
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](LICENSE) and [NOTICE](NOTICE).
Loading