Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
steveruizok committed Sep 21, 2021
1 parent 9529e0e commit d3040a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ While `getStroke` returns an array of points representing the outline of a strok
The function below will turn the points returned by `getStroke` into SVG path data.

```js
function getSvgPathFromStroke(points: number[][]): string {
if (!points.length) return ''

return points
.reduce(
(acc, point, i, arr) => {
if (i === points.length - 1)
acc.push(point, Vec.med(point, arr[0]), 'L', arr[0], 'Z')
else acc.push(point, Vec.med(point, arr[i + 1]))
return acc
},
['M', points[0], 'Q']
)
.join(' ')
function getSvgPathFromStroke(stroke) {
if (!stroke.length) return ''

const d = stroke.reduce(
(acc, [x0, y0], i, arr) => {
const [x1, y1] = arr[(i + 1) % arr.length]
acc.push(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2)
return acc
},
['M', ...stroke[0], 'Q']
)

d.push('Z')
return d.join(' ')
}
```

Expand Down
28 changes: 14 additions & 14 deletions packages/perfect-freehand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ While `getStroke` returns an array of points representing the outline of a strok
The function below will turn the points returned by `getStroke` into SVG path data.

```js
function getSvgPathFromStroke(points: number[][]): string {
if (!points.length) return ''

return points
.reduce(
(acc, point, i, arr) => {
if (i === points.length - 1)
acc.push(point, Vec.med(point, arr[0]), 'L', arr[0], 'Z')
else acc.push(point, Vec.med(point, arr[i + 1]))
return acc
},
['M', points[0], 'Q']
)
.join(' ')
function getSvgPathFromStroke(stroke) {
if (!stroke.length) return ''

const d = stroke.reduce(
(acc, [x0, y0], i, arr) => {
const [x1, y1] = arr[(i + 1) % arr.length]
acc.push(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2)
return acc
},
['M', ...stroke[0], 'Q']
)

d.push('Z')
return d.join(' ')
}
```

Expand Down

1 comment on commit d3040a8

@vercel
Copy link

@vercel vercel bot commented on d3040a8 Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.