%% Test: X-Koordinate eines Rechtecks aus Plot
% 29.01.2019 Nicolas

% Generate plot to draw rectangle
%t = 0:0.1:10;
%plot(t, sin(t))

close all
clear all

hFigure = openfig('sinWithRect.fig', 'new');

% Rectangle
hRect = findall(hFigure, 'Type', 'rectangleshape');
posRect = get(hRect, 'Position');
xRect = posRect([1 3]);

% Axe
hAxe = get(hFigure, 'Children');
assert(numel(hAxe) == 1);
posAxe = get(hAxe, 'Position');
xLimAxe = get(hAxe, 'XLim');
xPosAxe = posAxe([1 3]);

% x-co-ordinates of rectangle in figure 
xf = [xRect(1) sum(xRect)];

% x-co-ordinates of rectangle in axe [0 1]
xa = (xf - xPosAxe(1))./(xPosAxe(2)-xPosAxe(1));

% x-co-ordinates of rectangle in axe [xLim]
x = xLimAxe(1) + (xLimAxe(2)-xLimAxe(1))*xa;

% Check matching 
hold on
plot(x, 0*x, 'o')