implemented optimized pmc

only iterates through line segments in the correct layer.