points = function (line) {
let current = { points: [[0,0]], bbox: [] };
let mover = {
"R" : (o, offset) => {
return {
points: Array(offset).fill().map((v, i) => [o[0]+i+1,o[1]]),
bbox: [o,[o[0]+offset,o[1]]]
}},
"L" : (o, offset) => {
return {
points: Array(offset).fill().map((v, i) => [o[0]-i-1,o[1]]),
bbox: [[o[0]-offset,o[1]],o]
}},
"U" : (o, offset) => {
return {
points: Array(offset).fill().map((v, i) => [o[0],o[1]+i+1]),
bbox: [o,[o[0],o[1]+offset]]
}},
"D" : (o, offset) => {
return {
points: Array(offset).fill().map((v, i) => [o[0],o[1]-i-1]),
bbox: [[o[0],o[1]-offset],o]
}}
}
let points = line.map ( move => {
current = mover[move.slice(0,1)](current.points[current.points.length-1], move.slice(1)*1.0);
return current
}, [])
return points
}