/** * @upsetjs/react * https://github.com/upsetjs/upsetjs * * Copyright (c) 2021 Samuel Gratzl */ import { IArcSlice, IEllipse, ICircle, isEllipse, IUniverseSet } from './interfaces'; export function generateUniverseSetPath(l: IUniverseSet, refs: readonly (ICircle | IEllipse)[]) { const { width: w, height: h, x1, y1 } = l; const arcs = l.arcs .map((arc) => { const ref = refs[arc.ref]; const rx = isEllipse(ref) ? ref.rx : ref.r; const ry = isEllipse(ref) ? ref.ry : ref.r; const rot = isEllipse(ref) ? ref.rotation : 0; return `A ${rx} ${ry} ${rot} ${arc.large ? 1 : 0} ${arc.sweep ? 1 : 0} ${arc.x2} ${arc.y2}`; }) .join(' '); return y1 < h / 2 ? `M 0 0 L ${x1} 0 L ${x1} ${y1} ${arcs} L ${x1} 0 L ${w} 0 L ${w} ${h} L 0 ${h} Z` : `M ${w} ${h} L ${x1} ${h} L ${x1} ${y1} ${arcs} L ${x1} ${h} L 0 ${h} L 0 0 L ${w} 0 Z`; } export function generateArcSlicePath(s: IArcSlice, refs: readonly { l: ICircle | IEllipse }[], p = 0) { if (s.path) { return s.path; } return `M ${s.x1 - p},${s.y1 - p} ${s.arcs .map((arc) => { const ref = refs[arc.ref].l; const rx = isEllipse(ref) ? ref.rx : ref.r; const ry = isEllipse(ref) ? ref.ry : ref.r; const rot = isEllipse(ref) ? ref.rotation : 0; return `A ${rx - p} ${ry - p} ${rot} ${arc.large ? 1 : 0} ${arc.sweep ? 1 : 0} ${arc.x2 - p} ${arc.y2 - p}`; }) .join(' ')}`; }