HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_Vector2.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_Vector2_h__
10 #define __HOM_Vector2_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include "HOM_Errors.h"
15 #include "HOM_Matrix2.h"
16 #include "HOM_Module.h"
17 #include "HOM_PtrOrNull.h"
18 #include <UT/UT_Vector2.h>
19 #include <vector>
20 #include <stdexcept>
21 
23 
25 {
26 public:
28  : myVector2(0.0, 0.0)
29  { HOM_CONSTRUCT_OBJECT(this) }
30 
31  HOM_Vector2(double x, double y)
32  : myVector2(x, y)
33  { HOM_CONSTRUCT_OBJECT(this) }
34 
36  HOM_Vector2(const HOM_Vector2 &vector2)
37  : myVector2(vector2.myVector2)
38  { HOM_CONSTRUCT_OBJECT(this) }
39 
41  HOM_Vector2(const UT_Vector2D &vector2)
42  : myVector2(vector2)
43  { HOM_CONSTRUCT_OBJECT(this) }
44 
46  HOM_Vector2(const UT_Vector2F &vector2)
47  : myVector2(vector2)
48  { HOM_CONSTRUCT_OBJECT(this) }
49 
50  HOM_Vector2(const std::vector<double> &sequence)
51  {
53  setTo(sequence);
54  }
55 
57  { HOM_DESTRUCT_OBJECT(this) }
58 
60  { return vector2.myPointer && myVector2 == vector2.myPointer->myVector2; }
61 
63  { return !operator==(vector2); }
64 
65  bool isAlmostEqual(HOM_Vector2 &vector2, double tolerance=0.00001);
66 
67  // This method is deprecated.
68  bool almostEqual(HOM_Vector2 &vector2, double tolerance=0.00001)
69  { return isAlmostEqual(vector2, tolerance); }
70 
71  int __hash__();
74 
75  double __getitem__(int index);
76  void __setitem__(int index, double value);
77  int __len__()
78  { return 2; }
79 
80  // operator[] exists only to make this class easier to use from C++,
81  // and isn't wrapped by swig.
82  SWIGOUT(%ignore operator[];)
83  double &operator[](int index);
84 
85  void setTo(const std::vector<double> &sequence);
86 
87  SWIGOUT(%ignore operator=;)
88  HOM_Vector2 &operator=(const HOM_Vector2& vector2)
89  {
90  myVector2 = vector2.myVector2;
91  return *this;
92  }
93 
95  { return HOM_Vector2(myVector2 + vector2.myVector2); }
97  { return HOM_Vector2(myVector2 - vector2.myVector2); }
99  { return HOM_Vector2(-myVector2); }
100  HOM_Vector2 __mul__(double scalar)
101  { return HOM_Vector2(myVector2 * scalar); }
102  HOM_Vector2 __rmul__(double scalar)
103  { return HOM_Vector2(myVector2 * scalar); }
105  { return HOM_Vector2(myVector2 * matrix2.myMatrix2); }
106  HOM_Vector2 __div__(double scalar)
107  { return HOM_Vector2(myVector2 / scalar); }
108  HOM_Vector2 __truediv__(double scalar)
109  { return HOM_Vector2(myVector2 / scalar); }
110 
112  double length()
113  { return myVector2.length(); }
114  double lengthSquared()
115  { return myVector2.length2(); }
116 
117  double distanceTo(HOM_Vector2 &vector2);
118 
119  double dot(HOM_Vector2 &vector2)
120  { return myVector2.dot(vector2.myVector2); }
121 
122  double x()
123  { return myVector2.x(); }
124  double y()
125  { return myVector2.y(); }
126 
128  { return &myVector2; }
129 
130  SWIGOUT(%ignore myVector2;)
131  UT_Vector2D myVector2;
132 
133  // Pickle Support
134  //
135  // By design, pickle doesn't not call __init__() when unpickling. This is a
136  // problem for SWIG though because it requires this in order for the object
137  // to be properly wrapped to the C++ methods. So we need to wrap the
138  // __setstate__() implementation around something that calls __init__()
139  // first. For symmetry, we also wrap __getstate__() as well. So in the
140  // Python implementation, we define __getstate__()/__setstate__() that call
141  // the internal _getstate()/_setstate() C++ methods.
142  std::vector<double> _getstate();
143  void _setstate(std::vector<double>);
144  // NOTE: Be careful with the %pythoncode below which must be indented using
145  // spaces!
146 #ifdef SWIG
147 %extend {
148 %pythoncode {
149  def __getstate__(self):
150  return self._getstate()
151  def __setstate__(self, state):
152  try:
153  self.this
154  except:
155  self.__init__()
156  self._setstate(state)
157 }
158 };
159 #endif
160 };
161 
162 #endif
void _setstate(std::vector< double >)
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1303
void setTo(const std::vector< double > &sequence)
HOM_Vector2 __truediv__(double scalar)
Definition: HOM_Vector2.h:108
double dot(HOM_Vector2 &vector2)
Definition: HOM_Vector2.h:119
void __setitem__(int index, double value)
HOM_Vector2 __neg__()
Definition: HOM_Vector2.h:98
double x()
Definition: HOM_Vector2.h:122
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
double length()
Definition: HOM_Vector2.h:112
HOM_Vector2 __mul__(const HOM_Matrix2 &matrix2)
Definition: HOM_Vector2.h:104
bool operator==(HOM_PtrOrNull< HOM_Vector2 > vector2)
Definition: HOM_Vector2.h:59
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
double __getitem__(int index)
string __repr__(VtArray< T > const &self)
Definition: wrapArray.h:349
**But if you need a or simply need to know when the task has note that the like this
Definition: thread.h:617
GLint y
Definition: glcorearb.h:103
HOM_Vector2(double x, double y)
Definition: HOM_Vector2.h:31
HOM_Vector2 __mul__(double scalar)
Definition: HOM_Vector2.h:100
void * _asVoidPointer()
Definition: HOM_Vector2.h:127
#define HOM_API
Definition: HOM_API.h:13
HOM_Vector2 __sub__(HOM_Vector2 &vector2)
Definition: HOM_Vector2.h:96
HOM_Vector2(const UT_Vector2F &vector2)
Definition: HOM_Vector2.h:46
void ignore(T const &) VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6508
double lengthSquared()
Definition: HOM_Vector2.h:114
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1302
std::string __str__()
double y()
Definition: HOM_Vector2.h:124
Definition: Types.h:285
bool operator!=(HOM_PtrOrNull< HOM_Vector2 > vector2)
Definition: HOM_Vector2.h:62
HOM_Vector2 __add__(HOM_Vector2 &vector2)
Definition: HOM_Vector2.h:94
HOM_Vector2(const UT_Vector2D &vector2)
Definition: HOM_Vector2.h:41
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
HOM_Vector2(const HOM_Vector2 &vector2)
Definition: HOM_Vector2.h:36
GLint GLenum GLint x
Definition: glcorearb.h:409
std::vector< double > _getstate()
double distanceTo(HOM_Vector3 &vector3)
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
GLuint index
Definition: glcorearb.h:786
UT_DMatrix2 myMatrix2
Definition: HOM_Matrix2.h:118
HOM_Vector2(const std::vector< double > &sequence)
Definition: HOM_Vector2.h:50
Definition: core.h:1131
HOM_Vector2 __rmul__(double scalar)
Definition: HOM_Vector2.h:102
UT_Vector2D myVector2
Definition: HOM_Vector2.h:131
bool isAlmostEqual(HOM_Vector3 &vector3, double tolerance=0.00001)
int __len__()
Definition: HOM_Vector2.h:77
HOM_Vector2 __div__(double scalar)
Definition: HOM_Vector2.h:106
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
int __hash__()
bool almostEqual(HOM_Vector2 &vector2, double tolerance=0.00001)
Definition: HOM_Vector2.h:68