布尔运算,在多边形$polygon标签上支持,且必须声明multi。多个多边形两两之间进行布尔运算,合减交差(union, diff, intersection, xor)。下面是交集运算前后对比。
csx code
123456789010123456789020123456789030123456789040123456789050123456789060123456
- karas.render(
- <canvas width="360" height="360">
- <$polygon points={[
- [
- [0, 0],
- [0.6, 0],
- [0.6, 0.6],
- [0, 0.6]
- ],
- [
- [0.4, 0.2],
- [1, 0.2],
- [1, 1],
- [0.4, 1]
- ],
- ]} controls={[
- [
- [],
- [0.8, 0.3]
- ],
- ]} multi={true} booleanOperations={['intersection']} style={{
- position: 'absolute',
- left: 20,
- top: 20,
- width: 200,
- height: 200,
- fill: '#F00',
- }}/>
- </canvas>,
- '#example'
- );
- karas.render(
- <svg width="360" height="360">
- <$polygon points={[
- [
- [0, 0],
- [0.6, 0],
- [0.6, 0.6],
- [0, 0.6]
- ],
- [
- [0.4, 0.2],
- [1, 0.2],
- [1, 1],
- [0.4, 1]
- ],
- ]} controls={[
- [
- [],
- [0.8, 0.3]
- ],
- ]} multi={true} style={{
- position: 'absolute',
- left: 20,
- top: 20,
- width: 200,
- height: 200,
- fill: '#F00',
- }}/>
- </svg>,
- '#example2'
- );
karas.render(
<canvas width="360" height="360">
<$polygon points={[
[
[0, 0],
[0.6, 0],
[0.6, 0.6],
[0, 0.6]
],
[
[0.4, 0.2],
[1, 0.2],
[1, 1],
[0.4, 1]
],
]} controls={[
[
[],
[0.8, 0.3]
],
]} multi={true} booleanOperations={['intersection']} style={{
position: 'absolute',
left: 20,
top: 20,
width: 200,
height: 200,
fill: '#F00',
}}/>
</canvas>,
'#example'
);
karas.render(
<svg width="360" height="360">
<$polygon points={[
[
[0, 0],
[0.6, 0],
[0.6, 0.6],
[0, 0.6]
],
[
[0.4, 0.2],
[1, 0.2],
[1, 1],
[0.4, 1]
],
]} controls={[
[
[],
[0.8, 0.3]
],
]} multi={true} style={{
position: 'absolute',
left: 20,
top: 20,
width: 200,
height: 200,
fill: '#F00',
}}/>
</svg>,
'#example2'
);