From: <jpi...@us...> - 2011-11-20 23:32:30
|
Revision: 9156 http://octave.svn.sourceforge.net/octave/?rev=9156&view=rev Author: jpicarbajal Date: 2011-11-20 23:32:21 +0000 (Sun, 20 Nov 2011) Log Message: ----------- geometry. Merging with octCLIP Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/NEWS trunk/octave-forge/main/geometry/PKG_ADD trunk/octave-forge/main/geometry/PKG_DEL Added Paths: ----------- trunk/octave-forge/main/geometry/inst/octclip/ trunk/octave-forge/main/geometry/inst/octclip/inst/ trunk/octave-forge/main/geometry/inst/octclip/inst/oc_polybool.m trunk/octave-forge/main/geometry/inst/octclip/src/ trunk/octave-forge/main/geometry/inst/octclip/src/Makefile trunk/octave-forge/main/geometry/inst/octclip/src/_oc_polybool.cc trunk/octave-forge/main/geometry/inst/octclip/src/compilador.c trunk/octave-forge/main/geometry/inst/octclip/src/errores.c trunk/octave-forge/main/geometry/inst/octclip/src/eucli.c trunk/octave-forge/main/geometry/inst/octclip/src/fgeneral.c trunk/octave-forge/main/geometry/inst/octclip/src/greiner.c trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/ trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/compilador.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/constantes.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/errores.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/eucli.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/fgeneral.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/general.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/geom.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/greiner.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/polig.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/ptopol.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/segmento.h trunk/octave-forge/main/geometry/inst/octclip/src/libgeoc/ventorno.h trunk/octave-forge/main/geometry/inst/octclip/src/octclip.h trunk/octave-forge/main/geometry/inst/octclip/src/polig.c trunk/octave-forge/main/geometry/inst/octclip/src/ptopol.c trunk/octave-forge/main/geometry/inst/octclip/src/segmento.c trunk/octave-forge/main/geometry/inst/octclip/src/ventorno.c Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-20 23:09:21 UTC (rev 9155) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-20 23:32:21 UTC (rev 9156) @@ -1,11 +1,11 @@ Name: Geometry -Version: 1.2.2 -Date: 2011-11-4 -Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> +Version: 1.3.0 +Date: 2011-11-24 +Author: David Legland <dav...@gr...>, José Luis García Pallero <jgp...@gm...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Title: Computational Geometry Description: Library for geometric computing extending MatGeom functions. Useful to create, transform, manipulate and display geometric primitives. Depends: octave (>= 3.4.0) -Autoload: no +Autoload: yes License: GPL version 3 and BSD (see files) Url: http://octave.sf.net, http://matgeom.sf.net Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-11-20 23:09:21 UTC (rev 9155) +++ trunk/octave-forge/main/geometry/INDEX 2011-11-20 23:32:21 UTC (rev 9156) @@ -117,6 +117,7 @@ 2D Polygons drawPolygon simplifypolygon + oc_polybool 2D Piecewise polynomial shapes polygon2shape shape2polygon Modified: trunk/octave-forge/main/geometry/NEWS =================================================================== --- trunk/octave-forge/main/geometry/NEWS 2011-11-20 23:09:21 UTC (rev 9155) +++ trunk/octave-forge/main/geometry/NEWS 2011-11-20 23:32:21 UTC (rev 9156) @@ -1,6 +1,12 @@ Summary of important user-visible changes for releases of the geometry package =============================================================================== +geometry-1.3.0 Release Date: 2011-11-24 Release Manager: Juan Pablo Carbajal +=============================================================================== + +* Geometry merged with octCLIP. + +=============================================================================== geometry-1.2.2 Release Date: 2011-11-04 Release Manager: Juan Pablo Carbajal =============================================================================== Modified: trunk/octave-forge/main/geometry/PKG_ADD =================================================================== --- trunk/octave-forge/main/geometry/PKG_ADD 2011-11-20 23:09:21 UTC (rev 9155) +++ trunk/octave-forge/main/geometry/PKG_ADD 2011-11-20 23:32:21 UTC (rev 9156) @@ -1,5 +1,5 @@ %1 -dirlist = {"geom2d","io","polygons2d","shape2d"}; +dirlist = {"geom2d","io","polygons2d","shape2d","octclip"}; dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); if (! exist (fullfile (dirname, "inst"), "dir")) Modified: trunk/octave-forge/main/geometry/PKG_DEL =================================================================== --- trunk/octave-forge/main/geometry/PKG_DEL 2011-11-20 23:09:21 UTC (rev 9155) +++ trunk/octave-forge/main/geometry/PKG_DEL 2011-11-20 23:32:21 UTC (rev 9156) @@ -1,5 +1,5 @@ %1 -dirlist = {"geom2d","io","polygons2d","shape2d"}; +dirlist = {"geom2d","io","polygons2d","shape2d","octclip"}; dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); if (! exist (fullfile (dirname, "inst"), "dir")) Added: trunk/octave-forge/main/geometry/inst/octclip/inst/oc_polybool.m =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/inst/oc_polybool.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/inst/oc_polybool.m 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,264 @@ +## Copyright (C) 2011, José Luis García Pallero, <jgp...@gm...> +## +## This file is part of OctCLIP. +## +## OctCLIP 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. +## +## This program 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 Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}_oc_polybool(@var{sub},@var{clip},@var{op}) +## @deftypefnx{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}_oc_polybool(@var{sub},@var{clip}) +## +## This function performs boolean operations between two polygons using the +## Greiner-Hormann algorithm (http://davis.wpi.edu/~matt/courses/clipping/). +## +## @var{sub} is a two column matrix containing the X and Y coordinates of the +## vertices for the subject polygon. +## +## @var{clip} is a two column matrix containing the X and Y coordinates of the +## vertices for the clipper polygon. +## +## @var{op} is a text string containing the operation to perform between +## @var{sub} and @var{clip}. Possible values are: +## +## @itemize @bullet +## @item @var{'AND'} +## Intersection of @var{sub} and @var{clip} (value by default). +## @item @var{'OR'} +## Union of @var{subt} and @var{clip}. +## @item @var{'AB'} +## Operation @var{sub} - @var{clip}. +## @item @var{'BA'} +## Operation of @var{clip} - @var{sub}. +## @end itemize +## +## For the matrices @var{sub} and @var{clip}, the first point is not needed to +## be repeated at the end (but is permitted). Pairs of (NaN,NaN) coordinates in +## @var{sub} and/or @var{clip} are ommitted. +## +## @var{X} is a column vector containing the X coordinates of the vertices for. +## resultant polygon(s). +## +## @var{Y} is a column vector containing the Y coordinates of the vertices for. +## resultant polygon(s). +## +## @var{nPol} is the number of output polygons. +## +## @var{nInt} is the number of intersections between @var{sub} and @var{clip}. +## +## @var{nPert} is the number of perturbed points of the @var{clip} polygon in +## any particular case (points in the oborder of the other polygon) occurs see +## http://davis.wpi.edu/~matt/courses/clipping/ for details. +## @end deftypefn + + + + +function [X,Y,nPol,nInt,nPert] = oc_polybool(sub,clip,op) + +try + functionName = 'oc_polybool'; + minArg = 2; + maxArg = 3; + +%******************************************************************************* +%NUMBER OF INPUT ARGUMENTS CHECKING +%******************************************************************************* + + %number of input arguments checking + if (nargin<minArg)||(nargin>maxArg) + error(['Incorrect number of input arguments (%d)\n\t ',... + 'Correct number of input arguments = %d or %d'],... + nargin,minArg,maxArg); + end + %check if we omit the op argument + if nargin==minArg + %by default, use AND + op = 'AND'; + end + +%******************************************************************************* +%INPUT ARGUMENTS CHECKING +%******************************************************************************* + + %checking input arguments + [op] = checkInputArguments(sub,clip,op); +catch + %error message + error('\n\tIn function %s:\n\t -%s ',functionName,lasterr); +end + +%******************************************************************************* +%COMPUTATION +%******************************************************************************* + +try + %calling oct function + [X,Y,nPol,nInt,nPert] = _oc_polybool(sub,clip,op); +catch + %error message + error('\n\tIn function %s:\n\tIn function %s ',functionName,lasterr); +end + + + + +%******************************************************************************* +%AUXILIARY FUNCTION +%******************************************************************************* + + + + +function [outOp] = checkInputArguments(sub,clip,inOp) + +%sub must be matrix type +if ismatrix(sub) + %a dimensions + [rowSub,colSub] = size(sub); +else + error('The first input argument is not numeric'); +end +%clip must be matrix type +if ismatrix(clip) + %b dimensions + [rowClip,colClip] = size(clip); +else + error('The second input argument is not numeric'); +end +%checking dimensions +if (colSub~=2)||(colClip~=2) + error('The columns of input arguments must be 2'); +end +%operation must be a text string +if ~ischar(inOp) + error('The third input argument is not a text string'); +else + %upper case + outOp = toupper(inOp); + %check values + if (~strcmp(outOp,'AND'))&&(~strcmp(outOp,'OR'))&& ... + (~strcmp(outOp,'AB'))&&(~strcmp(outOp,'BA')) + error('The third input argument is not correct'); + end +end + + + + +%*****END OF FUNCIONS***** + + + + +%*****FUNCTION TESTS***** + + + + +%tests for input arguments +%!error(oc_polybool) +%!error(oc_polybool(1,2,3,4)) +%!error(oc_polybool('string',2,3)) +%!error(oc_polybool(1,'string',3)) +%!error(oc_polybool(1,2,3)) +%demo program +%!demo +%! %subject polygon +%! clSub = [9.0 7.5 +%! 9.0 3.0 +%! 2.0 3.0 +%! 2.0 4.0 +%! 8.0 4.0 +%! 8.0 5.0 +%! 2.0 5.0 +%! 2.0 6.0 +%! 8.0 6.0 +%! 8.0 7.0 +%! 2.0 7.0 +%! 2.0 7.5 +%! 9.0 7.5]; +%! %clipper polygon +%! clClip = [2.5 1.0 +%! 7.0 1.0 +%! 7.0 8.0 +%! 6.0 8.0 +%! 6.0 2.0 +%! 5.0 2.0 +%! 5.0 8.0 +%! 4.0 8.0 +%! 4.0 2.0 +%! 3.0 2.0 +%! 3.0 8.0 +%! 2.5 8.0 +%! 2.5 1.0]; +%! %limits for the plots +%! clXLim = [1.5 11.75]; +%! clYLim = [0.5 8.50]; +%! %compute intersection +%! [clXI,clYI] = oc_polybool(clSub,clClip,'and'); +%! %compute union +%! [clXU,clYU] = oc_polybool(clSub,clClip,'or'); +%! %compute A-B +%! [clXA,clYA] = oc_polybool(clSub,clClip,'ab'); +%! %compute B-A +%! [clXB,clYB] = oc_polybool(clSub,clClip,'ba'); +%! %plot window for intersection +%! subplot(2,2,1); +%! plot(clXI,clYI,'r.-','markersize',10,'linewidth',3,clSub(:,1),clSub(:,2),... +%! clClip(:,1),clClip(:,2)); +%! axis('equal'); +%! xlim(clXLim); +%! ylim(clYLim); +%! title('OctCLIP intersection'); +%! legend('Intersection','Subject polygon','Clipper polygon',... +%! 'location','southeast'); +%! %plot window for union +%! subplot(2,2,2); +%! plot(clXU,clYU,'r.-','markersize',10,'linewidth',3,clSub(:,1),clSub(:,2),... +%! clClip(:,1),clClip(:,2)); +%! axis('equal'); +%! xlim(clXLim); +%! ylim(clYLim); +%! title('OctCLIP union'); +%! legend('Union','Subject polygon','Clipper polygon','location','southeast'); +%! %plot window for A-B +%! subplot(2,2,3); +%! plot(clXA,clYA,'r.-','markersize',10,'linewidth',3,clSub(:,1),clSub(:,2),... +%! clClip(:,1),clClip(:,2)); +%! axis('equal'); +%! xlim(clXLim); +%! ylim(clYLim); +%! title('OctCLIP A-B'); +%! legend('A-B','Subject polygon','Clipper polygon','location','southeast'); +%! %plot window for B-A +%! subplot(2,2,4); +%! plot(clXB,clYB,'r.-','markersize',10,'linewidth',3,clSub(:,1),clSub(:,2),... +%! clClip(:,1),clClip(:,2)); +%! axis('equal'); +%! xlim(clXLim); +%! ylim(clYLim); +%! title('OctCLIP B-A'); +%! legend('B-A','Subject polygon','Clipper polygon','location','southeast'); +%! %input message +%! disp('Press ENTER to continue ...'); +%! pause(); +%! %kill and close the plot window +%! clf(); +%! close(); + + + + +%*****END OF TESTS***** Added: trunk/octave-forge/main/geometry/inst/octclip/src/Makefile =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/Makefile (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/Makefile 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +CC=mkoctfile + +.PHONY: all +all: compile clean + +.PHONY: compile +compile: + $(CC) -c -Wall -Wextra -I. compilador.c -o compilador.o + $(CC) -c -Wall -Wextra -I. errores.c -o errores.o + $(CC) -c -Wall -Wextra -I. eucli.c -o eucli.o + $(CC) -c -Wall -Wextra -I. fgeneral.c -o fgeneral.o + $(CC) -c -Wall -Wextra -I. greiner.c -o greiner.o + $(CC) -c -Wall -Wextra -I. polig.c -o polig.o + $(CC) -c -Wall -Wextra -I. ptopol.c -o ptopol.o + $(CC) -c -Wall -Wextra -I. segmento.c -o segmento.o + $(CC) -c -Wall -Wextra -I. ventorno.c -o ventorno.o + $(CC) -s -Wall -Wextra -I. _oc_polybool.cc *.o + +.PHONY: clean +clean: + rm -rf *.o *~ Added: trunk/octave-forge/main/geometry/inst/octclip/src/_oc_polybool.cc =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/_oc_polybool.cc (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/_oc_polybool.cc 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,240 @@ +/* -*- coding: utf-8 -*- */ +/* Copyright (C) 2011 José Luis García Pallero, <jgp...@gm...> + * + * This file is part of OctCLIP. + * + * OctCLIP 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. + * + * This program 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 this software; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + */ +/******************************************************************************/ +/******************************************************************************/ +#define HELPTEXT "\ +-*- texinfo -*-\n\ +@deftypefn{Loadable Function}{[@var{X},@var{Y},@var{nPol},@var{nInt},\ +@var{nPert}] =}_oc_polybool(@var{sub},@var{clip},@var{op})\n\ +\n\ +@cindex Performs boolean operations between two polygons.\n\ +\n\ +This function performs boolean operations between two polygons using the\n\ +Greiner-Hormann algorithm (http://davis.wpi.edu/~matt/courses/clipping/).\n\ +\n\ +@var{sub} is a two column matrix containing the X and Y coordinates of the\n\ +vertices for the subject polygon.\n\n\ +@var{clip} is a two column matrix containing the X and Y coordinates of the\n\ +vertices for the clipper polygon.\n\n\ +@var{op} is a text string containing the operation to perform between\n\ +@var{sub} and @var{clip}. Possible values are:\n\ +\n\ +@itemize @bullet\n\ +@item @var{'AND'}\n\ +Intersection of @var{sub} and @var{clip}.\n\n\ +@item @var{'OR'}\n\ +Union of @var{subt} and @var{clip}.\n\n\ +@item @var{'AB'}\n\ +Operation @var{sub} - @var{clip}.\n\n\ +@item @var{'BA'}\n\ +Operation of @var{clip} - @var{sub}.\n\ +@end itemize\n\ +\n\ +For the matrices @var{sub} and @var{clip}, the first point is not needed to\n\ +be repeated at the end (but is permitted). Pairs of (NaN,NaN) coordinates in\n\ +@var{sub} and/or @var{clip} are ommitted.\n\ +\n\ +@var{X} is a column vector containing the X coordinates of the vertices for.\n\ +resultant polygon(s).\n\n\ +@var{Y} is a column vector containing the Y coordinates of the vertices for.\n\ +resultant polygon(s).\n\n\ +@var{nPol} is the number of output polygons.\n\n\ +@var{nInt} is the number of intersections between @var{sub} and @var{clip}.\n\n\ +@var{nPert} is the number of perturbed points of the @var{clip} polygon in\n\ +any particular case (points in the oborder of the other polygon) occurs see\n\ +http://davis.wpi.edu/~matt/courses/clipping/ for details.\n\ +\n\ +This function do not check if the dimensions of @var{sub} and @var{clip} are\n\ +correct.\n\ +\n\ +@end deftypefn" +/******************************************************************************/ +/******************************************************************************/ +#include<octave/oct.h> +#include<cstdio> +#include<cstring> +#include<cstdlib> +#include<cmath> +#include"octclip.h" +/******************************************************************************/ +/******************************************************************************/ +#define ERRORTEXT 1000 +/******************************************************************************/ +/******************************************************************************/ +DEFUN_DLD(_oc_polybool,args,,HELPTEXT) +{ + //error message + char errorText[ERRORTEXT+1]="_oc_polybool:\n\t"; + //output list + octave_value_list outputList; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //checking input arguments + if(args.length()!=3) + { + //error text + sprintf(&errorText[strlen(errorText)], + "Incorrect number of input arguments\n\t" + "See help _oc_polybool"); + //error message + error(errorText); + } + else + { + //loop index + size_t i=0; + //polygons and operation + ColumnVector xSubj=args(0).matrix_value().column(0); + ColumnVector ySubj=args(0).matrix_value().column(1); + ColumnVector xClip=args(1).matrix_value().column(0); + ColumnVector yClip=args(1).matrix_value().column(1); + std::string opchar=args(2).string_value(); + //computation vectors + double* xA=NULL; + double* yA=NULL; + double* xB=NULL; + double* yB=NULL; + //double linked lists + vertPoliClip* polA=NULL; + vertPoliClip* polB=NULL; + //operation identifier + enum GEOC_OP_BOOL_POLIG op=GeocOpBoolInter; + //output struct + poligGreiner* result=NULL; + //number of polygons, intersections and perturbations + size_t nPol=0,nInter=0,nPert=0; + //number of elements for the output vectors + size_t nElem=0; + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //pointers to data + xA = xSubj.fortran_vec(); + yA = ySubj.fortran_vec(); + xB = xClip.fortran_vec(); + yB = yClip.fortran_vec(); + //create double linked lists for subject and clipper polygons + polA = CreaPoliClip(xA,yA,static_cast<size_t>(xSubj.length()),1,1); + polB = CreaPoliClip(xB,yB,static_cast<size_t>(xClip.length()),1,1); + //error checking + if((polB==NULL)||(polB==NULL)) + { + //free peviously allocated memory + LibMemPoliClip(polA); + LibMemPoliClip(polB); + //error text + sprintf(&errorText[strlen(errorText)],"Error in memory allocation"); + //error message + error(errorText); + //exit + return outputList; + } + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //select operation + if((!strcmp(opchar.c_str(),"AND"))||(!strcmp(opchar.c_str(),"and"))) + { + op = GeocOpBoolInter; + } + else if((!strcmp(opchar.c_str(),"OR"))||(!strcmp(opchar.c_str(),"or"))) + { + op = GeocOpBoolUnion; + } + else if((!strcmp(opchar.c_str(),"AB"))||(!strcmp(opchar.c_str(),"ab"))) + { + op = GeocOpBoolAB; + } + else if((!strcmp(opchar.c_str(),"BA"))||(!strcmp(opchar.c_str(),"ba"))) + { + op = GeocOpBoolBA; + } + else + { + //free peviously allocated memory + LibMemPoliClip(polA); + LibMemPoliClip(polB); + //error text + sprintf(&errorText[strlen(errorText)], + "The third input argument (op=%s) is not correct", + opchar.c_str()); + //error message + error(errorText); + //exit + return outputList; + } + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //clipping + result = PoliBoolGreiner(polA,polB,op,GEOC_GREINER_FAC_EPS_PERTURB, + &nInter,&nPert); + //error checking + if(result==NULL) + { + //free peviously allocated memory + LibMemPoliClip(polA); + LibMemPoliClip(polB); + //error text + sprintf(&errorText[strlen(errorText)],"Error in memory allocation"); + //error message + error(errorText); + //exit + return outputList; + } + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //number or output polygons + nPol = result->nPolig; + //dimensions for the output vectors + if(nPol) + { + nElem = result->nElem; + } + else + { + nElem = 0; + } + //output vectors + ColumnVector xResult(nElem); + ColumnVector yResult(nElem); + //copy output data + for(i=0;i<nElem;i++) + { + xResult(i) = result->x[i]; + yResult(i) = result->y[i]; + } + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //output parameters list + outputList(0) = xResult; + outputList(1) = yResult; + outputList(2) = nPol; + outputList(3) = nInter; + outputList(4) = nPert; + //////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// + //free memory + LibMemPoliClip(polA); + LibMemPoliClip(polB); + LibMemPoligGreiner(result); + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //exit + return outputList; +} Added: trunk/octave-forge/main/geometry/inst/octclip/src/compilador.c =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/compilador.c (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/compilador.c 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,75 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup general geopot +@{ +\file compilador.c +\brief Definición de funciones para la detección de compiladores. +\author José Luis García Pallero, jgp...@gm... +\date 28 de abril de 2011 +\version 1.0 +\section Licencia Licencia +Copyright (c) 2011, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- 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. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 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 COPYRIGHT HOLDER BE 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 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 POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/compilador.h" +/******************************************************************************/ +/******************************************************************************/ +int EsCompiladorGNU(int* noGnu) +{ + //variable de salida + int salida=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //inicializamos la variable noGnu, si ha lugar + if(noGnu!=NULL) + { + //inicializamos la variable a 0 + *noGnu = 0; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //para que sea GCC, la constante __GNUC__ ha de estar definida +#if defined(__GNUC__) + //el compilador es GCC + salida = 1; + //comprobamos si es el compilador de intel +#if defined(__INTEL_COMPILER) + if(noGnu!=NULL) + { + //el compilador es de intel + *noGnu = 1; + } +#endif +#endif + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +/** @} */ Property changes on: trunk/octave-forge/main/geometry/inst/octclip/src/compilador.c ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/geometry/inst/octclip/src/errores.c =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/errores.c (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/errores.c 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,112 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup anespec errores eop fichero general geodesia geom geopot gshhs marea +\ingroup matriz mmcc orden snx texto +@{ +\file errores.c +\brief Definición de funciones para el tratamiento de errores. + +En el momento de la compilación ha de seleccionarse el comportamiento de la +función \ref GeocError. Para realizar la selección es necesario definir las +variables para el preprocesador \em ESCRIBE_MENSAJE_ERROR si se quiere que la +función imprima un mensaje de error y/o \em FIN_PROGRAMA_ERROR si se quiere que +la función termine la ejecución del programa en curso. Si no se define ninguna +variable, la función no ejecuta ninguna acción. En \p gcc, las variables para el +preprocesador se pasan como \em -DXXX, donde \em XXX es la variable a +introducir. +\author José Luis García Pallero, jgp...@gm... +\date 09 de enero de 2011 +\section Licencia Licencia +Copyright (c) 2009-2011, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- 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. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 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 COPYRIGHT HOLDER BE 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 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 POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/errores.h" +/******************************************************************************/ +/******************************************************************************/ +int GeocTipoError(void) +{ + //variable de salida + int valor=GEOC_TIPO_ERR_NADA; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //distinguimos los posibles casos según las variables del preprocesador +#if defined(ESCRIBE_MENSAJE_ERROR) && defined(FIN_PROGRAMA_ERROR) + //mensaje de error y terminación del programa + valor = GEOC_TIPO_ERR_MENS_Y_EXIT; +#elif defined(ESCRIBE_MENSAJE_ERROR) + //mensaje de error + valor = GEOC_TIPO_ERR_MENS; +#elif defined(FIN_PROGRAMA_ERROR) + //terminación del programa + valor = GEOC_TIPO_ERR_EXIT; +#endif + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return valor; +} +/******************************************************************************/ +/******************************************************************************/ +void GeocError(const char mensaje[], + const char funcion[]) +{ + //hacemos una copia para que en la compilación no dé warning si sólo se + //termina la ejecución del programa o no se hace nada + mensaje = mensaje; + funcion = funcion; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //distinguimos los posibles casos según las variables del preprocesador +#if defined(ESCRIBE_MENSAJE_ERROR) && defined(FIN_PROGRAMA_ERROR) + //imprimimos el nombre de la función y el mensaje + fprintf(stderr,"En la función '%s'\n",funcion); + fprintf(stderr,"%s\n",mensaje); + //indicamos que el programa finalizará + fprintf(stderr,"El programa finalizará mediante la llamada a la función " + "'exit(EXIT_FAILURE)'\n"); + //detenemos la ejecución del programa + exit(EXIT_FAILURE); +#elif defined(ESCRIBE_MENSAJE_ERROR) + //imprimimos el nombre de la función y el mensaje + fprintf(stderr,"En la función '%s'\n",funcion); + fprintf(stderr,"%s\n",mensaje); + //salimos de la función + return; +#elif defined(FIN_PROGRAMA_ERROR) + //indicamos que el programa finalizará + fprintf(stderr,"El programa finalizará mediante la llamada a la función " + "'exit(EXIT_FAILURE)'\n"); + //detenemos la ejecución del programa + exit(EXIT_FAILURE); +#else + //salimos de la función + return; +#endif +} +/******************************************************************************/ +/******************************************************************************/ +/** @} */ Property changes on: trunk/octave-forge/main/geometry/inst/octclip/src/errores.c ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/geometry/inst/octclip/src/eucli.c =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/eucli.c (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/eucli.c 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,160 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup geom interp +@{ +\file eucli.c +\brief Definición de funciones para la realización de cálculos de geometría + euclídea. +\author José Luis García Pallero, jgp...@gm... +\date 27 de octubre de 2009 +\section Licencia Licencia +Copyright (c) 2009-2010, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- 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. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 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 COPYRIGHT HOLDER BE 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 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 POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/eucli.h" +/******************************************************************************/ +/******************************************************************************/ +double Dist2D(const double x1, + const double y1, + const double x2, + const double y2) +{ + //calculamos y salimos de la función + return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); +} +/******************************************************************************/ +/******************************************************************************/ +void Dist2DVC(const double x1, + const double y1, + const double x2, + const double y2, + const double varx1, + const double varx1y1, + const double vary1, + const double varx2, + const double varx2y2, + const double vary2, + double* dist, + double* varDist) +{ + //matrices auxiliares + double j[4],jvc[4]; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos la distancia + *dist = Dist2D(x1,y1,x2,y2); + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //rellenamos la matriz jacobiana + j[0] = -(x2-x1)/(*dist); + j[1] = -(y2-y1)/(*dist); + j[2] = -j[0]; + j[3] = -j[1]; + //producto de la matriz jacobiana por la matriz de varianza-covarianza + jvc[0] = j[0]*varx1+j[1]*varx1y1; + jvc[1] = j[0]*varx1y1+j[1]*vary1; + jvc[2] = j[2]*varx2+j[3]*varx2y2; + jvc[3] = j[2]*varx2y2+j[3]*vary2; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //realizamos la propagación de errores + *varDist = jvc[0]*j[0]+jvc[1]*j[1]+jvc[2]*j[2]+jvc[3]*j[3]; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +double Dist3D(const double x1, + const double y1, + const double z1, + const double x2, + const double y2, + const double z2) +{ + //calculamos y salimos de la función + return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1)); +} +/******************************************************************************/ +/******************************************************************************/ +void Dist3DVC(const double x1, + const double y1, + const double z1, + const double x2, + const double y2, + const double z2, + const double varx1, + const double varx1y1, + const double varx1z1, + const double vary1, + const double vary1z1, + const double varz1, + const double varx2, + const double varx2y2, + const double varx2z2, + const double vary2, + const double vary2z2, + const double varz2, + double* dist, + double* varDist) +{ + //matrices auxiliares + double j[6],jvc[6]; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos la distancia + *dist = Dist3D(x1,y1,z1,x2,y2,z2); + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //rellenamos la matriz jacobiana + j[0] = -(x2-x1)/(*dist); + j[1] = -(y2-y1)/(*dist); + j[2] = -(z2-z1)/(*dist); + j[3] = -j[0]; + j[4] = -j[1]; + j[5] = -j[2]; + //producto de la matriz jacobiana por la matriz de varianza-covarianza + jvc[0] = j[0]*varx1+j[1]*varx1y1+j[2]*varx1z1; + jvc[1] = j[0]*varx1y1+j[1]*vary1+j[2]*vary1z1; + jvc[2] = j[0]*varx1z1+j[1]*vary1z1+j[2]*varz1; + jvc[3] = j[3]*varx2+j[4]*varx2y2+j[5]*varx2z2; + jvc[4] = j[3]*varx2y2+j[4]*vary2+j[5]*vary2z2; + jvc[5] = j[3]*varx2z2+j[4]*vary2z2+j[5]*varz2; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //realizamos la propagación de errores + *varDist = jvc[0]*j[0]+jvc[1]*j[1]+jvc[2]*j[2]+jvc[3]*j[3]+jvc[4]*j[4]+ + jvc[5]*j[5]; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +/** @} */ Property changes on: trunk/octave-forge/main/geometry/inst/octclip/src/eucli.c ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/geometry/inst/octclip/src/fgeneral.c =================================================================== --- trunk/octave-forge/main/geometry/inst/octclip/src/fgeneral.c (rev 0) +++ trunk/octave-forge/main/geometry/inst/octclip/src/fgeneral.c 2011-11-20 23:32:21 UTC (rev 9156) @@ -0,0 +1,500 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup eop general geom geopot matriz +@{ +\file fgeneral.c +\brief Definición de funciones de utilidad general. +\author José Luis García Pallero, jgp...@gm... +\date 10 de octubre de 2009 +\version 1.0 +\section Licencia Licencia +Copyright (c) 2009-2011, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- 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. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 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 COPYRIGHT HOLDER BE 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 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 POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/fgeneral.h" +/******************************************************************************/ +/******************************************************************************/ +void BuscaSegmento1DInc(const double valor, + const double* lista, + const size_t nDatos, + const size_t incDatos, + size_t* posInicio, + size_t* posFin) +{ + //variable para recorrer bucles + size_t i=0; + //variable indicadora de búsqueda secuencial + int busca=0; + //variables para calcular posiciones + size_t pos1=0,pos2=0; + //posiciones en memoria + size_t posm=0,pos1m=0,pos2m=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //CONSIDERAMOS QUE LA LISTA CONTIENE ENTEROS EQUIESPACIADOS UNA UNIDAD + //posición del valor anterior al de trabajo + pos1 = (size_t)(floor(valor)-lista[0]); + //posición del valor posterior al de trabajo + pos2 = (size_t)(ceil(valor)-lista[0]); + //si pos1==pos2, valor puede ser un extremo de la lista + if(pos1==pos2) + { + if(pos1!=(nDatos-1)) + { + //calculamos el punto final del segmento + pos2++; + } + else + { + //calculamos el punto inicial del segmento + pos1--; + } + } + //calculamos las posiciones en memoria + pos1m = pos1*incDatos; + pos2m = pos2*incDatos; + //comprobamos si el segmento detectado es válido + if((lista[pos1m]!=round(lista[pos1m]))|| + (lista[pos2m]!=round(lista[pos2m]))|| + ((lista[pos2m]-lista[pos1m])!=1.0)|| + (valor<lista[pos1m])||(valor>lista[pos2m])) + { + //indicamos que se ha de hacer una búsqueda secuencial + busca = 1; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //LA LISTA CONTIENE REALES NO EQUIESPACIADOS + if(busca) + { + //recorremos todos los elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición en memoria + posm = i*incDatos; + //comprobamos si estamos ante un límite + if(lista[posm]>=valor) + { + //comprobamos el tipo de límite + if(lista[posm]>valor) + { + //extraemos las posiciones + pos1 = i-1; + pos2 = i; + } + else + { + //comprobamos si estamos trabajando con el último elemento + if(i==(nDatos-1)) + { + //extraemos las posiciones + pos1 = i-1; + pos2 = i; + } + else + { + //extraemos las posiciones + pos1 = i; + pos2 = i+1; + } + } + //salimos del bucle + break; + } + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //asignamos las variables de salida + *posInicio = pos1; + *posFin = pos2; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +void BuscaSegmento1D(const double valor, + const double* lista, + const size_t nDatos, + size_t* posInicio, + size_t* posFin) +{ + //realizamos la búsqueda con incremento igual a 1 + BuscaSegmento1DInc(valor,lista,nDatos,1,posInicio,posFin); +} +/******************************************************************************/ +/******************************************************************************/ +void BuscaPosNWEnMalla(const double xPto, + const double yPto, + const double xMin, + const double xMax, + const double yMin, + const double yMax, + const double pasoX, + const double pasoY, + size_t* fil, + size_t* col) +{ + //dimensiones de la matriz + size_t f=0,c=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos las dimensiones de la matriz de trabajo + f = (size_t)(round((yMax-yMin)/pasoY)+1.0); + c = (size_t)(round((xMax-xMin)/pasoX)+1.0); + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos la fila y comprobamos si es el extremo S + *fil = f-1-(size_t)((yPto-yMin)/pasoY); + if(*fil==(f-1)) + { + //retrasamos una fila + (*fil)--; + } + //calculamos la columna y comprobamos si es el extremo E + *col = (size_t)((xPto-xMin)/pasoX); + if(*col==(c-1)) + { + //retrasamos una columna + (*col)--; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +void MinMax(const double* lista, + const size_t nDatos, + size_t* posMin, + size_t* posMax) +{ + //índice para recorrer bucles + size_t i=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //consideramos que el primer elemento es el mayor y el menor + *posMin = 0; + *posMax = 0; + //recorremos el resto de elementos de la lista + for(i=1;i<nDatos;i++) + { + //comprobamos si el elemento actual es menor que el considerado menor + if(lista[i]<lista[*posMin]) + { + //asignamos la nueva posición + *posMin = i; + } + //comprobamos si el elemento actual es mayor que el considerado mayor + if(lista[i]>lista[*posMax]) + { + //asignamos la nueva posición + *posMax = i; + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +void MinMaxAbs(const double* lista, + const size_t nDatos, + size_t* posMin, + size_t* posMax) +{ + //índice para recorrer bucles + size_t i=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //consideramos que el primer elemento es el mayor y el menor + *posMin = 0; + *posMax = 0; + //recorremos el resto de elementos de la lista + for(i=1;i<nDatos;i++) + { + //comprobamos si el elemento actual es menor que el considerado menor + if(fabs(lista[i])<fabs(lista[*posMin])) + { + //asignamos la nueva posición + *posMin = i; + } + //comprobamos si el elemento actual es mayor que el considerado mayor + if(fabs(lista[i])>fabs(lista[*posMax])) + { + //asignamos la nueva posición + *posMax = i; + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +void MinMaxSizeT(const size_t* lista, + const size_t nDatos, + size_t* posMin, + size_t* posMax) +{ + //índice para recorrer bucles + size_t i=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //consideramos que el primer elemento es el mayor y el menor + *posMin = 0; + *posMax = 0; + //recorremos el resto de elementos de la lista + for(i=1;i<nDatos;i++) + { + //comprobamos si el elemento actual es menor que el considerado menor + if(lista[i]<lista[*posMin]) + { + //asignamos la nueva posición + *posMin = i; + } + //comprobamos si el elemento actual es mayor que el considerado mayor + if(lista[i]>lista[*posMax]) + { + //asignamos la nueva posición + *posMax = i; + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +double** AsigMemMatrizC(const size_t fil, + const size_t col) +{ + //índices para recorrer bucles + size_t i=0; + //matriz de salida + double** matriz=NULL; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //asignamos memoria para el array principal + matriz = (double**)malloc(fil*sizeof(double*)); + //comprobamos los errores + if(matriz==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //asignamos toda la memoria al primer puntero + matriz[0] = (double*)malloc(fil*col*sizeof(double)); + //comprobamos los errores + if(matriz[0]==NULL) + { + //liberamos la memoria previamente asignada + free(matriz); + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + //recorremos el resto de filas + for(i=1;i<fil;i++) + { + //vamos asignando las direcciones de inicio de cada fila + matriz[i] = &matriz[0][i*col]; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return matriz; +} +/******************************************************************************/ +/******************************************************************************/ +void LibMemMatrizC(double** matriz) +{ + //sólo trabajamos si hay memoria asignada + if(matriz!=NULL) + { + //sólo trabajamos si hay memoria asignada + if(matriz[0]!=NULL) + { + //liberamos la memoria de los datos + free(matriz[0]); + } + //liberamos la memoria del array principal + free(matriz); + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +double GeocNan(void) +{ + //devolvemos el valor de NaN + //le calculamos el valor absoluto porque, en algunos sistemas, al imprimir + //un valor GEOC_NAN normal, éste sale con un signo negativo delante + return fabs(GEOC_NAN); +} +/******************************************************************************/ +/******************************************************************************/ +int EsGeocNan(const double valor) +{ + //comparamos y salimos de la función + return valor!=valor; +} +/******************************************************************************/ +/******************************************************************************/ +size_t* PosRepeEnVector(const double* datos, + const size_t nDatos, + const size_t incDatos, + size_t* nRepe) +{ + //índice para recorrer bucles + size_t i=0; + //número de repeticiones encontradas + size_t numRep=0; + //datos de las posiciones de trabajo + double dato=0.0,datoTrab=0.0; + //variable de salida + size_t* pos=NULL; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //asignamos memoria para el vector de salida + pos = (size_t*)malloc(nDatos*sizeof(double)); + //comprobamos los posibles errores + if(pos==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //inicializamos la primera posición, extraemos el dato e inicializamos el + //contador de repeticiones + pos[0] = 0; + dato = datos[0]; + numRep = 1; + //recorremos el resto de elementos del vector + for(i=1;i<nDatos;i++) + { + //extraemos el dato de trabajo + datoTrab = datos[i*incDatos]; + //lo comparamos con el dato de referencia + if(datoTrab!=dato) + { + //asignamos la nueva posición + pos[numRep] = i; + //aumentamos el contador de repeticiones + numRep++; + //convertimos el nuevo dato en dato de referencia + dato = datoTrab; + } + } + //////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////... [truncated message content] |