function [max_offset] = get_max_offset(vertices)
% -------------------------------------------------------------------------
% MSc Project - MSc in Communications and Signal Processing
% Department of Electrical and Electronic Engineering
% Imperial College London, 2011
%
% Supervisor  : Dr Pier Luigi Dragotti
% Contributor : Andriy Gelman
% Author      : Jon Onativia Bravo
%
% File        : get_max_offset.m
% -------------------------------------------------------------------------
% Measure the max offset in pixels between consecutive vertices.
%
% [max_offset] = get_max_offset(vertices)
%
% INPUT:
%  - vertices   : List of vertices (2xN) with first element of each 
%                 segment corresponding to [0; segment_length].
%
% OUTPUT:
%  - max_offset : Maximum offset.
%


%% Output argument
max_offset = 0;


%% Obtain number of segments
segment_inds = find(vertices(1,:) == 0);
seg_lengths  = vertices(2,segment_inds);
num_of_segs  = length(segment_inds);


%% Loop over each segment
for i_seg = 1 : num_of_segs
    
    % Retrive the segment
    seg_len   = seg_lengths(i_seg);
    seg_start = segment_inds(i_seg) + 1;
    seg_end   = seg_start + seg_len - 1;
    seg       = vertices(:,seg_start:seg_end);
    
    % Loop over each vertex
    for i_vert = 2 : seg_len
        prev_vert = i_vert - 1;
        
        x_offset = abs(seg(1,i_vert) - seg(1,prev_vert));
        y_offset = abs(seg(2,i_vert) - seg(2,prev_vert));
        
        max_offset = max([max_offset x_offset y_offset]);
    end
    
end


%%

