lvecBase2_src.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Filename: lvecBase2_src.h
  2. // Created by: drose (08Mar00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. //typedef struct {FLOATTYPE _0, _1} FLOATNAME(data);
  19. ////////////////////////////////////////////////////////////////////
  20. // Class : LVecBase2
  21. // Description : This is the base class for all two-component
  22. // vectors and points.
  23. ////////////////////////////////////////////////////////////////////
  24. class EXPCL_PANDA FLOATNAME(LVecBase2) {
  25. PUBLISHED:
  26. typedef const FLOATTYPE *iterator;
  27. typedef const FLOATTYPE *const_iterator;
  28. INLINE_LINMATH FLOATNAME(LVecBase2)();
  29. INLINE_LINMATH FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) &copy);
  30. INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) &copy);
  31. INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value);
  32. INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE fill_value);
  33. INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y);
  34. ALLOC_DELETED_CHAIN(FLOATNAME(LVecBase2));
  35. INLINE_LINMATH static const FLOATNAME(LVecBase2) &zero();
  36. INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_x();
  37. INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_y();
  38. INLINE_LINMATH ~FLOATNAME(LVecBase2)();
  39. INLINE_LINMATH FLOATTYPE operator [](int i) const;
  40. INLINE_LINMATH FLOATTYPE &operator [](int i);
  41. INLINE_LINMATH bool is_nan() const;
  42. INLINE_LINMATH FLOATTYPE get_cell(int i) const;
  43. INLINE_LINMATH FLOATTYPE get_x() const;
  44. INLINE_LINMATH FLOATTYPE get_y() const;
  45. INLINE_LINMATH void set_cell(int i, FLOATTYPE value);
  46. INLINE_LINMATH void set_x(FLOATTYPE value);
  47. INLINE_LINMATH void set_y(FLOATTYPE value);
  48. // These next functions add to an existing value.
  49. // i.e. foo.set_x(foo.get_x() + value)
  50. // These are useful to reduce overhead in scripting
  51. // languages:
  52. INLINE_LINMATH void add_to_cell(int i, FLOATTYPE value);
  53. INLINE_LINMATH void add_x(FLOATTYPE value);
  54. INLINE_LINMATH void add_y(FLOATTYPE value);
  55. INLINE_LINMATH const FLOATTYPE *get_data() const;
  56. INLINE_LINMATH int get_num_components() const;
  57. public:
  58. INLINE_LINMATH iterator begin();
  59. INLINE_LINMATH iterator end();
  60. INLINE_LINMATH const_iterator begin() const;
  61. INLINE_LINMATH const_iterator end() const;
  62. PUBLISHED:
  63. INLINE_LINMATH void fill(FLOATTYPE fill_value);
  64. INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y);
  65. INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &other) const;
  66. INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase2) &other) const;
  67. INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase2) &other) const;
  68. INLINE_LINMATH bool operator != (const FLOATNAME(LVecBase2) &other) const;
  69. INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other) const;
  70. INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other,
  71. FLOATTYPE threshold) const;
  72. INLINE_LINMATH size_t get_hash() const;
  73. INLINE_LINMATH size_t get_hash(FLOATTYPE threshold) const;
  74. INLINE_LINMATH size_t add_hash(size_t hash) const;
  75. INLINE_LINMATH size_t add_hash(size_t hash, FLOATTYPE threshold) const;
  76. INLINE_LINMATH FLOATNAME(LVecBase2) operator - () const;
  77. INLINE_LINMATH FLOATNAME(LVecBase2)
  78. operator + (const FLOATNAME(LVecBase2) &other) const;
  79. INLINE_LINMATH FLOATNAME(LVecBase2)
  80. operator - (const FLOATNAME(LVecBase2) &other) const;
  81. INLINE_LINMATH FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar) const;
  82. INLINE_LINMATH FLOATNAME(LVecBase2) operator / (FLOATTYPE scalar) const;
  83. INLINE_LINMATH void operator += (const FLOATNAME(LVecBase2) &other);
  84. INLINE_LINMATH void operator -= (const FLOATNAME(LVecBase2) &other);
  85. INLINE_LINMATH void operator *= (FLOATTYPE scalar);
  86. INLINE_LINMATH void operator /= (FLOATTYPE scalar);
  87. INLINE_LINMATH FLOATNAME(LVecBase2) fmax(const FLOATNAME(LVecBase2) &other);
  88. INLINE_LINMATH FLOATNAME(LVecBase2) fmin(const FLOATNAME(LVecBase2) &other);
  89. INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other,
  90. FLOATTYPE threshold) const;
  91. INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other) const;
  92. INLINE_LINMATH void output(ostream &out) const;
  93. #ifdef HAVE_PYTHON
  94. INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
  95. #endif
  96. public:
  97. INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;
  98. INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen,
  99. FLOATTYPE threshold) const;
  100. public:
  101. union {
  102. FLOATTYPE data[2];
  103. struct {FLOATTYPE _0, _1;} v;
  104. } _v;
  105. private:
  106. static const FLOATNAME(LVecBase2) _zero;
  107. static const FLOATNAME(LVecBase2) _unit_x;
  108. static const FLOATNAME(LVecBase2) _unit_y;
  109. public:
  110. INLINE_LINMATH void write_datagram(Datagram &destination) const;
  111. INLINE_LINMATH void read_datagram(DatagramIterator &source);
  112. public:
  113. static TypeHandle get_class_type() {
  114. return _type_handle;
  115. }
  116. static void init_type();
  117. private:
  118. static TypeHandle _type_handle;
  119. };
  120. INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LVecBase2) &vec) {
  121. vec.output(out);
  122. return out;
  123. }
  124. #include "lvecBase2_src.I"