New C++ contour code with corner_mask