www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffgui/@toGVCell/getZoomFractions.m
function fract = getZoomFractions(obj, selrect) %GETZOOMFRACTIONS Create zoom fractions from a selection rectangle % % FRACT = GETZOOMFRACTIONS(OBJ, SELRECT) creates a cell array with 2 % cells containing zoom fractions for the x limits and y limmits % respectively. These fractions are created from the overlap of the given % selection rectangle (a figure-based position rect) and the position of % the axes within the cell. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. % Convert selection rectangle into same coordinate system as the axes. selrect(1:2) = mbcgui.util.convertLocation(selrect(1:2), obj.hAxes); ax_pos = get(obj.hAxes, 'Position'); ax_pos(1:2) = 1; fract = cell(1,2); fract{1} = i_createfract(ax_pos([1 3]), selrect([1 3])); fract{2} = i_createfract(ax_pos([2 4]), selrect([2 4])); function fract = i_createfract(ax_pos, sel_pos) % Convert position inputs to [x1, x2] instead of [x, w] ax_range = ax_pos(2); ax_pos(2) = ax_pos(1) + ax_range - 1; sel_pos(2) = sel_pos(1) + sel_pos(2); if sel_pos(2)<sel_pos(1); sel_pos = sel_pos([2 1]); end fract = [(sel_pos(1)-ax_pos(1))./ax_range, ... 1 - (ax_pos(2)-sel_pos(2))./ax_range]; if fract(1)<0 || fract(1)>1 fract(1) = 0; end if fract(2)>1 || fract(2)<0; fract(2) = 1; end