home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / POLYTOPE.ZIP / vectorval.inc < prev   
Encoding:
Text File  |  1997-08-01  |  2.0 KB  |  70 lines

  1. /*
  2.  
  3.     POLYTOPE OBJECT INCLUDE FILE v1.0b - vectorval include file
  4.     Copyright (C) 1997 Thomas Willhalm
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. */
  22.  
  23. /*
  24.      Convert string to vector
  25.  
  26.      Usage:
  27.     PRE:  <string_vector> is string of a vector
  28.                       with no additional blanks
  29.     POST: <float_vector>  vector with contents of <string_vector>
  30.     SIDE: <__cur_pos>, <__old_pos>, <__x>, <__y> altered
  31. */
  32.  
  33. // checking
  34. #ifndef (string_vector)
  35.     #error "string_vector undefined"
  36. #end
  37.  
  38. #if (strcmp(substr(string_vector,1,1),"<"))
  39.     #error "string_vector does not start with <"
  40. #end
  41.  
  42. // find first comma
  43. #declare __cur_pos=1
  44. #while (strcmp(substr(string_vector,__cur_pos,1),","))
  45.     #declare __cur_pos = __cur_pos+1
  46. #end
  47.  
  48. // store first coordinate
  49. #declare __x = val(substr(string_vector,2,__cur_pos-2))
  50.  
  51. // find second comma
  52. #declare __cur_pos = __cur_pos+1
  53. #declare __old_pos = __cur_pos
  54. #while (strcmp(substr(string_vector,__cur_pos,1),","))
  55.     #declare __cur_pos = __cur_pos+1
  56. #end
  57.  
  58. // store second coordinate
  59. #declare __y = val(substr(string_vector,__old_pos,__cur_pos-__old_pos))
  60.  
  61. // find terminating >
  62. #declare __cur_pos = __cur_pos+1
  63. #declare __old_pos = __cur_pos
  64. #while (strcmp(substr(string_vector,__cur_pos,1),">"))
  65.     #declare __cur_pos = __cur_pos+1
  66. #end
  67.  
  68. // store result
  69. #declare float_vector = <__x,__y,val(substr(string_vector,__old_pos,__cur_pos-__old_pos))>
  70.