add handling for overlapping triangles

and implement debug function to test it