Guest User

Untitled

a guest
Aug 20th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type coord2_i
  2.     x as integer
  3.     y as integer
  4. end type
  5.  
  6. type coord2_d
  7.     x as double
  8.     y as double
  9. end type
  10.  
  11. 'For radial/angle data
  12. type coord2_r
  13.     r as double
  14.     o as double
  15. end type
  16.  
  17. 'Wrapper type for all these things, and associated constants
  18.  
  19. const vector_Int = 0
  20. const vector_Dbl = 1
  21. const vector_Rad = 2 'radial types always use double precision
  22. const vector_Sph = 3 'so no need to designate data type
  23. const vector_Cyl = 4
  24. 'Most functions will be overloaded so type data isn't as important to distinguish
  25. 'here, but it's done for possible future considerations
  26.  
  27. type vector2
  28.     dataType as integer
  29.     union
  30.         i as coord2_i
  31.         d as coord2_d
  32.         r as coord2_r
  33.     end union
  34.    
  35.     declare constructor() 'defaults to double I suppose
  36.     declare constructor(x as integer, y as integer)
  37.     declare constructor(a as double, b as double, dataType as integer) 'optional parameter defaults to vector_Dbl
  38.     declare constructor(i_ as coord2_i)
  39.     declare constructor(d_ as coord2_d)
  40.     declare constructor(r_ as coord2_r)
  41.    
  42. end type
  43.  
  44. constructor vector2()
  45.     d = type(0.0d, 0.0d)
  46.     dataType = vector_Dbl
  47. end constructor
  48.  
  49. constructor vector2(x as integer, y as integer)
  50.     i = type(x,y)
  51.     dataType = vector_Int
  52. end constructor
  53.  
  54. constructor vector2(a as double, b as double, dataType as integer = vector_Dbl)
  55.     select case dataType
  56.     case vector_Dbl:
  57.         d = type(a,b)
  58.         dataType = vector_Dbl
  59.     case vector_Rad:
  60.         r = type(a,b)
  61.         dataType = vector_Rad
  62.     case else 'default to double in case garbage passed in
  63.         d = type(a,b)
  64.         dataType = vector_Dbl
  65.     end select
  66. end constructor
  67.  
  68. constructor vector2(i_ as coord2_i)
  69.     i = i_
  70.     dataType = vector_Int
  71. end constructor
  72.  
  73. constructor vector2(d_ as coord2_d)
  74.     d = d_
  75.     dataType = vector_Dbl
  76. end constructor
  77.  
  78. constructor vector2(r_ as coord2_r)
  79.     r = r_
  80.     dataType = vector_Rad
  81. end constructor
Add Comment
Please, Sign In to add comment