import * as vec from "./vec" ; import { getSweep } from "utils" ; import { getBoundsBetweenPoints } from "./bounds-utils" ; import { IBounds } from "./types" ; export function ellipse ( A , r ) { return `M ${ A [ 0 ] - r },${ A [ 1 ] }
      a ${ r },${ r } 0 1,0 ${ r * 2 },0
      a ${ r },${ r } 0 1,0 -${ r * 2 },0 ` ; } export function moveTo ( v ) { return `M ${ v [ 0 ] },${ v [ 1 ] } ` ; } export function lineTo ( v ) { return `L ${ v [ 0 ] },${ v [ 1 ] } ` ; } export function line ( a , ... pts ) { return moveTo ( a ) + pts . map ( ( p ) => lineTo ( p ) ) . join ( ) ; } export function hLineTo ( v ) { return `H ${ v [ 0 ] },${ v [ 1 ] } ` ; } export function vLineTo ( v ) { return `V ${ v [ 0 ] },${ v [ 1 ] } ` ; } param a param b returns export function rectFromBounds ( bounds ) { const { minX , maxX , minY , maxY } = bounds ; return [ moveTo ( [ minX , maxX ] ) , lineTo ( [ maxX , minY ] ) , lineTo ( [ maxX , maxY ] ) , lineTo ( [ minX , minY ] ) , closePath ( ) , ] . join ( " " ) ; } param point param size returns export function rect ( point , size ) { return rectFromBounds ( getBoundsBetweenPoints ( point , vec . add ( point , size ) ) ) ; } export function bezierTo ( A , B , C ) { return `C ${ A [ 0 ] },${ A [ 1 ] } ${ B [ 0 ] },${ B [ 1 ] } ${ C [ 0 ] },${ C [ 1 ] } ` ; } export function arcTo ( C , r , A , B ) { return [ "A" , r , r , 0 , getSweep ( C , A , B ) > 0 ? "1" : "0" , 0 , B [ 0 ] , B [ 1 ] , ] . join ( " " ) ; } export function closePath ( ) { return "Z" ; } export function rectTo ( A ) { return [ "R" , A [ 0 ] , A [ 1 ] ] . join ( " " ) ; } export function getPointAtLength ( path , length ) { const point = path . getPointAtLength ( length ) ; return [ point . x , point . y ] ; }