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: clipPolygon.m
    path of file: ./repos/matGeom/matGeom/polygons2d
    
    the code of the file until where you have to start completion: function poly2 = clipPolygon(polygon, w)
%CLIPPOLYGON Clip a polygon with a rectangular box.

    
function poly2 = clipPolygon(polygon, w)
%CLIPPOLYGON Clip a polygon with a rectangular box.
%
%   POLY2 = clipPolygon(POLY, BOX);
%   POLY is N-by-2 array of points
%   BOX has the form: [XMIN XMAX YMIN YMAX].
%   Returns the polygon created by the intersection of the polygon POLY and
%   the bounding box BOX.
%
%   Note: Works only for convex polygons at the moment.
%
%   See also 
%     polygons2d, boxes2d, clipPolygonByLine, clipPolyline
%

% ------
% Author: David Legland 
% E-mail: david.legland@inrae.fr
% Created: 2005-05-14
% Copyright 2005-2023 INRA - Cepia Software Platform

% check case of polygons stored in cell array
if iscell(polygon)
    poly2 = cell(1, length(polygon));
    for i = 1:length(polygon)
        poly2{i} = clipPolygon(polygon{i}, w);
    end