@@ -473,7 +473,7 @@ def does_overlap(self, aabb, method='DFS', closed=False):
473
473
474
474
return len (_overlap_pairs (self , aabb , method , True , closed )) > 0
475
475
476
- def overlap_aabbs (self , aabb , method = 'DFS' , closed = False ):
476
+ def overlap_aabbs (self , aabb , method = 'DFS' , closed = False , unique = True ):
477
477
"""Get overlapping AABBs
478
478
479
479
This function gets each overlapping AABB.
@@ -491,17 +491,19 @@ def overlap_aabbs(self, aabb, method='DFS', closed=False):
491
491
closed (bool): Option to specify closed or open box intersection.
492
492
If open, there must be a non-zero amount of overlap. If closed,
493
493
boxes can be touching.
494
+ unique (bool): Return only unique pairs. Defaults to True.
494
495
495
496
Returns:
496
497
list: AABB objects in AABBTree that overlap with the input.
497
498
"""
498
- pairs = _overlap_pairs (self , aabb , method , closed = closed )
499
+ pairs = _overlap_pairs (self , aabb , method , closed = closed ,
500
+ unique = unique )
499
501
if len (pairs ) == 0 :
500
502
return []
501
503
boxes , _ = zip (* pairs )
502
504
return list (boxes )
503
505
504
- def overlap_values (self , aabb , method = 'DFS' , closed = False ):
506
+ def overlap_values (self , aabb , method = 'DFS' , closed = False , unique = True ):
505
507
"""Get values of overlapping AABBs
506
508
507
509
This function gets the value field of each overlapping AABB.
@@ -519,11 +521,13 @@ def overlap_values(self, aabb, method='DFS', closed=False):
519
521
closed (bool): Option to specify closed or open box intersection.
520
522
If open, there must be a non-zero amount of overlap. If closed,
521
523
boxes can be touching.
524
+ unique (bool): Return only unique pairs. Defaults to True.
522
525
523
526
Returns:
524
527
list: Value fields of each node that overlaps.
525
528
"""
526
- pairs = _overlap_pairs (self , aabb , method , closed = closed )
529
+ pairs = _overlap_pairs (self , aabb , method , closed = closed ,
530
+ unique = unique )
527
531
if len (pairs ) == 0 :
528
532
return []
529
533
_ , values = zip (* pairs )
@@ -537,7 +541,8 @@ def _merge(lims1, lims2):
537
541
return (lower , upper )
538
542
539
543
540
- def _overlap_pairs (in_tree , aabb , method = 'DFS' , halt = False , closed = False ):
544
+ def _overlap_pairs (in_tree , aabb , method = 'DFS' , halt = False , closed = False ,
545
+ unique = True ):
541
546
"""Get overlapping AABBs and values in (AABB, value) pairs
542
547
543
548
*New in version 2.6.0*
@@ -553,6 +558,7 @@ def _overlap_pairs(in_tree, aabb, method='DFS', halt=False, closed=False):
553
558
halt (bool): Return the list immediately once a pair has been
554
559
added.
555
560
closed (bool): Check for closed box intersection. Defaults to False.
561
+ unique (bool): Return only unique pairs. Defaults to True.
556
562
557
563
Returns:
558
564
list: (AABB, value) pairs in AABBTree that overlap with the input.
@@ -571,7 +577,7 @@ def _overlap_pairs(in_tree, aabb, method='DFS', halt=False, closed=False):
571
577
e_str = "method should be 'DFS' or 'BFS', not " + str (method )
572
578
raise ValueError (e_str )
573
579
574
- if len (pairs ) < 2 :
580
+ if len (pairs ) < 2 or not unique :
575
581
return pairs
576
582
return _unique_pairs (pairs )
577
583
0 commit comments