1

我使用 js-angusj-clipper。我有三个正方形。他们的立场是这样的。我让他们执行交集操作,但我无法得到正确的结果。我的代码如下:

    this._clipper = await loadNativeClipperLibInstanceAsync(
      NativeClipperLibRequestedFormat.WasmWithAsmJsFallback,
    );

    const group = [[[
            {
                "x": 141.88,
                "y": 177.22
            },
            {
                "x": 229.06,
                "y": 177.22
            },
            {
                "x": 229.06,
                "y": 60.62
            },
            {
                "x": 141.88,
                "y": 60.62
            }
        ],[
            {
                "x": 113.12,
                "y": 196.81
            },
            {
                "x": 190.58,
                "y": 196.81
            },
            {
                "x": 190.58,
                "y": 123.12
            },
            {
                "x": 113.12,
                "y": 123.12
            }
        ],[
            {
                "x": 164.55,
                "y": 210.16
            },
            {
                "x": 269.98,
                "y": 210.16
            },
            {
                "x": 269.98,
                "y": 140.15
            },
            {
                "x": 164.55,
                "y": 140.15
            }
        ]]];

    const subjectInputs = [];
    const clipInputs = [];
    group.forEach((pointsList, index) => {
      pointsList.forEach((points) => {
        if (index !== group.length - 1) {
          subjectInputs.push({ data: points, closed: true });
        } else {
          clipInputs.push({ data: points });
        }
      });
    });

    let polyResult =
        this._clipper.clipToPaths({
          clipType: 'intersect',
          subjectInputs,
          clipInputs,
          subjectFillType: PolyFillType.EvenOdd,
          clipFillType: PolyFillType.EvenOdd,
        }) || [];

三个矩形的位置如下:

在此处输入图像描述

但结果是错误的:

在此处输入图像描述

正确的结果应该只有一个中间矩形:

在此处输入图像描述

我应该怎么办?谢谢你!

4

0 回答 0