Search code examples
paperjs

Corners not connected in paperjs shapes


I am trying to draw some shapes using paperjs using CompoundPath. But the corners of the shapes are not intersecting and there is some space between the segments. For example, if I try to draw a triangle as follows:

var point0 = new Point(448, 217);
var point1 = new Point(110, 565);
var point2 = new Point(785, 565);


console.log(point0);
var path = new CompoundPath({
    children: [
        new Path.Line(point0, point1),
        new Path.Line(point1, point2),
        new Path.Line(point2, point0)
    ]
});
path.strokeWidth = 15;
path.strokeColor = "black";

The corners of this triangle are not connected. Here is the Sketch link for the same: Sketch Link.

How I can make connected corners in these cases?


Solution

  • You don't need to use CompoundPath to connect some lines, you can build a Path including them. Here is a sketch demonstrating the solution.

    var point0 = new Point(448, 217);
    var point1 = new Point(110, 565);
    var point2 = new Point(785, 565);
    
    var path = new Path({
        segments: [
            point0,
            point1,
            point2
        ],
        strokeWidth: 15,
        strokeColor: 'black',
        closed: true
    });