Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
2.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef DISP_VERTINDEX_H
  8. #define DISP_VERTINDEX_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier0/dbg.h"
  13. // ------------------------------------------------------------------------ //
  14. // Helper class used for indexing vertices in the 2D grid.
  15. // ------------------------------------------------------------------------ //
  16. class CVertIndex
  17. {
  18. public:
  19. CVertIndex();
  20. CVertIndex( short ix, short iy );
  21. void Init( short ix, short iy );
  22. short& operator[]( short i );
  23. short const& operator[]( short i ) const;
  24. void operator+=( CVertIndex const &other );
  25. void operator-=( CVertIndex const &other );
  26. CVertIndex operator+( CVertIndex const &other ) const;
  27. CVertIndex operator-( CVertIndex const &other ) const;
  28. void operator<<=( int shift );
  29. void operator>>=( int shift );
  30. bool operator==( CVertIndex const &other ) const;
  31. bool operator!=( CVertIndex const &other ) const;
  32. public:
  33. short x, y;
  34. };
  35. // ------------------------------------------------------------------ //
  36. // Helper functions.
  37. // ------------------------------------------------------------------ //
  38. inline CVertIndex BuildOffsetVertIndex(
  39. CVertIndex const &nodeIndex,
  40. CVertIndex const &offset,
  41. int mul )
  42. {
  43. return CVertIndex( nodeIndex.x + offset.x * mul, nodeIndex.y + offset.y * mul );
  44. }
  45. // ------------------------------------------------------------------ //
  46. // CVertIndex inlines.
  47. // ------------------------------------------------------------------ //
  48. inline CVertIndex::CVertIndex()
  49. {
  50. }
  51. inline CVertIndex::CVertIndex( short ix, short iy )
  52. {
  53. x = ix;
  54. y = iy;
  55. }
  56. inline void CVertIndex::Init( short ix, short iy )
  57. {
  58. x = ix;
  59. y = iy;
  60. }
  61. inline short& CVertIndex::operator[]( short i )
  62. {
  63. Assert( i >= 0 && i <= 1 );
  64. return ((short*)this)[i];
  65. }
  66. inline short const& CVertIndex::operator[]( short i ) const
  67. {
  68. Assert( i >= 0 && i <= 1 );
  69. return ((short*)this)[i];
  70. }
  71. inline void CVertIndex::operator+=( CVertIndex const &other )
  72. {
  73. x += other.x;
  74. y += other.y;
  75. }
  76. inline void CVertIndex::operator-=( CVertIndex const &other )
  77. {
  78. x -= other.x;
  79. y -= other.y;
  80. }
  81. inline CVertIndex CVertIndex::operator+( CVertIndex const &other ) const
  82. {
  83. return CVertIndex( x + other.x, y + other.y );
  84. }
  85. inline CVertIndex CVertIndex::operator-( CVertIndex const &other ) const
  86. {
  87. return CVertIndex( x - other.x, y - other.y );
  88. }
  89. inline void CVertIndex::operator<<=( int shift )
  90. {
  91. x <<= shift;
  92. y <<= shift;
  93. }
  94. inline void CVertIndex::operator>>=( int shift )
  95. {
  96. x >>= shift;
  97. y >>= shift;
  98. }
  99. inline bool CVertIndex::operator==( CVertIndex const &other ) const
  100. {
  101. return x==other.x && y==other.y;
  102. }
  103. inline bool CVertIndex::operator!=( CVertIndex const &other ) const
  104. {
  105. return x!=other.x || y!=other.y;
  106. }
  107. #endif // DISP_VERTINDEX_H