AGX Dynamics  2.35.0.1
Vec2.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_VEC2_H
18 #define AGX_VEC2_H
19 
20 #include <agx/Vec2Template.h>
21 #include <agxData/Type.h>
22 
23 namespace agx
24 {
25 
35  typedef Vec2T<Real> Vec2;
38 
39 
40  typedef Vec2T<Int> Vec2i;
45 
46 
47  typedef Vec2T<UInt> Vec2u;
52 
53 
54 #ifndef SWIG
55  const Vec2 X_AXIS_2D( 1.0, 0.0 );
56  const Vec2 Y_AXIS_2D( 0.0, 1.0 );
57 #endif
58 
59  // Hash function
60  template <typename T>
61  struct HashFn< Vec2T<T> >
62  {
64  {
65  const agx::UInt32 p1 = 73856093UL;
66  const agx::UInt32 p2 = 19349663UL;
67 
68  return (p1 * (agx::UInt32)id[0]) ^ (p2 * (agx::UInt32)id[1]);
69  }
70  };
71 
73  {
74  agx::Vec2i cell;
75  cell[0] = (Vec2i::Type)(x * invCellSize);
76  cell[1] = (Vec2i::Type)(y * invCellSize);
77 
78  if (x < Real(0.0)) cell[0]--;
79  if (y < Real(0.0)) cell[1]--;
80 
81  return cell;
82  }
83 
84  AGX_FORCE_INLINE Vec2i calculateCellId(const Vec2& position, Real invCellSize)
85  {
86  return calculateCellId(position[0], position[1], invCellSize);
87  }
88 
89 } // end of namespace agx
90 
91 
94 
99 
104 
105 
106 #endif
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec2T< Real32 > Vec2f
Definition: Vec2.h:36
uint32_t UInt32
Definition: Integer.h:40
Vec2T< Int > Vec2i
Definition: Vec2.h:40
const Vec2 X_AXIS_2D(1.0, 0.0)
Vec2T< Real64 > Vec2d
Definition: Vec2.h:37
Vec2T< Real > Vec2
The object holding 2 dimensional vectors and providing basic arithmetic.
Definition: Vec2.h:35
Vec2T< Int8 > Vec2i8
Definition: Vec2.h:41
const Vec2 Y_AXIS_2D(0.0, 1.0)
Vec2T< Int16 > Vec2i16
Definition: Vec2.h:42
double Real
Definition: Real.h:42
Vec2T< UInt16 > Vec2u16
Definition: Vec2.h:49
Vec2T< Int64 > Vec2i64
Definition: Vec2.h:44
Vec2T< UInt > Vec2u
Definition: Vec2.h:47
Vec2T< UInt64 > Vec2u64
Definition: Vec2.h:51
Vec2i calculateCellId(Real x, Real y, Real invCellSize)
Definition: Vec2.h:72
Vec2T< UInt32 > Vec2u32
Definition: Vec2.h:50
Vec2T< Int32 > Vec2i32
Definition: Vec2.h:43
Vec2T< UInt8 > Vec2u8
Definition: Vec2.h:48
agx::UInt32 operator()(const Vec2T< T > &id) const
Definition: Vec2.h:63