What is the Best way to Subtract Multiple Times from Existing Path Item.

已查看 87 次
跳至第一个未读帖子

shishir raven

未读,
2021年3月4日 14:07:112021/3/4
收件人 Paper.js
Problem.

A = Path (Existing)
B, C are Paths which I want to subtract from A. 

When I subtract A-B it results in the Path but it gets inserted into the Canvas. 
Then I have to call remove A and insert the resulting Path Again. 
Something Like as shown Below. 

var newCounter = counter.subtract(drawCutouts.children[0]);
counter.remove();
counter.addChild(newCounter);

But I have to actually subtract Multiple Items. 
And I don't want Loop this Remove and Add Cycle. 

Is there any elegant way to do this. Such that I can subtract from the  Current Path. 
And also I don't have to add and remove multiple times. 

Thanks 
Shishir. 

Samuel ASENSI

未读,
2021年3月5日 01:16:522021/3/5
收件人 pap...@googlegroups.com
Hi,

You can set the boolean operation option `insert` to false to avoid the result from being inserted in the scene graph.
Then, you can chain your calls like shown in this sketch.

const circle1 = new Path.Circle({
    center: view.center,
    radius: 50,
    strokeColor: 'orange'
});
const circle2 = circle1.clone().translate(10, 50);
const circle3 = circle1.clone().translate(50, 10);

const subtraction = circle1
    .subtract(circle2, { insert: false })
    .subtract(circle3, { insert: false });
subtraction.addTo(project.activeLayer);
subtraction.selected = true;

project.activeLayer.fitBounds(view.bounds.scale(0.8));

--
You received this message because you are subscribed to the Google Groups "Paper.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paperjs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/paperjs/6008ba25-c7a7-4077-a47a-08dc2fbb9141n%40googlegroups.com.


--
    Samuel ASENSI

shishir raven

未读,
2021年3月8日 10:29:292021/3/8
收件人 pap...@googlegroups.com
Thanks Samuel for pointing me in the right direction. 

Really appreciate that you took time to help me out.👍👍

One small issue was that I cannot chain as the paths I want to subtract are in an Array. 

And so how to chain it is kind of difficult as Array has dynamic number of elements. 

Was hoping if there was something that would subtract and mutate the element itself rather than returning the result. 

But none the less, I learned how to insert back the item when insert = false.

Thanks once again for your help,
Shishir







回复全部
回复作者
转发
0 个新帖子