Calculate pairs of similar rectangles from its common ratio
foreach ( KeyValuePair < double , int > p in ratio ) { int val = p . Value ; if ( val > 1 ) { res += ( val * ( val - 1 ) ) / 2 ; } } return res ; }