多边形.clip
实施格来纳-凯"高效剪接任意多边形" 纸张
安装
npm install 2d-polygon-boolean
使用情况
签名
var polygons = polygonBoolean(array1, array2, mode)
模式为字符串 and (节间), or (工会), not (切开)
polygons 是数组数组
(例如
[
[
[0, 0],
[0, 1],
[1, 1]
]
]
实例
var polygonBoolean = require('2d-polygon-boolean');
var subject = [
[0, 0],
[100, 0],
[100, 100],
[0, 100]
];
var clip = [
[90, 90],
[110, 90],
[110, 110],
[90, 110],
[90, 90]
];
var union = polygonBoolean(subject, clip, 'or');
console.log('union results', union);
/*
union results [ [ [ 100, 90 ],
[ 100, 0 ],
[ 0, 0 ],
[ 0, 100 ],
[ 90, 100 ],
[ 90, 110 ],
[ 110, 110 ],
[ 110, 90 ] ] ]
*/
var cut = polygonBoolean(subject, clip, 'not');
console.log('cut results', cut);
/*
cut results [ [ [ 100, 90 ],
[ 100, 0 ],
[ 0, 0 ],
[ 0, 100 ],
[ 90, 100 ],
[ 90, 90 ] ] ]
*/
var intersect = polygonBoolean(subject, clip, 'and');
console.log('intersect results', intersect);
/*
intersect results [ [ [ 100, 90 ], [ 100, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]
*/