Measuring gap between tool and workpiece