@@ -41,7 +41,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
41
41
xAxisIds = dragOptions . xaxes . map ( getAxId ) ,
42
42
yAxisIds = dragOptions . yaxes . map ( getAxId ) ,
43
43
allAxes = dragOptions . xaxes . concat ( dragOptions . yaxes ) ,
44
- filterPoly , testPoly , mergedPolygons , currentPolygon ;
44
+ filterPoly , testPoly , mergedPolygons , currentPolygon ,
45
+ subtract = e . altKey ;
45
46
46
47
if ( mode === 'lasso' ) {
47
48
filterPoly = filteredPolygon ( [ [ x0 , y0 ] ] , constants . BENDPX ) ;
@@ -193,7 +194,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
193
194
194
195
// create outline & tester
195
196
if ( dragOptions . polygons && dragOptions . polygons . length ) {
196
- mergedPolygons = joinPolygons ( dragOptions . mergedPolygons , currentPolygon ) ;
197
+ mergedPolygons = mergePolygons ( dragOptions . mergedPolygons , currentPolygon , subtract ) ;
198
+ currentPolygon . subtract = subtract ;
197
199
testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
198
200
}
199
201
else {
@@ -262,6 +264,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
262
264
263
265
if ( currentPolygon && dragOptions . polygons ) {
264
266
// save last polygons
267
+ currentPolygon . subtract = subtract ;
265
268
dragOptions . polygons . push ( currentPolygon ) ;
266
269
267
270
// we have to keep reference to arrays container
@@ -272,8 +275,22 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
272
275
} ;
273
276
} ;
274
277
275
- function joinPolygons ( list , poly ) {
276
- var res = polybool . union ( {
278
+ function mergePolygons ( list , poly , subtract ) {
279
+ var res ;
280
+
281
+ if ( subtract ) {
282
+ res = polybool . difference ( {
283
+ regions : list ,
284
+ inverted : false
285
+ } , {
286
+ regions : [ poly ] ,
287
+ inverted : false
288
+ } ) ;
289
+
290
+ return res . regions ;
291
+ }
292
+
293
+ res = polybool . union ( {
277
294
regions : list ,
278
295
inverted : false
279
296
} , {
0 commit comments