SYS_Math.xor() method
Calculate the symmetric difference (XOR) of two polygons
Signature
typescript
function xor(
polygon1: TSYS_MathPolygonInput,
polygon2: TSYS_MathPolygonInput,
): TSYS_MathPolygonGroup;1
2
3
4
2
3
4
Parameters
Parameter | Type | Description |
|---|---|---|
polygon1 | Polygon 1 | |
polygon2 | Polygon 2 |
Returns
Polygon group of the symmetric difference result, preserving the association between outer rings and holes
Example
javascript
// 1. 新旧两版部分重叠的板框轮廓
const oldOutline = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const newOutline = [{ x: 50, y: 20 }, { x: 150, y: 20 }, { x: 150, y: 60 }, { x: 50, y: 60 }];
// 2. 异或:重叠的中间区域被扣除,剩下两侧不重叠的部分
const diff = eda.sys_Math.xor(oldOutline, newOutline);
console.log('差异区域多边形个数:', diff.length);
// 3. 异或面积:8000 + 4000 - 2 x 重叠 2000 = 8000(重叠部分两次都不算)
console.log('差异区域总面积:', eda.sys_Math.calculateArea(diff));
// 4. 完全相同的两个多边形异或结果为空数组(无差异;空组不能再传给
// calculateArea,空输入会抛『无法识别的多边形输入格式』)
console.log('自身与自身异或的差异区域个数:', eda.sys_Math.xor(oldOutline, oldOutline).length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14