function [lineSearchStat, bestObject] = iterateLineSearchGolden(...
    lineSearchStat, bestObject, getObjectCall, objectiveFunction)
% iteration step for golden line search (minimizer)
%
% THIS IS NO USER FUNCTION

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 Alexander Reinhold
%
% This program is free software: you can redistribute it and/or modify it 
%   under the terms of the GNU General Public License as published by the 
%   Free Software Foundation, either version 3 of the License, or (at your 
%   option) any later version.
%
% This program is distributed in the hope that it will be useful, but 
%   WITHOUT ANY WARRANTY; without even the implied warranty of 
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
%   General Public License for more details.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>

%% new guess
% new data point
newX = lineSearchStat(3,1) - (lineSearchStat(2,1) - lineSearchStat(1,1));

% new objective function
newObject = getObjectCall(newX);
newObjective = objectiveFunction(newObject);

%% make a decision
if lineSearchStat(2,2) < newObjective
    % current candidate remains
    if lineSearchStat(2,1) <= newX
        % right bound to abandon
        lineSearchStat(3,:) = [newX; newObjective];
    else
        % left bound to abandon
        lineSearchStat(1,:) = [newX; newObjective];
    end
else
    % new candidate remains
    bestObject = newObject;
    if lineSearchStat(2,1) < newX
        % left bound to abandon
        lineSearchStat(1,:) = lineSearchStat(2,:);
    else
        % right bound to abandon
        lineSearchStat(3,:) = lineSearchStat(2,:);
    end
    lineSearchStat(2,:) = [newX; newObjective];
end