Search code examples
htmlkineticjs

Kinectjs line.points returns string and not array?


With version 4.7.4 of kineticjs, I was able to use blob.getPoints() to return the x,y values of each point in the blob.

With version 5.0.1 the equivalent - line.points() returns a string of x,y values. With 4.74 I could determine the max and min bounds easily, however there doesn't seem to be an easy way to do it with 5.0.1

Am I missing something?


Solution

  • line.points() returns 1-d array of coordinates:

    [x1, y1, x2, y2, ..., xn, yn]
    

    if you need {x, y} points:

    var points = line.points();
    for (var i = 0; i < points.length / 2; i++) {
        var point = {
            x : points[i * 2],
            y : points[i * 2 + 1]
        };
        console.log(point);
    };