function frac = estFillingFraction
global xtrail ytrail

% Estimate how much of the available space is filled
% by the robot trail
%
% computes grid ID for occupied cells (1 cm square grid)
% and then divides by the total number of cells
%
% EXPLANATION OF ALGORITHM:
% round(xtrail) runs from -10 to 10 in integer steps
% round(xtrail+11) runs from 1 to 21 in integer steps
%
% gridIDx = round(xtrail+11)
% gridIDy = round(ytrail+11)
% gridID = 100*gridIDx + 1*gridIDy
%
% For example,
% gridID 0101 is the cell at (-10, -10)
% gridID 2121 is the cell at (+10, +10)

gridIDx = round(xtrail+11);
jj = find(gridIDx == 21);
if(any(jj)) gridIDx(jj) = 1; end;

gridIDy = round(ytrail+11);
jj = find(gridIDy == 21);
if(any(jj)) gridIDy(jj) = 1; end;

gridID = 100*gridIDx + gridIDy;

% count the number of *unique* occupied cells
numOccupied = length(unique(gridID));

% now divide by the total number of cells 
numTotal = 400; % 20*20
frac = numOccupied/numTotal;

