function [prob atlas cseg correct] = predict(atlas, prob, cseg)
%PREDICT   Compute predictor.
%
% Construct curve segment projection condition and theta-method predictor
% and correct.

% This file is part of the atlas_kd toolbox, copyright (C) Michael
% Henderson, Frank Schilder, Harry Dankowicz, Erika Fotsch, of the package
% COCO (http://sourceforge.net/projects/cocotools).

chart  = atlas.charts{atlas.boundary(1)};
chart.P.mark(chart.bv(1)) = 1;
atlas.charts{atlas.boundary(1)} = chart;

s      = chart.s(:, chart.bv(1));
h      = chart.h;
prcond = struct('x', chart.x, 'TS', chart.TS, 's', s, 'h', h);
th     = atlas.cont.theta;
if th>=0.5 && th<=1
  xp          = chart.x + (th*h)*(chart.TS*s);
  [prob cseg] = CurveSegment.create(prob, chart, prcond, xp);
  [prob cht2]  = cseg.update_TS(prob, cseg.curr_chart);
  s           = h*(cht2.TS'*chart.TS*s);
  h           = norm(s);
  s           = s/h;
  xp          = chart.x + h*(cht2.TS*s);
  prcond      = struct('x', chart.x, 'TS', cht2.TS, 's', s, 'h', h);
else
  xp          = chart.x + h*(chart.TS*s);
end
[prob cseg] = CurveSegment.create(prob, chart, prcond, xp);
correct     = true;

end
