Mercurial > forge
changeset 9821:c869fff01da2 octave-forge
geometry: adding path to prvate folder in tests
author | jpicarbajal |
---|---|
date | Thu, 22 Mar 2012 22:38:34 +0000 |
parents | e65110da131a |
children | c63f213bad31 |
files | main/geometry/inst/geom2d/bisector.m main/geometry/inst/geom2d/createCircle.m main/geometry/inst/geom2d/drawLine.m main/geometry/inst/geom2d/medianLine.m |
diffstat | 4 files changed, 195 insertions(+), 138 deletions(-) [+] |
line wrap: on
line diff
--- a/main/geometry/inst/geom2d/bisector.m Thu Mar 22 22:05:06 2012 +0000 +++ b/main/geometry/inst/geom2d/bisector.m Thu Mar 22 22:38:34 2012 +0000 @@ -10,8 +10,8 @@ %% %% 1. Redistributions of source code must retain the above copyright notice, this %% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, %% this list of conditions and the following disclaimer in the documentation %% and/or other materials provided with the distribution. %% @@ -19,9 +19,9 @@ %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE @@ -43,7 +43,7 @@ %% The result has the form [x0 y0 dx dy], with [x0 y0] being the origin %% point ans [dx dy] being the direction vector, normalized to have unit %% norm. -%% +%% %% @seealso{lines2d, rays2d} %% @end deftypefn @@ -53,9 +53,9 @@ % two lines line1 = varargin{1}; line2 = varargin{2}; - - point = intersectLines(line1, line2); - + + point = intersectLines(line1, line2); + elseif length(varargin)==3 % three points p1 = varargin{1}; @@ -65,7 +65,7 @@ line1 = createLine(p2, p1); line2 = createLine(p2, p3); point = p2; - + elseif length(varargin)==1 % three points, given in one array var = varargin{1}; @@ -90,7 +90,11 @@ endfunction +%!shared privpath +%! privpath = [fileparts(which('geom2d_Contents')) filesep() 'private']; + %!test +%! addpath (privpath,'-end') %! p0 = [0 0]; %! p1 = [10 0]; %! p2 = [0 10]; @@ -99,19 +103,24 @@ %! ray = bisector(line1, line2); %! assertElementsAlmostEqual([0 0], ray(1,1:2)); %! assertAlmostEqual(pi/4, lineAngle(ray)); +%! rmpath (privpath); %!test +%! addpath (privpath,'-end') %! p0 = [0 0]; %! p1 = [10 0]; %! p2 = [0 10]; %! ray = bisector(p1, p0, p2); %! assertElementsAlmostEqual([0 0], ray(1,1:2)); %! assertAlmostEqual(pi/4, lineAngle(ray)); +%! rmpath (privpath); %!test +%! addpath (privpath,'-end') %! p0 = [0 0]; %! p1 = [10 0]; %! p2 = [0 10]; %! ray = bisector([p1; p0; p2]); %! assertElementsAlmostEqual([0 0], ray(1,1:2)); %! assertAlmostEqual(pi/4, lineAngle(ray)); +%! rmpath (privpath);
--- a/main/geometry/inst/geom2d/createCircle.m Thu Mar 22 22:05:06 2012 +0000 +++ b/main/geometry/inst/geom2d/createCircle.m Thu Mar 22 22:38:34 2012 +0000 @@ -10,8 +10,8 @@ %% %% 1. Redistributions of source code must retain the above copyright notice, this %% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, %% this list of conditions and the following disclaimer in the documentation %% and/or other materials provided with the distribution. %% @@ -19,9 +19,9 @@ %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE @@ -36,7 +36,7 @@ %% @deftypefnx {Function File} {@var{circle} = } createCircle (@var{p1}, @var{p2}) %% Create a circle from 2 or 3 points. %% -%% Creates the circle passing through the 3 given points. +%% Creates the circle passing through the 3 given points. %% C is a 1x3 array of the form: [XC YX R]. %% %% When two points are given, creates the circle whith center @var{p1} and passing @@ -46,7 +46,7 @@ %% result has as many lines as the point arrays. %% %% Example -%% +%% %% @example %% % Draw a circle passing through 3 points. %% p1 = [10 15]; @@ -70,7 +70,7 @@ x0 = p1(:,1); y0 = p1(:,2); r = hypot((p2(:,1)-x0), (p2(:,2)-y0)); - + elseif nargin == 3 % inputs are three points on the circle p1 = varargin{1}; @@ -81,19 +81,23 @@ line1 = medianLine(p1, p2); line2 = medianLine(p1, p3); point = intersectLines(line1, line2); - x0 = point(:, 1); + x0 = point(:, 1); y0 = point(:, 2); - + % circle radius r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); end - - % create array for returning result + + % create array for returning result circle = [x0 y0 r]; endfunction +%!shared privpath +%! privpath = [fileparts(which('geom2d_Contents')) filesep() 'private']; + %!test +%! addpath (privpath,'-end') %! p1 = [10 15]; %! p2 = [15 20]; %! p3 = [10 25]; @@ -104,8 +108,10 @@ %! assertEqual(exp, circle); %! circle = createCircle(p2, p3, p1); %! assertEqual(exp, circle); +%! rmpath (privpath); %!test +%! addpath (privpath,'-end') %! p1 = [10 15]; %! p2 = [15 20]; %! p3 = [10 25]; @@ -120,4 +126,4 @@ %! assertEqual(exp, circle); %! circle = createCircle(p2, p3, p1); %! assertEqual(exp, circle); - +%! rmpath (privpath);
--- a/main/geometry/inst/geom2d/drawLine.m Thu Mar 22 22:05:06 2012 +0000 +++ b/main/geometry/inst/geom2d/drawLine.m Thu Mar 22 22:38:34 2012 +0000 @@ -10,8 +10,8 @@ %% %% 1. Redistributions of source code must retain the above copyright notice, this %% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, %% this list of conditions and the following disclaimer in the documentation %% and/or other materials provided with the distribution. %% @@ -19,9 +19,9 @@ %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE @@ -35,7 +35,7 @@ %% @deftypefn {Function File} {@var{h} =} drawLine (@var{line}) %% @deftypefnx {Function File} {@var{h} =} drawLine (@var{line}, @var{param},@var{value}) %% Draw the line on the current axis. -%% +%% %% Draws the line LINE on the current axis, by using current axis to clip %% the line. Extra @var{param},@var{value} pairs are passed to the @code{line} function. %% Returns a handle to the created line object. If clipped line is not @@ -85,110 +85,143 @@ %! drawLine([30 40 10 20]); %! drawLine([30 40 20 -10], 'color', 'm', 'linewidth', 2); -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [30 40 10 0]; -%%! edge = [0 40 100 40]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!shared privpath +%! privpath = [fileparts(which('geom2d_Contents')) filesep() 'private']; -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [30 40 -10 0]; -%%! edge = [100 40 0 40]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [30 40 10 0]; +%! edge = [0 40 100 40]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all + +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [30 40 -10 0]; +%! edge = [100 40 0 40]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [30 140 10 0]; -%%! hl = drawLine(line); -%%! assertEqual(-1, hl); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [30 140 10 0]; +%! hl = drawLine(line); +%! assertEqual(-1, hl); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [30 40 0 10]; -%%! edge = [30 0 30 100]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [30 40 0 10]; +%! edge = [30 0 30 100]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [30 40 0 -10]; -%%! edge = [30 100 30 0]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [30 40 0 -10]; +%! edge = [30 100 30 0]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [140 30 0 10]; -%%! hl = drawLine(line); -%%! assertEqual(-1, hl); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [140 30 0 10]; +%! hl = drawLine(line); +%! assertEqual(-1, hl); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [80 30 10 10]; -%%! edge = [50 0 100 50]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [80 30 10 10]; +%! edge = [50 0 100 50]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [20 70 10 10]; -%%! edge = [0 50 50 100]; -%%! hl = drawLine(line); -%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [20 70 10 10]; +%! edge = [0 50 50 100]; +%! hl = drawLine(line); +%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [140 -30 10 10]; -%%! hl = drawLine(line); -%%! assertEqual(-1, hl); -%%! line = [-40 130 10 10]; -%%! hl = drawLine(line); -%%! assertEqual(-1, hl); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [140 -30 10 10]; +%! hl = drawLine(line); +%! assertEqual(-1, hl); +%! line = [-40 130 10 10]; +%! hl = drawLine(line); +%! assertEqual(-1, hl); +%! rmpath (privpath); +%! close all -%%!test -%%! box = [0 100 0 100]; -%%! hf = figure(); -%%! axis(box); -%%! line = [... -%%! 80 30 10 10; ... -%%! 20 70 10 10; ... -%%! 140 -30 10 10; ... -%%! -40 130 10 10]; -%%! edge = [... -%%! 50 0 100 50; ... -%%! 0 50 50 100]; -%%! hl = drawLine(line); -%%! assertEqual(4, length(hl)); -%%! assertElementsAlmostEqual(edge(1, [1 3]), get(hl(1), 'xdata')); -%%! assertElementsAlmostEqual(edge(1, [2 4]), get(hl(1), 'ydata')); -%%! assertElementsAlmostEqual(edge(2, [1 3]), get(hl(2), 'xdata')); -%%! assertElementsAlmostEqual(edge(2, [2 4]), get(hl(2), 'ydata')); -%%! assertEqual(-1, hl(3)); -%%! assertEqual(-1, hl(4)); +%!test +%! addpath (privpath,'-end') +%! box = [0 100 0 100]; +%! hf = figure(); +%! axis(box); +%! line = [... +%! 80 30 10 10; ... +%! 20 70 10 10; ... +%! 140 -30 10 10; ... +%! -40 130 10 10]; +%! edge = [... +%! 50 0 100 50; ... +%! 0 50 50 100]; +%! hl = drawLine(line); +%! assertEqual(4, length(hl)); +%! assertElementsAlmostEqual(edge(1, [1 3]), get(hl(1), 'xdata')); +%! assertElementsAlmostEqual(edge(1, [2 4]), get(hl(1), 'ydata')); +%! assertElementsAlmostEqual(edge(2, [1 3]), get(hl(2), 'xdata')); +%! assertElementsAlmostEqual(edge(2, [2 4]), get(hl(2), 'ydata')); +%! assertEqual(-1, hl(3)); +%! assertEqual(-1, hl(4)); +%! rmpath (privpath); +%! close all
--- a/main/geometry/inst/geom2d/medianLine.m Thu Mar 22 22:05:06 2012 +0000 +++ b/main/geometry/inst/geom2d/medianLine.m Thu Mar 22 22:38:34 2012 +0000 @@ -10,8 +10,8 @@ %% %% 1. Redistributions of source code must retain the above copyright notice, this %% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, %% this list of conditions and the following disclaimer in the documentation %% and/or other materials provided with the distribution. %% @@ -19,9 +19,9 @@ %% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE %% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE %% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR %% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS %% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN %% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) %% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE @@ -47,7 +47,7 @@ %% Creates the median of the @var{edge}. @var{edge} is a 1*4 array, containing [X1 Y1] %% coordinates of first point, and [X2 Y2], the coordinates of the second %% point. -%% +%% %% Example %% %% @example @@ -84,27 +84,27 @@ tab = varargin{1}; if size(tab, 2)==2 % input is an array of two points - x0 = tab(1,1); + x0 = tab(1,1); y0 = tab(1,2); - dx = tab(2,1)-x0; + dx = tab(2,1)-x0; dy = tab(2,2)-y0; else % input is an edge - x0 = tab(:, 1); + x0 = tab(:, 1); y0 = tab(:, 2); - dx = tab(:, 3) - tab(:, 1); + dx = tab(:, 3) - tab(:, 1); dy = tab(:, 4) - tab(:, 2); end - + elseif nargs==2 % input is given as two points, or two point arrays p1 = varargin{1}; p2 = varargin{2}; - x0 = p1(:, 1); + x0 = p1(:, 1); y0 = p1(:, 2); - dx = bsxfun(@minus, p2(:, 1), x0); + dx = bsxfun(@minus, p2(:, 1), x0); dy = bsxfun(@minus, p2(:, 2), y0); - + else error('Too many input arguments'); end @@ -115,23 +115,32 @@ endfunction +%!shared privpath +%! privpath = [fileparts(which('geom2d_Contents')) filesep() 'private']; + %!test +%! addpath (privpath,'-end') %! p1 = [0 0]; %! p2 = [10 0]; %! exp = [5 0 0 10]; %! lin = medianLine(p1, p2); %! assertElementsAlmostEqual(exp, lin); - +%! rmpath (privpath); + %!test +%! addpath (privpath,'-end') %! p1 = [0 0]; %! p2 = [10 0]; %! exp = [5 0 0 10]; %! lin = medianLine([p1 p2]); %! assertElementsAlmostEqual(exp, lin); +%! rmpath (privpath); %!test +%! addpath (privpath,'-end') %! p1 = [0 0; 10 10]; %! p2 = [10 0;10 20]; %! exp = [5 0 0 10; 10 15 -10 0]; %! lin = medianLine(p1, p2); %! assertElementsAlmostEqual(exp, lin); +%! rmpath (privpath);