Skip to content

Commit

Permalink
fix(toPoints): read consecutive moveTo commands ad lineTo
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
colinmeinke committed Dec 17, 2017
1 parent 078195f commit 643a905
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/toPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,25 @@ const getPointsFromPath = ({ d }) => {
const upperCaseCommand = command.toUpperCase()
const commandLength = commandLengths[ upperCaseCommand ]
const relative = isRelative(command)
const prevPoint = i === 0 ? null : points[ points.length - 1 ]

if (commandLength > 0) {
const commandParams = params.shift()
const iterations = commandParams.length / commandLength

for (let j = 0; j < iterations; j++) {
const prevPoint = points[ points.length - 1 ] || { x: 0, y: 0 }

switch (upperCaseCommand) {
case 'M':
const x = (relative && prevPoint ? prevPoint.x : 0) + commandParams.shift()
const y = (relative && prevPoint ? prevPoint.y : 0) + commandParams.shift()

moveTo = { x, y }
const x = (relative ? prevPoint.x : 0) + commandParams.shift()
const y = (relative ? prevPoint.y : 0) + commandParams.shift()

points.push({ x, y, moveTo: true })
if (j === 0) {
moveTo = { x, y }
points.push({ x, y, moveTo: true })
} else {
points.push({ x, y })
}

break

Expand Down Expand Up @@ -245,6 +249,8 @@ const getPointsFromPath = ({ d }) => {
}
}
} else {
const prevPoint = points[ points.length - 1 ] || { x: 0, y: 0 }

if (prevPoint.x !== moveTo.x || prevPoint.y !== moveTo.y) {
points.push({ x: moveTo.x, y: moveTo.y })
}
Expand Down

0 comments on commit 643a905

Please sign in to comment.