Alexander Deplov

Select path segment on click

Select path segment on click

Code

var bg = new Path.Rectangle({
    size: view.bounds,
    fillColor: 'black'
})

var myline = new Path(new Point(100, 100));
myline.strokeColor = 'red';
myline.strokeWidth = 6;
myline.add(new Point(200, 100));
myline.add(new Point(260, 170));
myline.add(new Point(360, 170));
myline.add(new Point(420, 250));

function onMouseDown(event) {
    hit = paper.project.hitTest(event.point);

    // check if hit is on curve
    if (hit && hit.location) {
        // get curve
        var curve = hit.location.curve;
        // draw selection
        var selection = new Group(
            new Path.Line({
                from: curve.point1,
                to: curve.point2,
                strokeColor: 'blue',
                strokeWidth: 3
            }),
            new Path.Rectangle({
                from: curve.point1 - 5,
                to: curve.point1 + 5,
                fillColor: 'blue'
            }),
            new Path.Rectangle({
                from: curve.point2 - 5,
                to: curve.point2 + 5,
                fillColor: 'blue'
            })
        );
        // make it automatically be removed on next down event
        selection.removeOnDown();
    }
}