import { PathBuilder } from './PathBuilder'
describe('PathBuilder', () => {
describe('toSvg', () => {
it('should build an SVG path', () => {
const path = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 100, 100)
.toSvg({ strokeWidth: 1, style: 'solid' })
expect(path).toMatchInlineSnapshot(`
`)
const closed = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.close()
.toSvg({ strokeWidth: 1, style: 'solid' })
expect(closed).toMatchInlineSnapshot(`
`)
})
it('should support dashed paths', () => {
const path = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.toSvg({ strokeWidth: 1, style: 'dashed' })
expect(path).toMatchInlineSnapshot(`
`)
const closed = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.close()
.toSvg({ strokeWidth: 1, style: 'dashed' })
expect(closed).toMatchInlineSnapshot(`
`)
})
it('should support draw paths', () => {
const path = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.toSvg({ strokeWidth: 10, style: 'draw', randomSeed: '123' })
expect(path).toMatchInlineSnapshot(`
`)
const closed = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.close()
.toSvg({ strokeWidth: 10, style: 'draw', randomSeed: '123' })
expect(closed).toMatchInlineSnapshot(`
`)
})
})
describe('toGeometry', () => {
it('should combine multiple lineTos into a single line', () => {
const geometry = new PathBuilder()
.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(100, 0)
.circularArcTo(50, false, false, 0, 100)
.close()
.toGeometry()
expect(geometry?.toSimpleSvgPath()).toMatchInlineSnapshot(
`"M0,0L100,100L100,0L84.92197106154207,-11.50593202657044L67.93757691512266,-18.409491194065584L50.000000178767834,-20.71067750830319L32.06242347050369,-18.409490975101022L15.078029408356239,-11.505931600276853L6.103515630684342e-7,6.103515559630068e-7L-11.505931600276849,15.078029408356231L-18.409490975101022,32.062423470503674L-20.710677508303192,50.00000017876782L-18.409491194065588,67.93757691512262L-11.50593202657045,84.92197106154204L-1.4210854715202004e-14,99.99999999999999L0,0Z"`
)
})
})
})