Ocean
JSVector2.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_INTERACTION_JS_VECTOR_2_H
9 #define META_OCEAN_INTERACTION_JS_VECTOR_2_H
10 
13 
14 #include <v8.h>
15 
16 namespace Ocean
17 {
18 
19 namespace Interaction
20 {
21 
22 namespace JavaScript
23 {
24 
25 /**
26  * This class implements a wrapper for a JavaScript Vector2 object.
27  * @ingroup interactionjs
28  */
29 class OCEAN_INTERACTION_JS_EXPORT JSVector2 : public JSObject<JSVector2, Vector2>
30 {
31  friend class JSObject<JSVector2, Vector2>;
32  friend class JSLibrary;
33 
34  public:
35 
36  /**
37  * Definition of ids for individual accessors.
38  */
39  enum AccessorId : unsigned int
40  {
41  /// The accessor for the x property, a number value.
43  /// The accessor for the y property, a number value.
44  AI_Y
45  };
46 
47  /**
48  * Definition of ids for individual functions.
49  */
50  enum FunctionId : unsigned int
51  {
52  /**
53  * Adds two vectors or adds a scalar value to this vector.
54  * <pre>
55  * Vector2 = Vector2.add(Vector2)
56  * Vector2 = Veccto2.add(Number)
57  * </pre>
58  */
60 
61  /**
62  * Determines the angle between two vectors in radian.
63  * <pre>
64  * Number = Vector2.angle(Vector2)
65  * </pre>
66  */
68 
69  /**
70  * Inverts this vector.
71  * <pre>
72  * Vector2.invert()
73  * </pre>
74  */
76 
77  /**
78  * Returns the inverted vector of this vector.
79  * <pre>
80  * Vector2 = Vector2.inverted()
81  * </pre>
82  */
84 
85  /**
86  * Returns whether two vectors are equal up to some epsilon.
87  * <pre>
88  * Boolean = Vector2.isEqual(Vector2)
89  * </pre>
90  */
92 
93  /**
94  * Returns the length of this vector.
95  * <pre>
96  * Number = Vector2.length()
97  * </pre>
98  */
100 
101  /**
102  * Returns the distance between this vector and another vector.
103  * <pre>
104  * Number = Vector2.distance(Vector2)
105  * </pre>
106  */
108 
109  /**
110  * Multiplies two vectors to determine the scalar product or multiplies this vector with a scalar.
111  * <pre>
112  * Number = Vector2.multiply(Vector2)
113  * Vector2 = Vector2.multiply(Number)
114  * </pre>
115  */
117 
118  /**
119  * Normalizes this vector so that the vector has unit length afterwards.
120  * <pre>
121  * Vector2.normalize()
122  * </pre>
123  */
125 
126  /**
127  * Returns the normalized vector of this vector, so that the new vector has unit length.
128  * <pre>
129  * Vector2 = Vector2.normalized()
130  * </pre>
131  */
133 
134  /**
135  * Returns a string with the values of this vector.
136  * <pre>
137  * String = Vector2.string()
138  * </pre>
139  */
141 
142  /**
143  * Subtracts two vectors or subtracts a scalar value from this vector.
144  * <pre>
145  * Vector2 = Vector2.subtract(Vector2)
146  * Vector2 = Veccto2.subtract(Number)
147  * </pre>
148  */
149  FI_SUBTRACT
150  };
151 
152  public:
153 
154  /**
155  * Returns the JavaScript name of this object.
156  * @return The object's JavaScript name
157  */
158  static inline const char* objectName();
159 
160  protected:
161 
162  /**
163  * Creates the function template and object template for this object.
164  */
165  static void createFunctionTemplate();
166 };
167 
168 inline const char* JSVector2::objectName()
169 {
170  return "Vector2";
171 }
172 
173 }
174 
175 }
176 
177 }
178 
179 #endif // META_OCEAN_INTERACTION_JS_VECTOR_2_H
This class implements the java script interaction library object.
Definition: JSLibrary.h:32
This class implements the base class for all native wrapper of JavaScript objects.
Definition: JSObject.h:31
This class implements a wrapper for a JavaScript Vector2 object.
Definition: JSVector2.h:30
static const char * objectName()
Returns the JavaScript name of this object.
Definition: JSVector2.h:168
FunctionId
Definition of ids for individual functions.
Definition: JSVector2.h:51
@ FI_ANGLE
Determines the angle between two vectors in radian.
Definition: JSVector2.h:67
@ FI_INVERT
Inverts this vector.
Definition: JSVector2.h:75
@ FI_IS_EQUAL
Returns whether two vectors are equal up to some epsilon.
Definition: JSVector2.h:91
@ FI_LENGTH
Returns the length of this vector.
Definition: JSVector2.h:99
@ FI_MULTIPLY
Multiplies two vectors to determine the scalar product or multiplies this vector with a scalar.
Definition: JSVector2.h:116
@ FI_NORMALIZED
Returns the normalized vector of this vector, so that the new vector has unit length.
Definition: JSVector2.h:132
@ FI_NORMALIZE
Normalizes this vector so that the vector has unit length afterwards.
Definition: JSVector2.h:124
@ FI_INVERTED
Returns the inverted vector of this vector.
Definition: JSVector2.h:83
@ FI_DISTANCE
Returns the distance between this vector and another vector.
Definition: JSVector2.h:107
@ FI_STRING
Returns a string with the values of this vector.
Definition: JSVector2.h:140
@ FI_ADD
Adds two vectors or adds a scalar value to this vector.
Definition: JSVector2.h:59
static void createFunctionTemplate()
Creates the function template and object template for this object.
AccessorId
Definition of ids for individual accessors.
Definition: JSVector2.h:40
@ AI_X
The accessor for the x property, a number value.
Definition: JSVector2.h:42
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15