The arguments to the mask::AddGrid function are the mask layer, the discretization accuracy (which controls the maximum distance between the analytical curve and the mask polygon), and a function that relates the width of a layer to the width of the design intent. In this example, the ‘cladding’ layer follows the design intent at 2 micrometer distance on both sides. This could be any function; if you know your process has a width-dependent bias (which would mean that the deviation between the actual width on the chip and the width on the mask depends on the width), you can directly compensate for this in the width function.
In addition to width-dependent mask layers, it is also possible to directly define asymmetric mask layers. This allows for a different way to define the trenches above, which no longer needs any Boolean operations among virtual mask layers: