paper.js-offsets
paper.js-offsets copied to clipboard
When uniting, single counter-clockwise path is not a "hole".
With the following test (app.ts/js);
var paper = require('paper-jsdom');
paper.setup([640, 480]);
var toolbox = require('./ToolBox');
var offsett = require('./Offsetting');
//M45, 30c - 5, -10 30, -10 25, 0h5h5l - 10, 5v5c2, 2 5, 10 0, 10v5c0, -10 - 25, -10 - 25, 0v - 5l5, -5l - 10, -10z
var paths = [];
// var path = commonshapes.GetTestShapes(3);
// var path = commonshapes.GetCompoundTestShapes(2);
var path = paper.CompoundPath.importJSON(
["Path",{"applyMatrix":true,"data":{"initialPath":true},"segments":[[[124.83131,885.47614],[3.1821,1.90259],[-1.29606,-0.77492]],[[120.02097,884.61276],[1.86772,-0.13274],[-13.99327,-15.39827]],[[67.42749,856.10551],[21.05726,2.08035],[0.3085,-1.74744]],[[67.46169,850.75252],[0.34597,1.84348],[-1.27408,-6.78883]],[[54.00063,829.78952],[2.43153,7.65975],[-1.91726,-6.03971]],[[52.20613,809.85949],[-0.57089,6.56933],[14.7846,-8.07528]],[[85.32456,776.21597],[-7.90123,13.81057],[3.22984,0.88551]],[[94.64176,779.31437],[-2.85683,-1.08229],[8.06963,3.05712]],[[117.8309,793.54026],[-7.62877,-3.49681],[6.65966,3.0526]],[[137.5791,799.85138],[-5.3162,1.78587],[5.38924,-1.8104]],[[149.84212,782.4286],[-0.66289,6.2448],[0.67872,-6.39397]],[[141.10722,761.87167],[4.02746,6.19904],[-4.09403,-6.3015]],[[125.36605,744.99232],[5.85695,5.21705],[-6.14382,-5.47257]],[[104.92129,729.92608],[6.83789,5.3326],[-0.41903,-0.32678]],[[103.62686,728.94837],[0.44316,0.32515],[4.15666,-14.66501]],[[115.81461,685.21664],[-4.40979,14.09452],[1.52755,-0.62718]],[[119.9513,682.76031],[-1.20507,1.04133],[1.06335,-0.91887]],[[122.53426,679.17237],[-0.69342,1.42413],[4.86308,6.67079]],[[139.14171,696.78245],[-6.35243,-5.04001],[9.75851,7.7424]],[[173.20521,713.10703],[-13.15233,-3.52813],[-15.61577,31.15408]],[[163.60526,814.15354],[-17.27603,-33.11591],[7.78951,14.93148]],[[194.72873,851.88214],[-8.03444,-14.40908],[-4.41966,22.19745]],[[186.87754,919.36582],[4.99495,-21.97296],[-14.08316,1.02249]],[[146.55645,927.11174],[13.47913,-4.08361],[-4.29858,-10.00794]],[[130.82298,898.30481],[6.18879,8.98866],[-0.89019,-5.52435]]],"closed":true,"strokeJoin":"bevel"}]
)
paths.push(path);
// 0 = simplest offset
// 1 = closed path offset
// 2 = openpath turn to stroke // must be posative offsets
var type = 1;
for (var i = -50; i <= -20; i += 1)
{
console.log("doing " + i);
paths = paths.concat(offsett.OffsetPath(paths[0], i, i, type, 0.1, 5));
}
//paths = paths.concat(offsett.OffsetPath(paths[0], 2, -2, type, 0.1, 5));
toolbox.SavePaths(paths, "00", { Multicolor: true, FirstPathBlack: true });
A few of the offsets (like offset -25) are seen as "holes" and removed:

With this line commented out in Offsetting.js :
if (!offsetpaths[0].clockwise) {
// return null;
} // only holes cant be a real thing
The counter-clockwise offset path is shown, with a few addition true 'holes' that are wrong inverted paths:

Maybe the orientation is falsely calculated or we need to perform an additional check if !offsetpaths[0].clockwise
?
thanks.
this is a problem with boolean operators in paper.js, when using path.unite/path.subtract sometimes the resulting path has the wrong orientation.
I've tried to deal with this but without much luck, think we'll have to wait untill paper.js code is fixed for this