<commit_before>import d3 from 'd3';
import intersect from '../intersect';

// computes the area of overlap between the rectangle with the given index with the
// rectangles in the array
export const collisionArea = (rectangles, index) =>  d3.sum(
        rectangles.filter((_, i) => index !== i)
            .map((d) => intersect(rectangles[index], d))
    );

// computes the total overlapping area of all of the rectangles in the given array
export const totalCollisionArea = (rectangles) => d3.sum(
    rectangles.map((_, i) => collisionArea(rectangles, i))
);<commit_msg>perf: halved the time for computing collision area<commit_after>import d3 from 'd3';
import intersect from '../intersect';

// computes the area of overlap between the rectangle with the given index with the
// rectangles in the array
export const collisionArea = (rectangles, index) =>  d3.sum(
        rectangles.map((d, i) => (index === i) ? 0 : intersect(rectangles[index], d))
    );

// computes the total overlapping area of all of the rectangles in the given array
export const totalCollisionArea = (rectangles) => d3.sum(
    rectangles.map((_, i) => collisionArea(rectangles, i))
);
{'fraction_non_alphanumeric': 0.11996572407883462, 'fraction_numerical': 0.007712082262210797, 'mean_word_length': 3.9914529914529915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7384342', 'n_tokens_mistral': 336, 'n_tokens_neox': 324, 'n_words': 131}