-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boolean subtract with closed: false doesn't work as expected #1221
Comments
Here Sketch 2 for discussion. |
I think there should be options to control how the boolean subtract operation affects the resulting path (This might also be relevant for operations other than subtract, not sure right now). For subtracting I can think of two possible results that make sense, lets name them trace and split. The api could be something like: The naming is just my initial idea and could possibly be better! |
To give a real world example of why I think this is very useful: If you want to remove overlapping/occluded paths (i.e. for pen plotting), the split version makes a lot of sense to prevent drawing any outline more than once, while the trace version is I guess the expected result in the traditional sense! |
the closed flag does not appear to work in develop branch. i rolled all my current boolean ops stuff back to the bower/stable version as that seems to work alright. |
@mokafolio I am still waiting from some test-cases from you here. |
@lehni sorry zoned out on that. I put together a quick thing here to compare the bower paper version vs the current develop: http://stuff.mokafolio.de/DevelopVsBowerBoolean/BowerSubtract.html made a repo here too: https://github.com/mokafolio/PaperJSDevelopVSBowerSubtract The examples take 200 circles and subtract them from back to front. Both appear to perform very similarily, here are 5 results I got for each:
I think the difference in speed that I was seeing in my actual app was due to the open flag that is available in the current bower branch but not working in current develop. My guess is that that flag made it faster, we should re-evaluate it as soon as it works in develop again. That said, I could not get my actual app to work with the develp branch at all (I would love to try again as soon as we have a way to support open paths. I recommend providing an API similar to what I described in the comment with the illustration above). Hope that makes sense! |
In the same way, |
@mokafolio, @niravdhanorkar: I finally found some time to look into this, and it turns out silly me got With that in place, everything already works as it should:
I don't like the naming of the current option all that much though. I also don't think Another question that we still have to decide: Should the results of this split-mode be collected in a I tend to think |
Another possibility is to call the option Thoughts? |
I have implemented all my suggestions now in 3c9d2ee, along with unit tests for them. Let's keep the discussion going regarding terminology and I still need to adjust the docs once this is finalized. |
@lehni Great! I like both, Regarding
Overall I think approach 2 is the better way to go. |
I like approach 2 better too. I wonder what we should do about |
@mokafolio what are your thoughts on |
@lehni I think I like For the |
Actually, since return new Group([
path1.subtract(path2),
path1.intersect(path2)
]); But the problem will be that we're breaking backward compatibility... |
Good call. About backwards compatibility, didn't we already break it multiple times? Boolean operations in the master/bower branch return other things than the current develop branch, so I don't think that should stop us at this point. |
It hasn't stopped us before, so why now : ) |
#divide() with options.trace = false can call splitBoolean() just once without removing any split sub-paths. Relates to #1221
@mokafolio I've implemented this now, and there was a nice simplification in a43db84 I think we're done : ) |
@niravdhanorkar with the latest prebuilt version, you can now pass var path1 = PathItem.create("M534,273C171.7,111,60.5,117.1,30,158c-40.5,54.3,31.5,210.2,111,222c60.8,9,88-71.9,159-66c81.6,6.8,99.6,118.3,179,128c33.8,4.1,83.1-9.7,150-90")
var path2 = new Path.Rectangle({
point: [150, 85],
size: [287, 167]
});
path1.strokeColor = 'red';
path2.strokeColor = 'green';
var res = path1.subtract(path2, { trace: false });
res.position += [0, 300]; |
@lehni Thanks |
@niravdhanorkar please use |
Hi @lehni , e.g. Sometimes I get 4 children, and sometimes 3 children. |
Sketch 1
Result:
Expected:
The text was updated successfully, but these errors were encountered: