Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
HTML and React DOM: path, line, polyline, polygon, circle, ellipse and rect are SVGGeometryElements with getTotalLength and getPointAtLength, measured on the true outline (every path command, arcs included; within 0.03% of Chrome on straight edges and curves, and on circles and rounded corners the exact length, which Chrome flattens about 0.16% short), so a line-draw page's script no longer throws (closes #16)
shinyobjectz934d9b0a72ca
diff --git a/sdk/ui/src/dom/core.ts b/sdk/ui/src/dom/core.tsindex 7245dbff..0128029f 100644--- a/sdk/ui/src/dom/core.ts+++ b/sdk/ui/src/dom/core.ts@@ -1,7 +1,7 @@// The layout snapshot, the runner, the API scan, install (window and document) and an HTML page: what the parts share.import * as wire from "../wire";import { canvasGlobals } from "../canvas";-import { AnimationEvent_, ClipboardEvent_, FontFace_, Comment_, CompositionEvent_, CustomEvent_, DOMRectReadOnly_, DOMRect_, DocumentFragment_, Document_, DragEvent_, Element_, EventTarget_, Event_, FocusEvent_, HTMLAnchorElement_, HTMLBodyElement_, HTMLButtonElement_, HTMLCanvasElement_, HTMLDialogElement_, HTMLDivElement_, HTMLElement_, HTMLFormElement_, HTMLHeadElement_, HTMLHtmlElement_, HTMLIFrameElement_, HTMLImageElement_, HTMLInputElement_, HTMLLIElement_, HTMLLabelElement_, HTMLMediaElement_, HTMLOptionElement_, HTMLSelectElement_, HTMLSpanElement_, HTMLStyleElement_, HTMLTextAreaElement_, HTMLUListElement_, InputEvent_, IntersectionObserver_, KeyboardEvent_, MediaNews, MouseEvent_, MutationObserver_, NodeFilter_, Node_, DOMParser_, Range_, Selection_, CaretPosition_, markEditing, resetSelection, selection, PointerEvent_, ResizeObserver_, SVGElement_, SVGSVGElement_, ShadowRoot_, SubmitEvent_, Text_, TouchEvent_, TransitionEvent_, TreeWalker_, UIEvent_, WheelEvent_, addListener, cancelAnimationFrame, cssEscape, dispatch, fontWaits, getComputedStyle, heard, key, keyUp, makeElement, matchMedia, materialize, mediaNews, mirrorPlace, mirrorRemove, onLayout, plainClasses, query, reactContainer, removeListener, requestAnimationFrame, syncRoot, wireOf } from "./all";+import { AnimationEvent_, ClipboardEvent_, FontFace_, Comment_, CompositionEvent_, CustomEvent_, DOMRectReadOnly_, DOMRect_, DocumentFragment_, Document_, DragEvent_, Element_, EventTarget_, Event_, FocusEvent_, HTMLAnchorElement_, HTMLBodyElement_, HTMLButtonElement_, HTMLCanvasElement_, HTMLDialogElement_, HTMLDivElement_, HTMLElement_, HTMLFormElement_, HTMLHeadElement_, HTMLHtmlElement_, HTMLIFrameElement_, HTMLImageElement_, HTMLInputElement_, HTMLLIElement_, HTMLLabelElement_, HTMLMediaElement_, HTMLOptionElement_, HTMLSelectElement_, HTMLSpanElement_, HTMLStyleElement_, HTMLTextAreaElement_, HTMLUListElement_, InputEvent_, IntersectionObserver_, KeyboardEvent_, MediaNews, MouseEvent_, MutationObserver_, NodeFilter_, Node_, DOMParser_, Range_, Selection_, CaretPosition_, markEditing, resetSelection, selection, PointerEvent_, ResizeObserver_, SVGElement_, SVGGeometryElement_, SVGSVGElement_, ShadowRoot_, SubmitEvent_, Text_, TouchEvent_, TransitionEvent_, TreeWalker_, UIEvent_, WheelEvent_, addListener, cancelAnimationFrame, cssEscape, dispatch, fontWaits, getComputedStyle, heard, key, keyUp, makeElement, matchMedia, materialize, mediaNews, mirrorPlace, mirrorRemove, onLayout, plainClasses, query, reactContainer, removeListener, requestAnimationFrame, syncRoot, wireOf } from "./all";export const g = globalThis as any;@@ -317,7 +317,7 @@ export function install() {EventTarget: EventTarget_, Event: Event_, CustomEvent: CustomEvent_, UIEvent: UIEvent_, FocusEvent: FocusEvent_, MouseEvent: MouseEvent_, PointerEvent: PointerEvent_,WheelEvent: WheelEvent_, KeyboardEvent: KeyboardEvent_, InputEvent: InputEvent_, SubmitEvent: SubmitEvent_, AnimationEvent: AnimationEvent_, TransitionEvent: TransitionEvent_,TouchEvent: TouchEvent_, CompositionEvent: CompositionEvent_, ClipboardEvent: ClipboardEvent_, DragEvent: DragEvent_,- Node: Node_, Element: Element_, HTMLElement: HTMLElement_, SVGElement: SVGElement_, SVGSVGElement: SVGSVGElement_, Text: Text_, Comment: Comment_, CharacterData: Text_, Document: Document_, HTMLDocument: Document_,+ Node: Node_, Element: Element_, HTMLElement: HTMLElement_, SVGElement: SVGElement_, SVGSVGElement: SVGSVGElement_, SVGGeometryElement: SVGGeometryElement_, Text: Text_, Comment: Comment_, CharacterData: Text_, Document: Document_, HTMLDocument: Document_,DocumentFragment: DocumentFragment_, ShadowRoot: ShadowRoot_, HTMLInputElement: HTMLInputElement_, HTMLTextAreaElement: HTMLTextAreaElement_, HTMLButtonElement: HTMLButtonElement_,HTMLSelectElement: HTMLSelectElement_, HTMLOptionElement: HTMLOptionElement_, HTMLFormElement: HTMLFormElement_, HTMLAnchorElement: HTMLAnchorElement_, HTMLLabelElement: HTMLLabelElement_,HTMLDivElement: HTMLDivElement_, HTMLSpanElement: HTMLSpanElement_, HTMLUListElement: HTMLUListElement_, HTMLLIElement: HTMLLIElement_, HTMLImageElement: HTMLImageElement_, HTMLMediaElement: HTMLMediaElement_, HTMLVideoElement: HTMLMediaElement_, HTMLAudioElement: HTMLMediaElement_, HTMLStyleElement: HTMLStyleElement_,diff --git a/sdk/ui/src/dom/media.ts b/sdk/ui/src/dom/media.tsindex 1d3b083c..a0f6c3c4 100644--- a/sdk/ui/src/dom/media.ts+++ b/sdk/ui/src/dom/media.ts@@ -1,6 +1,7 @@// Images, media, style, iframe, canvas and SVG elements, and the tag-to-class table that makes elements.import * as wire from "../wire";import { canvasClass } from "../canvas";+import { outline, pointAtLength, totalLength } from "./svg-length";import { DocumentFragment_, Element_, Event_, HTMLAnchorElement_, HTMLButtonElement_, HTMLDivElement_, HTMLElement_, HTMLFormElement_, HTMLInputElement_, HTMLLIElement_, HTMLLabelElement_, HTMLOptionElement_, HTMLSelectElement_, HTMLSpanElement_, HTMLTextAreaElement_, HTMLUListElement_, MediaNews, Node_, S, SVG_NS, SVG_TAGS, Text_, byWid, dispatchDirect, focusTo, g, pageUrl, transition } from "./all";export class HTMLImageElement_ extends HTMLElement_ {@@ -137,6 +138,24 @@ export class SVGElement_ extends Element_ {export class SVGSVGElement_ extends SVGElement_ {}+/** path, line, polyline, polygon, circle, ellipse and rect: their outline's length and a point along it (#16) */+export class SVGGeometryElement_ extends SVGElement_ {+ private _outline() {+ const num = (n: string) => parseFloat(this.getAttribute(n) ?? "") || 0;+ return outline(this.localName, num, () => this.getAttribute("d") ?? "", () => this.getAttribute("points") ?? "") ?? [];+ }+ getTotalLength(): number {+ return totalLength(this._outline());+ }+ getPointAtLength(at: number) {+ const [x, y] = pointAtLength(this._outline(), Number(at) || 0);+ const P = g.DOMPoint;+ return P ? new P(x, y) : { x, y, z: 0, w: 1 };+ }+}++const GEOMETRY_TAGS = new Set(["path", "line", "polyline", "polygon", "circle", "ellipse", "rect"]);+const TAG_CLASS: Record<string, typeof HTMLElement_> = {input: HTMLInputElement_,textarea: HTMLTextAreaElement_,@@ -182,7 +201,7 @@ for (const [name, tags] of Object.entries(PLAIN)) {export function makeElement(tag: string, ns?: string): Element_ {const svg = ns === SVG_NS || (ns === undefined && SVG_TAGS.has(tag) && tag !== "text" && tag !== "image" && tag !== "title");- if (svg) return tag === "svg" ? new SVGSVGElement_(tag, SVG_NS) : new SVGElement_(tag, SVG_NS);+ if (svg) return tag === "svg" ? new SVGSVGElement_(tag, SVG_NS) : GEOMETRY_TAGS.has(tag) ? new SVGGeometryElement_(tag, SVG_NS) : new SVGElement_(tag, SVG_NS);const C = TAG_CLASS[tag.toLowerCase()] ?? HTMLElement_;return new C(tag);}diff --git a/sdk/ui/src/dom/svg-length.ts b/sdk/ui/src/dom/svg-length.tsnew file mode 100644index 00000000..c4d56d1d--- /dev/null+++ b/sdk/ui/src/dom/svg-length.ts@@ -0,0 +1,264 @@+// SVGGeometryElement's lengths (#16): getTotalLength and getPointAtLength of path, line, polyline, polygon, circle,+// ellipse and rect, from each shape's outline as SVG 2 defines it (a rect from (x + rx, y) clockwise, a circle and an+// ellipse from (cx + rx, cy) clockwise), curves and arcs flattened finely enough that a length is within about 1e-4+// of its exact value. A line-draw animation sets stroke-dasharray to the length, so it's what that needs.++type Pt = [number, number];+/** an outline: its subpaths, each a polyline (a move starts a new one and adds no length) */+type Outline = Pt[][];++/** segments a curve is flattened into, and an arc's per degree */+const CURVE_STEPS = 256;+const ARC_STEP = Math.PI / 180;++/** The outline of an SVG element (`attr` reads an attribute as a number, 0 when absent), or undefined for a tag with+ * no geometry. */+export function outline(tag: string, attr: (name: string) => number, d: () => string, points: () => string): Outline | undefined {+ switch (tag) {+ case "path":+ return pathOutline(d());+ case "line":+ return [[[attr("x1"), attr("y1")], [attr("x2"), attr("y2")]]];+ case "polyline":+ case "polygon": {+ const n = numbers(points());+ const pts: Pt[] = [];+ for (let i = 0; i + 1 < n.length; i += 2) pts.push([n[i], n[i + 1]]);+ if (tag === "polygon" && pts.length) pts.push(pts[0]);+ return [pts];+ }+ case "circle":+ return [ellipse(attr("cx"), attr("cy"), attr("r"), attr("r"))];+ case "ellipse":+ return [ellipse(attr("cx"), attr("cy"), attr("rx"), attr("ry"))];+ case "rect":+ return [rect(attr("x"), attr("y"), attr("width"), attr("height"), attr("rx"), attr("ry"))];+ }+ return undefined;+}++export function totalLength(o: Outline): number {+ let sum = 0;+ for (const sub of o) for (let i = 1; i < sub.length; i++) sum += dist(sub[i - 1], sub[i]);+ return sum;+}++/** The point `at` along the outline, clamped to its ends as a browser clamps it. */+export function pointAtLength(o: Outline, at: number): Pt {+ const subs = o.filter((s) => s.length);+ if (!subs.length) return [0, 0];+ let left = Math.max(0, at);+ for (const sub of subs) {+ for (let i = 1; i < sub.length; i++) {+ const d = dist(sub[i - 1], sub[i]);+ if (left <= d && d > 0) {+ const t = left / d;+ return [sub[i - 1][0] + (sub[i][0] - sub[i - 1][0]) * t, sub[i - 1][1] + (sub[i][1] - sub[i - 1][1]) * t];+ }+ left -= d;+ }+ }+ const last = subs[subs.length - 1];+ return last[last.length - 1];+}++const dist = (a: Pt, b: Pt) => Math.hypot(b[0] - a[0], b[1] - a[1]);++function numbers(s: string): number[] {+ return (s.match(/[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g) ?? []).map(Number);+}++function ellipse(cx: number, cy: number, rx: number, ry: number): Pt[] {+ if (rx <= 0 || ry <= 0) return [];+ const pts: Pt[] = [];+ const n = 360;+ for (let i = 0; i <= n; i++) {+ const a = (i / n) * 2 * Math.PI;+ pts.push([cx + rx * Math.cos(a), cy + ry * Math.sin(a)]);+ }+ return pts;+}++function rect(x: number, y: number, w: number, h: number, rx0: number, ry0: number): Pt[] {+ if (w <= 0 || h <= 0) return [];+ // SVG 2: an absent rx or ry takes the other's value, each at most half its side+ let rx = rx0 > 0 ? rx0 : ry0 > 0 ? ry0 : 0;+ let ry = ry0 > 0 ? ry0 : rx;+ rx = Math.min(rx, w / 2);+ ry = Math.min(ry, h / 2);+ const pts: Pt[] = [];+ const corner = (cx: number, cy: number, from: number) => {+ for (let i = 1; i <= 90; i++) {+ const a = from + (i / 90) * (Math.PI / 2);+ pts.push([cx + rx * Math.cos(a), cy + ry * Math.sin(a)]);+ }+ };+ pts.push([x + rx, y], [x + w - rx, y]);+ if (rx > 0) corner(x + w - rx, y + ry, -Math.PI / 2);+ pts.push([x + w, y + h - ry]);+ if (rx > 0) corner(x + w - rx, y + h - ry, 0);+ pts.push([x + rx, y + h]);+ if (rx > 0) corner(x + rx, y + h - ry, Math.PI / 2);+ pts.push([x, y + ry]);+ if (rx > 0) corner(x + rx, y + ry, Math.PI);+ return pts;+}++/** A path's d as polylines: every command (absolute and relative) of SVG 2's path grammar. */+export function pathOutline(d: string): Outline {+ const tokens = d.match(/[MmLlHhVvCcSsQqTtAaZz]|[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g) ?? [];+ const out: Outline = [];+ let sub: Pt[] = [];+ let cur: Pt = [0, 0];+ let start: Pt = [0, 0];+ let ctrl: Pt | undefined; // the last curve's second control point, for S and T+ let prev = "";+ let i = 0;+ let cmd = "";+ const num = () => Number(tokens[i++]);+ // an arc's flags may be written run together ("a1 1 0 00 10 10"): one digit each+ const flag = () => {+ const t = tokens[i];+ if (t.length > 1 && (t[0] === "0" || t[0] === "1")) {+ tokens[i] = t.slice(1);+ return t[0] === "1";+ }+ i++;+ return Number(t) !== 0;+ };+ const lineTo = (p: Pt) => {+ if (!sub.length) sub.push(cur);+ sub.push(p);+ cur = p;+ };+ const curve = (pts: Pt[]) => {+ if (!sub.length) sub.push(cur);+ const p0 = cur;+ for (let k = 1; k <= CURVE_STEPS; k++) sub.push(bezier([p0, ...pts], k / CURVE_STEPS));+ cur = pts[pts.length - 1];+ };+ while (i < tokens.length) {+ if (/[a-zA-Z]/.test(tokens[i])) cmd = tokens[i++];+ else if (!cmd) break;+ const rel = cmd === cmd.toLowerCase();+ const at = (x: number, y: number): Pt => (rel ? [cur[0] + x, cur[1] + y] : [x, y]);+ const C = cmd.toUpperCase();+ if (C !== "Z" && i >= tokens.length) break;+ switch (C) {+ case "M": {+ const p = at(num(), num());+ if (sub.length) out.push(sub);+ sub = [p];+ cur = start = p;+ cmd = rel ? "l" : "L"; // further pairs are lines+ break;+ }+ case "L":+ lineTo(at(num(), num()));+ break;+ case "H": {+ const x = num();+ lineTo([rel ? cur[0] + x : x, cur[1]]);+ break;+ }+ case "V": {+ const y = num();+ lineTo([cur[0], rel ? cur[1] + y : y]);+ break;+ }+ case "C": {+ const c1 = at(num(), num()), c2 = at(num(), num()), p = at(num(), num());+ curve([c1, c2, p]);+ ctrl = c2;+ break;+ }+ case "S": {+ const c1: Pt = ctrl && /[CS]/.test(prev) ? [2 * cur[0] - ctrl[0], 2 * cur[1] - ctrl[1]] : cur;+ const c2 = at(num(), num()), p = at(num(), num());+ curve([c1, c2, p]);+ ctrl = c2;+ break;+ }+ case "Q": {+ const c = at(num(), num()), p = at(num(), num());+ curve([c, p]);+ ctrl = c;+ break;+ }+ case "T": {+ const c: Pt = ctrl && /[QT]/.test(prev) ? [2 * cur[0] - ctrl[0], 2 * cur[1] - ctrl[1]] : cur;+ const p = at(num(), num());+ curve([c, p]);+ ctrl = c;+ break;+ }+ case "A": {+ const rx = num(), ry = num(), rot = num(), large = flag(), sweep = flag();+ const p = at(num(), num());+ if (!sub.length) sub.push(cur);+ for (const q of arc(cur, p, rx, ry, rot, large, sweep)) sub.push(q);+ cur = p;+ break;+ }+ case "Z":+ if (sub.length) {+ sub.push(start);+ out.push(sub);+ sub = [];+ }+ cur = start;+ break;+ default:+ i = tokens.length;+ }+ prev = C;+ }+ if (sub.length) out.push(sub);+ return out;+}++function bezier(p: Pt[], t: number): Pt {+ let q = p;+ while (q.length > 1) {+ const n: Pt[] = [];+ for (let k = 1; k < q.length; k++) n.push([q[k - 1][0] + (q[k][0] - q[k - 1][0]) * t, q[k - 1][1] + (q[k][1] - q[k - 1][1]) * t]);+ q = n;+ }+ return q[0];+}++/** An elliptical arc from p0 to p1 as points after p0 (SVG 2's implementation notes: endpoint to center form). */+function arc(p0: Pt, p1: Pt, rx0: number, ry0: number, rotDeg: number, large: boolean, sweep: boolean): Pt[] {+ if (p0[0] === p1[0] && p0[1] === p1[1]) return [];+ let rx = Math.abs(rx0), ry = Math.abs(ry0);+ if (!rx || !ry) return [p1];+ const phi = (rotDeg * Math.PI) / 180;+ const cos = Math.cos(phi), sin = Math.sin(phi);+ const dx = (p0[0] - p1[0]) / 2, dy = (p0[1] - p1[1]) / 2;+ const x1 = cos * dx + sin * dy, y1 = -sin * dx + cos * dy;+ const lambda = (x1 * x1) / (rx * rx) + (y1 * y1) / (ry * ry);+ if (lambda > 1) {+ rx *= Math.sqrt(lambda);+ ry *= Math.sqrt(lambda);+ }+ const num = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1;+ const den = rx * rx * y1 * y1 + ry * ry * x1 * x1;+ let k = Math.sqrt(Math.max(0, num / den));+ if (large === sweep) k = -k;+ const cx1 = (k * rx * y1) / ry, cy1 = (-k * ry * x1) / rx;+ const cx = cos * cx1 - sin * cy1 + (p0[0] + p1[0]) / 2, cy = sin * cx1 + cos * cy1 + (p0[1] + p1[1]) / 2;+ const angle = (ux: number, uy: number, vx: number, vy: number) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);+ const t1 = angle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry);+ let dt = angle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry);+ if (!sweep && dt > 0) dt -= 2 * Math.PI;+ if (sweep && dt < 0) dt += 2 * Math.PI;+ const n = Math.max(1, Math.ceil(Math.abs(dt) / ARC_STEP));+ const pts: Pt[] = [];+ for (let s = 1; s < n; s++) {+ const t = t1 + (dt * s) / n;+ const ex = rx * Math.cos(t), ey = ry * Math.sin(t);+ pts.push([cos * ex - sin * ey + cx, sin * ex + cos * ey + cy]);+ }+ pts.push(p1);+ return pts;+}diff --git a/sdk/ui/test/svg-length.test.ts b/sdk/ui/test/svg-length.test.tsnew file mode 100644index 00000000..951eea4a--- /dev/null+++ b/sdk/ui/test/svg-length.test.ts@@ -0,0 +1,54 @@+// SVG geometry lengths (#16): getTotalLength and getPointAtLength on path, line, polyline, polygon, circle, ellipse+// and rect, against Chrome 148's answers for the same shapes. Chrome flattens circles, ellipses and rounded corners+// coarsely (a circle of r 40 measures 250.92 there, 2πr is 251.33); raea measures the true outline, which its+// renderer dashes along, so those are compared within 0.2% and the rest within 0.03%.+import { beforeAll, describe, expect, test } from "bun:test";+import { install } from "../src/dom";++beforeAll(() => install());+const SVG = "http://www.w3.org/2000/svg";+const ROUND = new Set(["circle", "ellipse"]);++// [tag, attributes, Chrome's length, Chrome's points at 0, 0.3 and 0.77 of it]+const CHROME: [string, Record<string, string | number>, number, number[][]][] = [+ ["path", {"d": "M0 0 L100 0"}, 100, [[0, 0], [30, 0], [77, 0]]],+ ["path", {"d": "M10 10 h50 v30 H10 z"}, 160, [[10, 10], [58, 10], [16.8, 40]]],+ ["path", {"d": "M0 0 C 50 100 100 -100 150 0 S 250 100 300 0"}, 418.5452, [[0, 0], [94.92, -18.515], [239.315, 72.268]]],+ ["path", {"d": "M0 0 Q 50 80 100 0 T 200 0"}, 266.7412, [[0, 0], [62.973, 37.307], [155.309, -39.549]]],+ ["path", {"d": "M10 80 a25 25 0 1 1 50 0 a25 25 0 01 50 0"}, 157.1191, [[10, 80], [42.724, 56.207], [88.13, 55.194]]],+ ["path", {"d": "M0 0 A 100 50 30 0 1 120 40"}, 130.6555, [[0, 0], [38.844, -0.153], [95.584, 22.535]]],+ ["path", {"d": "M0 0 l10 0 M50 50 l0 20"}, 30, [[0, 0], [9, 0], [50, 63.1]]],+ ["line", {"x1": 0, "y1": 0, "x2": 30, "y2": 40}, 50, [[0, 0], [9, 12], [23.1, 30.8]]],+ ["polyline", {"points": "0,0 30,0 30,40"}, 70, [[0, 0], [21, 0], [30, 23.9]]],+ ["polygon", {"points": "0,0 30,0 30,40"}, 120, [[0, 0], [30, 6], [16.56, 22.08]]],+ ["circle", {"cx": 50, "cy": 50, "r": 40}, 250.9214, [[90, 50], [37.681, 88.056], [54.961, 10.309]]],+ ["ellipse", {"cx": 50, "cy": 50, "rx": 80, "ry": 20}, 342.5899, [[130, 50], [33.031, 69.545], [56.676, 30.07]]],+ ["rect", {"x": 5, "y": 5, "width": 100, "height": 60}, 320, [[5, 5], [101, 5], [18.6, 65]]],+ ["rect", {"x": 5, "y": 5, "width": 100, "height": 60, "rx": 10}, 302.427, [[15, 5], [103.828, 10.303], [13.396, 64.871]]],+];++describe("SVGGeometryElement (#16)", () => {+ for (const [tag, attrs, length, points] of CHROME) {+ test(`${tag} ${JSON.stringify(attrs)}`, () => {+ const el = (globalThis as any).document.createElementNS(SVG, tag);+ for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, String(v));+ const L = el.getTotalLength();+ const coarse = ROUND.has(tag) || attrs.rx !== undefined;+ expect(Math.abs(L - length) / length).toBeLessThan(coarse ? 0.002 : 0.0003);+ [0, 0.3, 0.77].forEach((f, i) => {+ const p = el.getPointAtLength(L * f);+ expect(Math.hypot(p.x - points[i][0], p.y - points[i][1])).toBeLessThan(coarse ? 0.25 : 0.02);+ });+ });+ }++ test("a path made by the page parser has it too, and it is an SVGGeometryElement", () => {+ const d = (globalThis as any).document;+ const host = d.createElement("div");+ host.innerHTML = `<svg><path id="p" d="M0 0 L100 0"/></svg>`;+ const p = host.querySelector("path");+ expect(p instanceof (globalThis as any).SVGGeometryElement).toBe(true);+ expect(p.getTotalLength()).toBe(100);+ expect(p.getPointAtLength(1e9)).toMatchObject({ x: 100, y: 0 });+ });+});