From d714e9fa5f5ca0ee429e31fdb95127b9c4ac9e4f Mon Sep 17 00:00:00 2001 From: pearmini Date: Sun, 20 Oct 2024 15:58:04 -0400 Subject: [PATCH] Fix group transform without data --- src/shapes/group.js | 2 +- test/apps/spin.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/shapes/group.js b/src/shapes/group.js index c1837388..93989689 100644 --- a/src/shapes/group.js +++ b/src/shapes/group.js @@ -16,7 +16,7 @@ function mergeMatrix(I, PM = [], M = []) { function withTransform({x, y, rotate}, ...flows) { return (raw) => { - const {data, x: px, y: py, rotate: protate, ...rest} = raw ?? {data: [0]}; + const {data = [0], x: px, y: py, rotate: protate, ...rest} = raw ?? {}; const I = Array.from({length: data.length}, (_, i) => i); const transform = (context, _, value) => { const {x: X = [], y: Y = [], rotate: R = []} = value; diff --git a/test/apps/spin.js b/test/apps/spin.js index 4909e47e..169d1f9a 100644 --- a/test/apps/spin.js +++ b/test/apps/spin.js @@ -8,8 +8,11 @@ export function spin() { const t = Date.now() / 1000; return cm.group( cm.background({fill: "white"}), - cm.circle({x: 320, y: 320, r: 120, fill: "black"}), - cm.circle({x: 320 + Math.cos(t) * 200, y: 320 + Math.sin(t) * 200, r: 40, fill: "black"}), + cm.group( + {x: 320, y: 320}, + cm.circle({x: 0, y: 0, r: 120, fill: "black"}), + cm.circle({x: Math.cos(t) * 200, y: Math.sin(t) * 200, r: 40, fill: "black"}), + ), ); }, });