import { Shape, Box, Circle, Segment, Arc, Path, Polygon, Point } from '../' import { ShapeTag } from '../classes/Shape' import * as Utils from '../utils/utils' import { convertToString } from '../utils/attributes' import { TAU } from '../utils/constants' export function stringify(shape: Shape, attrs?: Record) { switch (shape.tag) { case ShapeTag.Point: { const point = shape as Point const r = attrs.r ?? 3 return `\n` } case ShapeTag.Arc: { const arc = shape as Arc let largeArcFlag = arc.sweep <= Math.PI ? '0' : '1' let sweepFlag = arc.clockwise ? '1' : '0' if (Utils.EQ(arc.sweep, TAU)) { return stringify(new Circle(arc.pc, arc.r), attrs) } else { return `\n` } } case ShapeTag.Box: { const box = shape as Box const width = box.xmax - box.xmin const height = box.ymax - box.ymin return `\n` } case ShapeTag.Circle: { const circle = shape as Circle return `\n` } case ShapeTag.Path: { const path = shape as Path const start = path.pointAtLength(0) let d = `M${start.x},${start.y} ` for (const part of path.parts) { if (part instanceof Segment) { d += `L${part.end.x},${part.end.y}` } else { throw new Error('unreachable') } } return `` } case ShapeTag.Polygon: { const polygon = shape as Polygon let svgStr = `\n\n` return svgStr } case ShapeTag.Segment: { const segment = shape as Segment return `\n` } default: { throw new Error('unimplemented') } } }