optimized mesh intersection code