You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: poly2tri.m
    path of file: ./repos/bspm/thirdparty/spm12/external/fieldtrip/private
    
    the code of the file until where you have to start completion: function mesh = poly2tri(mesh)

% POLY2TRI converts the polygons in a mesh to triangles by splitting
% them in half. The input polygons should consist of 4 vertices.
% Curvature is not considered and the resulting split will only be
% optimal for flat polygons.
%
% Use as
%  mesh = poly2tri(mesh)

    
function mesh = poly2tri(mesh)

% POLY2TRI converts the polygons in a mesh to triangles by splitting
% them in half. The input polygons should consist of 4 vertices.
% Curvature is not considered and the resulting split will only be
% optimal for flat polygons.
%
% Use as
%  mesh = poly2tri(mesh)
%
% See also MESH2EDGE

if ~isfield(mesh, 'poly')
  ft_error('the mesh does not contain polygons')
elseif ~size(mesh.poly,2)==4
  ft_error('this is only implemented for polygons with 4 corner points')
end