-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error computing cubic Bézier curves bounding boxes (#95)
* Fix error computing bounding boxes with cubic Bézier commands * Refactor * Bump version * Minor change * Refactor in tests * Minor change
- Loading branch information
Showing
9 changed files
with
50 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ deps.txt | |
emsdk | ||
*.wasm | ||
*.tgz | ||
/*.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,26 @@ | ||
import { jest } from "@jest/globals"; | ||
import { linealCases, pathologicalCases } from "./cases/bbox"; | ||
import cases from "./cases/bbox"; | ||
import type { BBox } from "../src"; | ||
|
||
jest.retryTimes(3); | ||
jest.setTimeout(2000); | ||
|
||
const rounding = 5; | ||
|
||
const round = (num: number): number => { | ||
const result = parseFloat(num.toFixed(rounding)); | ||
return result == 0 ? 0 : result; | ||
}; | ||
|
||
describe("Consistency with browser's element.getBBox()", () => { | ||
beforeAll(async () => { | ||
await page.goto("http://localhost:8080"); | ||
}); | ||
|
||
const cases = [...linealCases, ...pathologicalCases]; | ||
|
||
test.each(cases)( | ||
"browserSvgPathBbox(%p) ⇢ %p", | ||
async (d: string, libBbox: BBox) => { | ||
const browserBbox = await page.evaluate( | ||
(d, rounding) => { | ||
const round = (num: number): number => | ||
parseFloat(num.toFixed(rounding)); | ||
const browserBbox = await page.evaluate((d) => { | ||
document.body.innerHTML = `<svg width="800" height="800"><path d="${d}"/></svg>`; | ||
const bbox = ( | ||
document.querySelector("path") as SVGPathElement | ||
).getBBox(); | ||
return [bbox.x, bbox.y, bbox.x + bbox.width, bbox.y + bbox.height]; | ||
}, d); | ||
|
||
document.body.innerHTML = | ||
`<svg width="800" height='800'>` + | ||
`<path fill='black' d="${d}"/></svg>`; | ||
const bbox = ( | ||
document.querySelector("path") as SVGPathElement | ||
).getBBox(); | ||
return [ | ||
round(bbox.x), | ||
round(bbox.y), | ||
round(bbox.x + bbox.width), | ||
round(bbox.y + bbox.height), | ||
]; | ||
}, | ||
d, | ||
rounding | ||
); | ||
expect(browserBbox).toEqual(libBbox.map((num) => round(num))); | ||
expect(browserBbox[0]).toBeCloseTo(libBbox[0], 3); | ||
expect(browserBbox[1]).toBeCloseTo(libBbox[1], 3); | ||
expect(browserBbox[2]).toBeCloseTo(libBbox[2], 3); | ||
expect(browserBbox[3]).toBeCloseTo(libBbox[3], 3); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as fs from "node:fs"; | ||
|
||
test("Latest version has a CHANGELOG entry", () => { | ||
const changelog = fs.readFileSync("CHANGELOG.md", "utf8"); | ||
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")); | ||
|
||
const changelogEntry = changelog | ||
.split("\n") | ||
.find((line: string) => line.startsWith(`## [${packageJson.version}]`)); | ||
expect(changelogEntry).toBeDefined(); | ||
}); |