How to speed the function H in this code? (Hausdorff Chirality Measurement)

I’m sorry, I didn’t think it through