From: <par...@us...> - 2011-11-03 21:52:37
|
Revision: 8965 http://octave.svn.sourceforge.net/octave/?rev=8965&view=rev Author: paramaniac Date: 2011-11-03 21:52:30 +0000 (Thu, 03 Nov 2011) Log Message: ----------- quaternion-oo: simplify constructor again, add an oct-file for argument checking Modified Paths: -------------- trunk/octave-forge/extra/quaternion_oo/DESCRIPTION trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/quaternion.m Added Paths: ----------- trunk/octave-forge/extra/quaternion_oo/Makefile trunk/octave-forge/extra/quaternion_oo/devel/makefile_quaternion.m trunk/octave-forge/extra/quaternion_oo/src/ trunk/octave-forge/extra/quaternion_oo/src/Makefile trunk/octave-forge/extra/quaternion_oo/src/is_real_matrice.cc Modified: trunk/octave-forge/extra/quaternion_oo/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/quaternion_oo/DESCRIPTION 2011-11-03 21:51:53 UTC (rev 8964) +++ trunk/octave-forge/extra/quaternion_oo/DESCRIPTION 2011-11-03 21:52:30 UTC (rev 8965) @@ -1,6 +1,6 @@ Name: quaternion -Version: 0.1.0 -Date: 2010-05-17 +Version: 0.2.0 +Date: 2011-11-03 Author: Lukas Reichlin <luk...@gm...> Maintainer: Lukas Reichlin <luk...@gm...> Title: Quaternion Added: trunk/octave-forge/extra/quaternion_oo/Makefile =================================================================== --- trunk/octave-forge/extra/quaternion_oo/Makefile (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/Makefile 2011-11-03 21:52:30 UTC (rev 8965) @@ -0,0 +1,16 @@ +sinclude ../../Makeconf + +PKG_FILES = COPYING DESCRIPTION INDEX $(wildcard inst/*) +SUBDIRS = doc/ + +.PHONY: $(SUBDIRS) + +pre-pkg:: + @for _dir in $(SUBDIRS); do \ + $(MAKE) -C $$_dir all; \ + done + +clean: + @for _dir in $(SUBDIRS); do \ + $(MAKE) -C $$_dir $(MAKECMDGOALS); \ + done Added: trunk/octave-forge/extra/quaternion_oo/devel/makefile_quaternion.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/devel/makefile_quaternion.m (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/devel/makefile_quaternion.m 2011-11-03 21:52:30 UTC (rev 8965) @@ -0,0 +1,9 @@ +homedir = pwd (); +develdir = fileparts (which ("makefile_quaternion")); +srcdir = [develdir, "/../src"]; +cd (srcdir); + +mkoctfile is_real_matrice.cc + +system ("rm *.o"); +cd (homedir); \ No newline at end of file Modified: trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/quaternion.m =================================================================== --- trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/quaternion.m 2011-11-03 21:51:53 UTC (rev 8964) +++ trunk/octave-forge/extra/quaternion_oo/inst/@quaternion/quaternion.m 2011-11-03 21:52:30 UTC (rev 8965) @@ -36,46 +36,38 @@ if (isa (a, "quaternion")) q = a; return; - elseif (isnumeric (a)) - w = a; - x = y = z = zeros (size (a), class (a)); + elseif (is_real_matrice (a)) + b = c = d = zeros (size (a)); else print_usage (); endif case 3 + if (! is_real_matrice (a, b, c)) + error ("quaternion: arguments must be real matrices"); + endif if (! size_equal (a, b, c)); error ("quaternion: arguments must have identical sizes"); endif - c_a = class (a); - if (isnumeric (a) && strcmp (c_a, class (b)) && strcmp (c_a, class (c))) - w = zeros (size (a), c_a); - x = a; - y = b; - z = c; - else - error ("quaternion: arguments must be numeric and of the same type"); - endif + d = c; + c = b; + b = a; + a = zeros (size (a)); case 4 + if (! is_real_matrice (a, b, c, d)) + error ("quaternion: arguments must be real matrices"); + endif if (! size_equal (a, b, c, d)); error ("quaternion: arguments must have identical sizes"); endif - c_a = class (a); - if (isnumeric (a) && strcmp (c_a, class (b)) && \ - strcmp (c_a, class (c)) && strcmp (c_a, class (d))) - w = a; - x = b; - y = c; - z = d; - else - error ("quaternion: arguments must be numeric and of the same type"); - endif otherwise print_usage (); endswitch - q = class (struct ("w", w, "x", x, "y", y, "z", z), "quaternion"); + q = class (struct ("w", a, "x", b, "y", c, "z", d), "quaternion"); + + ## TODO: avoid duplicate code in case 3 and 4 endfunction Property changes on: trunk/octave-forge/extra/quaternion_oo/src ___________________________________________________________________ Added: svn:ignore + *.oct Added: trunk/octave-forge/extra/quaternion_oo/src/Makefile =================================================================== --- trunk/octave-forge/extra/quaternion_oo/src/Makefile (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/src/Makefile 2011-11-03 21:52:30 UTC (rev 8965) @@ -0,0 +1,8 @@ +all: is_real_matrice.oct + +# helper +is_real_matrice.oct: is_real_matrice.cc + mkoctfile is_real_matrice.cc + +clean: + rm *.o core octave-core *.oct *~ Added: trunk/octave-forge/extra/quaternion_oo/src/is_real_matrice.cc =================================================================== --- trunk/octave-forge/extra/quaternion_oo/src/is_real_matrice.cc (rev 0) +++ trunk/octave-forge/extra/quaternion_oo/src/is_real_matrice.cc 2011-11-03 21:52:30 UTC (rev 8965) @@ -0,0 +1,61 @@ +/* + +Copyright (C) 2010 Lukas F. Reichlin + +This file is part of LTI Syncope. + +LTI Syncope 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. + +LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +Return true if argument is a real matrix. + +Author: Lukas Reichlin <luk...@gm...> +Created: September 2010 +Version: 0.1 + +*/ + +#include <octave/oct.h> + +DEFUN_DLD (is_real_matrice, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} is_real_matrice (@var{a}, @dots{})\n\ +Return true if argument is a real matrix.\n\ +@var{[]} is a valid matrix.\n\ +Avoid nasty stuff like @code{true = isreal (\"a\")}.\n\ +Renamed to is_real_matrice to avoid conflicts with \n\ +is_real_matrix from the control package.\n\ +@end deftypefn") +{ + octave_value retval = true; + int nargin = args.length (); + + if (nargin == 0) + { + print_usage (); + } + else + { + for (int i = 0; i < nargin; i++) + { + if (args(i).ndims () != 2 || ! args(i).is_numeric_type () + || ! args(i).is_real_type ()) + { + retval = false; + break; + } + } + } + + return retval; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |