Convert polygon code to nested arrays