function drawPolygonBySide({
cx = 0,
cy = 0,
side,
fill = "none",
edges = 3,
rotate = 0,
stroke = `hsl(0, 0%, 5%)`,
strokeWidth = 1,
rotateToFirstEdge = false,
alignY,
v,
t = 0,
shouldRotate360deg
} = {}) {
edges = Math.max(3, edges);
const segmentAngle = (Math.PI * 2) / edges;
const r = side2r(side, segmentAngle);
const animationAngle = shouldRotate360deg ? Math.PI * 2 : segmentAngle;
let dTheta = t * animationAngle + rotate - Math.PI / 2;
if (rotateToFirstEdge) {
dTheta = dTheta + segmentAngle / 2;
}
const innerR = r2innerR(r, segmentAngle);
const dy = v * (alignY - innerR);
const points = d3.range(edges).reduce((acc, i) => {
const angle = i * segmentAngle + dTheta;
const x = cx + r * Math.cos(angle);
const y = cy + r * Math.sin(angle) + dy;
return [...acc, [x, y]];
}, []);
const shape = htl.svg`<path
d=${`M${points.join(" ")}Z`}
fill=${fill}
stroke=${stroke}
stroke-width=${strokeWidth}
stroke-linejoin="round"
/>`;
return Object.assign(shape, { r });
}