public static double relativeOverlap ( SpatialComparable box1 , SpatialComparable box2 ) { final int dim = assertSameDimensionality ( box1 , box2 ) ; // the overlap volume double overlap = 1. ; double vol1 = 1. ; double vol2 = 1. ; for ( int i = 0 ; i < dim ; i ++ ) { final double box1min = box1 . getMin ( i ) ; final double box1max = box1 . getMax ( i ) ; final double box2min = box2 . getMin ( i ) ; final double box2max = box2 . getMax ( i ) ; final double omax = Math . min ( box1max , box2max ) ; final double omin = Math . max ( box1min , box2min ) ; // if omax <= omin in any dimension, the overlap box has a volume of zero if ( omax <= omin ) { return 0. ; } overlap *= omax - omin ; vol1 *= box1max - box1min ; vol2 *= box2max - box2min ; } return overlap / ( vol1 + vol2 ) ; }
Computes the volume of the overlapping box between two SpatialComparables and return the relation between the volume of the overlapping box and the volume of both SpatialComparable .