@@ -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 ) ;
@@ -196,7 +197,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
196
197
197
198
// create outline & tester
198
199
if ( dragOptions . polygons && dragOptions . polygons . length ) {
199
- mergedPolygons = joinPolygons ( dragOptions . mergedPolygons , currentPolygon ) ;
200
+ mergedPolygons = mergePolygons ( dragOptions . mergedPolygons , currentPolygon , subtract ) ;
201
+ currentPolygon . subtract = subtract ;
200
202
testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
201
203
}
202
204
else {
@@ -265,17 +267,33 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
265
267
266
268
if ( currentPolygon && dragOptions . polygons ) {
267
269
// save last polygons
270
+ currentPolygon . subtract = subtract ;
268
271
dragOptions . polygons . push ( currentPolygon ) ;
269
272
270
- // we have to keep reference to arrays, therefore just replace items
271
- dragOptions . mergedPolygons . splice . apply ( dragOptions . mergedPolygons , [ 0 , dragOptions . mergedPolygons . length ] . concat ( mergedPolygons ) ) ;
273
+ // we have to keep reference to arrays container
274
+ dragOptions . mergedPolygons . length = 0 ;
275
+ [ ] . push . apply ( dragOptions . mergedPolygons , mergedPolygons ) ;
272
276
}
273
277
} ) ;
274
278
} ;
275
279
} ;
276
280
277
- function joinPolygons ( list , poly ) {
278
- var res = polybool . union ( {
281
+ function mergePolygons ( list , poly , subtract ) {
282
+ var res ;
283
+
284
+ if ( subtract ) {
285
+ res = polybool . difference ( {
286
+ regions : list ,
287
+ inverted : false
288
+ } , {
289
+ regions : [ poly ] ,
290
+ inverted : false
291
+ } ) ;
292
+
293
+ return res . regions ;
294
+ }
295
+
296
+ res = polybool . union ( {
279
297
regions : list ,
280
298
inverted : false
281
299
} , {
0 commit comments