布尔运算,在多边形$polygon标签上支持,且必须声明multi。多个多边形两两之间进行布尔运算,合减交差(union, diff, intersection, xor)。下面是交集运算前后对比。

csx code

123456789010123456789020123456789030123456789040123456789050123456789060123456
  1. karas.render(
  2.   <canvas width="360" height="360">
  3.     <$polygon points={[
  4.       [
  5.         [00],
  6.         [0.60],
  7.         [0.60.6],
  8.         [00.6]
  9.       ],
  10.       [
  11.         [0.40.2],
  12.         [10.2],
  13.         [11],
  14.         [0.41]
  15.       ],
  16.     ]} controls={[
  17.       [
  18.         [],
  19.         [0.80.3]
  20.       ],
  21.     ]} multi={truebooleanOperations={['intersection']} style={{
  22.       position'absolute',
  23.       left20,
  24.       top20,
  25.       width200,
  26.       height200,
  27.       fill'#F00',
  28.     }}/>
  29.   </canvas>,
  30.   '#example'
  31. );
  32. karas.render(
  33.   <svg width="360" height="360">
  34.     <$polygon points={[
  35.       [
  36.         [00],
  37.         [0.60],
  38.         [0.60.6],
  39.         [00.6]
  40.       ],
  41.       [
  42.         [0.40.2],
  43.         [10.2],
  44.         [11],
  45.         [0.41]
  46.       ],
  47.     ]} controls={[
  48.       [
  49.         [],
  50.         [0.80.3]
  51.       ],
  52.     ]}  multi={truestyle={{
  53.       position'absolute',
  54.       left20,
  55.       top20,
  56.       width200,
  57.       height200,
  58.       fill'#F00',
  59.     }}/>
  60.   </svg>,
  61.   '#example2'
  62. );
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'
);