colinmeinke / svg-points

A specification for storing SVG shape data in Javascript, and some handy conversion functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

point index off in toPoints.js?

snorpey opened this issue · comments

hi @colinmeinke,
thank you for creating this library.

i noticed that some of the code in this repo is also used in the wilderness repo (please correct me if i'm wrong).

when trying to display and animate some imported svg paths with wilderness, i'm getting an error in the toPoints (line 161) function: Cannot read property 'xAxisRotation' of undefined.

i'm not 100% certain, but i think the code in this line is referring to the wrong point index. i guess it should refer to the recently added point. instead of points[ i ][ 'curve' ][ k ] i think it should be points[ points.length - 1 ][ 'curve' ][ k ] (or something like this)

again i'm not 100% sure it's just observation, so i'm filing this as an issue, not a pull request.

Thanks for the report. Can you provide your toPoints input SVG shape object, the output points array, and how that differs from the expected output points array?

here's the shape object that is passed into the toPoints function (please excuse the profanity in the image, unfortunately i couldn't reproduce the error with any other path):

        {
            d:"M68.84,167a3.63,3.63,0,0,1,.33-1.76c1.11-1.07,2.42-2.8,3.61-2.76,2.26,0.07,2.68,2.32,1.8,4a17.48,17.48,0,0,1-4.07,5c-4.62,3.93-10.36,5-16.16,5.88-2.54.38-5.05,1-8.14,1.6,0.86,1.07,1.47,1.48,1.55,2,0.24,1.41.88,3.45,0.22,4.14a6.33,6.33,0,0,1-4.55,1.57c-0.92-.06-2.55-2-2.43-2.83,0.32-2.36,1.45-4.61,2.18-6.93,0.45-1.42,1.3-3,1-4.32-0.9-4.71-2.2-9.34-3.35-14l-1.21-.16c-0.31,1.21-.6,2.42-0.92,3.62s-0.35,2.95-1.18,3.66-2.95.7-3.53,0.09c-0.9-.95-1.72-3.07-1.24-4,1.35-2.66,3.41-5,5.12-7.44,0.68-1,1.77-2.2,1.65-3.19-0.58-4.78-1.54-9.51-2.31-14.27a3.19,3.19,0,0,0-3.15-3.06c-2.73-.38-4.63-2-4.57-5.12A3.94,3.94,0,0,1,33,124.5c2.75-.46,3.95,1.31,4.67,4.21,3.79-2.34,7.37-4.57,11-6.77,4.86-3,9.7-6,14.59-8.91,4.34-2.59,7.19-2.22,9.34,1.32,0.65,1.07.61,2.57,0.89,3.86,4.65-1.28,7.34-.18,10.1,4.15,1.76,2.76,3.59,5.49,5.58,8.08a4.2,4.2,0,0,0,2.73,1.14c1.62,0.15,3.28-.17,4.91-0.06a4.21,4.21,0,0,1,4.13,4.64c0,1.23-1.5,2.7-2.7,3.45-0.42.26-2-1.24-3-2a15,15,0,0,1-1.66-1.9l-1.17.92L102.42,154c2.51-.52,4.21-1.28,5.73-1,0.79,0.14,1.83,2.13,1.76,3.21-0.14,2.2-1,4.66-3.76,4.53a7.21,7.21,0,0,1-4.86-2.07,145.91,145.91,0,0,1-8.41-12.08c-1.43-2.2-2.48-4.64-3.78-6.93-1.65-2.9-3.42-3.52-6.39-1.82a13.93,13.93,0,0,0-5,4.17c-1.78,2.88-4.12,3.24-7,2.85-3.57-.49-4,0-3.81,3.6,0.29,5.26.49,10.52,0.74,15.77,0,0.92.18,1.84,0.27,2.76Zm-10.61-45.9c-6,3.69-11.4,6.87-16.62,10.25a3.35,3.35,0,0,0-.81,2.8q1.15,6.64,2.69,13.2c0.29,1.23,1.31,3.32,1.85,3.28a13.94,13.94,0,0,0,6.28-1.76,64.21,64.21,0,0,0,8-6.63c0.77-.7,1.74-1.91,1.62-2.75C60.39,133.5,59.32,127.59,58.23,121.06Zm-13.15,34.1,4.47,19.08L64,170.55l-2.49-24.27A9.12,9.12,0,0,0,55,152.17c-1.06,2.54-2.62,4.29-5.85,3C48.12,154.83,46.83,155.16,45.07,155.16Zm40.4-22.61-6.24-9c-2.19,1-4.19,2.56-5,2.09-1.43-.79-2.13-2.9-3.46-5-2.23.2-4.14-1.33-5.17-4.68-1.11,1.23-2.31,2.55-2.2,3.76,0.54,5.87,1.4,11.72,2.22,17.56,0.42,3,4.37,4.5,6.42,2.26C75.52,135.78,80,134.11,85.48,132.55Z M254.91,142.87c-1.13-9.27-9.56-15.86-16.42-17.81-0.66-.19-2.1.73-2.48,1.48-2.61,5.19-5.12,10.43-7.42,15.76-0.31.72,0.42,2.41,1.18,3,4.69,3.55,10,6.45,14.17,10.48,2.76,2.64,4.36,6.69,5.84,10.37,0.53,1.31-.37,3.83-1.46,5-4.82,5.36-11,7.87-18.06,5.79-9.89-2.9-19.75-6.3-27.47-13.46-3.62-3.35-6.21-7.81-9.23-11.79a22.54,22.54,0,0,0-1.85-2.57c-0.15,2.63-.54,5-3.7,4.67-1.19-.12-3.25-1.36-3.22-2,0.12-2.12.47-4.69,1.78-6.11,1-1,3.61-.88,5.45-0.71,2.46,0.22,5,1.79,6.69-1.57,0.28-.55,2.23-0.24,3.41-0.33,0,1.63.51,3.56-.18,4.82s-2.58,1.76-4.21,2.77c3,5.11,6.66,9.58,11.92,12.63,1.45,0.84,2.59.95,3.53-.76,2.94-5.37,5.94-10.71,9.11-16.41a51,51,0,0,0-5.67-2.66,23.33,23.33,0,0,1-12.63-10c-4.7-7.29-1.38-16.25,8.14-17.39,6.21-.75,12.8.89,19.11,2,3.58,0.65,7,2.39,10.4,3.79,9.9,4,15.89,11.33,18,21.81,0.09,0.43.22,0.84,0.35,1.26a3,3,0,0,0,.35.49,6.86,6.86,0,0,1,1.72-1.19c1.32-.41,3.6-1.22,3.9-0.78a7.47,7.47,0,0,1,1.46,4.92c-0.17,1-2.31,2.58-3.43,2.47a27.26,27.26,0,0,1-7.51-2.18,3.91,3.91,0,0,0-4.64.62c-2.28,1.88-5.11.92-5.75-1.68-0.55-2.24.1-4,2.64-4.36C250.78,143,252.85,143,254.91,142.87Zm-38.65,23.39c5.28,2.33,10.2,4.68,15.26,6.65a8.11,8.11,0,0,0,5.46.27c2.71-1.1,5.84-2.51,7.4-4.75,1.86-2.67.42-6.19-1.83-8.4a96.18,96.18,0,0,0-10.31-8.48,54.63,54.63,0,0,0-6.49-3.6ZM233,123.09a43,43,0,0,0-20.51-2.83,7.14,7.14,0,0,0-2.16.76c-4.38,2-5.51,5.76-3.11,10,3.73,6.55,10.3,8.55,16.74,11Z M121.22,142.5c-0.43,1.67-.37,3.62-1.22,4.18-1,.66-3.42.71-4.13,0a6.22,6.22,0,0,1-1.29-4.62c0.34-2.51,2.31-3.89,4.86-4.17,1.51-.17,3-0.2,4.54-0.29l-0.69-.81c1.13-1.36,2.06-3,3.48-3.92,0.57-.35,2.7.75,3.28,1.71,1.3,2.13-.17,4.82-4.34,8.07,2,1.23,3.59,2.83,5.48,3.29,5,1.22,10.1,1.94,15.16,2.87,1.83,0.33,2.63-.39,2.62-2.27,0-4.83,0-9.66.14-14.48,0.07-2.41-1.41-2.42-3.17-2.69-5-.76-9.94-1.6-14.85-2.67a12.54,12.54,0,0,1-8.85-7.29,13.69,13.69,0,0,1-1-7.81,24.42,24.42,0,0,1,3.88-8.85c0.95-1.37,3.37-2.28,5.19-2.4,9-.59,18.16-2.25,27.17-0.06,9.18,2.23,17.51,6.16,23.68,14,0.1-.83-0.09-2,0.34-2.31A11,11,0,0,1,186,110c0.4-.05,1.71,2.34,1.57,3.48-0.6,4.68-3.38,6.26-8,4.92-1.15-.33-2.28-0.71-3.28-1a4.31,4.31,0,0,0-.71.5,23.42,23.42,0,0,1-3.12,3.58c-0.41.32-2.44-.46-2.46-0.81a10.3,10.3,0,0,1,.56-5c0.6-1.22,2.26-1.91,3.74-3.06a49.56,49.56,0,0,0-21.7-9c0,4.28-.27,8.29.05,12.26,0.81,9.82.93,9.81,10.69,11.22,2.92,0.43,5.86.83,8.75,1.42a6.58,6.58,0,0,1,5.36,5.21c1.91,8.18.37,14.42-8.53,17.34A50.87,50.87,0,0,1,141,152.17c-1.6-.36-3.25-0.46-4.86-0.78C130,150.21,124.09,148.68,121.22,142.5Zm28-17.19c-0.5-7.17-.85-13.51-1.49-19.81a3.35,3.35,0,0,0-2.6-2,106.79,106.79,0,0,0-13,1.35c-3.71.66-7.17,5.67-7.19,9.61,0,3.17,3.19,6.69,7.08,7.74,3,0.8,5.88,1.72,8.88,2.28C143.39,125,146,125,149.21,125.32Zm5.2,4.85c-0.43,5.72-.72,10.84-1.25,15.94-0.28,2.71.94,3.87,3.32,3.4,3.72-.72,7.34-2,11.06-2.78,4.84-1,5.69-4.22,5.55-8.48-0.17-5.11-.59-5.66-5.79-6.28-3-.36-6-1-9.06-1.47C157,130.31,155.72,130.28,154.42,130.16Z",
            type:"path"
        }

due to the to the error, i'm not getting any output.

I've narrowed the error down to this shape:

{
  d: "m-38.65,23.39c5.28,2.33,10.2,4.68,15.26,6.65a8.11,8.11,0,0,0,5.46.27c2.71-1.1,5.84-2.51,7.4-4.75,1.86-2.67.42-6.19-1.83-8.4a96.18,96.18,0,0,0-10.31-8.48,54.63,54.63,0,0,0-6.49-3.6ZM233,123.09a43,43,0,0,0-20.51-2.83,7.14,7.14,0,0,0-2.16.76c-4.38,2-5.51,5.76-3.11,10,3.73,6.55,10.3,8.55,16.74,11Z",
  type: "path"
}

@snorpey you were totally right, thanks for the catch!