2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /// A two-dimensional vector.
24 public class Vector2 : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 protected bool swigCMemOwn;
32 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
34 swigCMemOwn = cMemoryOwn;
35 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
40 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
43 //A Flag to check who called Dispose(). (By User or DisposeQueue)
44 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 protected bool disposed = false;
54 /// <since_tizen> 3 </since_tizen>
59 isDisposeQueued = true;
60 DisposeQueue.Instance.Add(this);
67 /// <since_tizen> 3 </since_tizen>
70 //Throw excpetion if Dispose() is called in separate thread.
71 if (!Window.IsInstalled())
73 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
78 Dispose(DisposeTypes.Implicit);
82 Dispose(DisposeTypes.Explicit);
83 System.GC.SuppressFinalize(this);
90 /// <param name="type">The dispose type</param>
91 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if(type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Vector2(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 /// The addition operator.
125 /// <param name="arg1">The first value.</param>
126 /// <param name="arg2">The second value.</param>
127 /// <returns>The vector containing the result of the addition.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
131 return arg1.Add(arg2);
135 /// The subtraction operator.
137 /// <param name="arg1">The first value.</param>
138 /// <param name="arg2">The second value.</param>
139 /// <returns>The vector containing the result of the subtraction.</returns>
140 /// <since_tizen> 3 </since_tizen>
141 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
143 return arg1.Subtract(arg2);
147 /// The unary negation operator.
149 /// <param name="arg1">The target value.</param>
150 /// <returns>The vector containing the negation.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public static Vector2 operator -(Vector2 arg1)
154 return arg1.Subtract();
158 /// The multiplication operator.
160 /// <param name="arg1">The first value.</param>
161 /// <param name="arg2">The second value.</param>
162 /// <returns>The vector containing the result of the multiplication.</returns>
163 /// <since_tizen> 3 </since_tizen>
164 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
166 return arg1.Multiply(arg2);
170 /// Th multiplication operator.
172 /// <param name="arg1">The first value.</param>
173 /// <param name="arg2">The float value to scale the vector.</param>
174 /// <returns>The vector containing the result of the scaling.</returns>
175 /// <since_tizen> 3 </since_tizen>
176 public static Vector2 operator *(Vector2 arg1, float arg2)
178 return arg1.Multiply(arg2);
182 /// The division operator.
184 /// <param name="arg1">The first value.</param>
185 /// <param name="arg2">The second value.</param>
186 /// <returns>The vector containing the result of the division.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
190 return arg1.Divide(arg2);
194 /// Th division operator.
196 /// <param name="arg1">The first value.</param>
197 /// <param name="arg2">The float value to scale the vector by.</param>
198 /// <returns>The vector containing the result of the scaling.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static Vector2 operator /(Vector2 arg1, float arg2)
202 return arg1.Divide(arg2);
206 /// The array subscript operator overload.
208 /// <param name="index">The subscript index.</param>
209 /// <returns>The float at the given index.</returns>
210 /// <since_tizen> 3 </since_tizen>
211 public float this[uint index]
215 return ValueOfIndex(index);
219 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
221 Vector2 ret = new Vector2(cPtr, false);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227 /// The default constructor initializes the vector to 0.
229 /// <since_tizen> 3 </since_tizen>
230 public Vector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// <param name="x">The x or width component.</param>
239 /// <param name="y">The y or height component.</param>
240 /// <since_tizen> 3 </since_tizen>
241 public Vector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// The conversion constructor from an array of two floats.
249 /// <param name="array">The array of xy.</param>
250 /// <since_tizen> 3 </since_tizen>
251 public Vector2(float[] array) : this(NDalicPINVOKE.new_Vector2__SWIG_2(array), true)
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// <param name="vec3">Vector3 to create this vector from.</param>
260 /// <since_tizen> 3 </since_tizen>
261 public Vector2(Vector3 vec3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 /// <param name="vec4">Vector4 to create this vector from.</param>
270 /// <since_tizen> 3 </since_tizen>
271 public Vector2(Vector4 vec4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 /// <since_tizen> 3 </since_tizen>
280 public static Vector2 One
284 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ONE_get();
285 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// The vector representing the x-axis.
294 /// <since_tizen> 3 </since_tizen>
295 public static Vector2 XAxis
299 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_XAXIS_get();
300 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 /// The vector representing the y-axis.
309 /// <since_tizen> 3 </since_tizen>
310 public static Vector2 YAxis
314 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_YAXIS_get();
315 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 /// The vector representing the negative x-axis.
324 /// <since_tizen> 3 </since_tizen>
325 public static Vector2 NegativeXAxis
329 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_XAXIS_get();
330 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 /// The vector representing the negative y-axis.
339 /// <since_tizen> 3 </since_tizen>
340 public static Vector2 NegativeYAxis
344 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_YAXIS_get();
345 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 /// <since_tizen> 3 </since_tizen>
355 public static Vector2 Zero
359 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ZERO_get();
360 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 private Vector2 Add(Vector2 rhs)
368 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 private Vector2 AddAssign(Vector2 rhs)
375 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 private Vector2 Subtract(Vector2 rhs)
382 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 private Vector2 SubtractAssign(Vector2 rhs)
389 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 private Vector2 Multiply(Vector2 rhs)
396 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 private Vector2 Multiply(float rhs)
403 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 private Vector2 MultiplyAssign(Vector2 rhs)
410 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
411 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415 private Vector2 MultiplyAssign(float rhs)
417 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422 private Vector2 Divide(Vector2 rhs)
424 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 private Vector2 Divide(float rhs)
431 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
432 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 private Vector2 DivideAssign(Vector2 rhs)
438 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 private Vector2 DivideAssign(float rhs)
445 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 private Vector2 Subtract()
452 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457 private bool EqualTo(Vector2 rhs)
459 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464 private bool NotEqualTo(Vector2 rhs)
466 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
467 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471 private float ValueOfIndex(uint index)
473 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
474 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479 /// Returns the length of the vector.
481 /// <returns>The length of the vector.</returns>
482 /// <since_tizen> 3 </since_tizen>
483 public float Length()
485 float ret = NDalicPINVOKE.Vector2_Length(swigCPtr);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
491 /// Returns the length of the vector squared.<br />
492 /// This is more efficient than Length() for threshold
493 /// testing as it avoids the use of a square root.<br />
495 /// <returns>The length of the vector squared</returns>
496 /// <since_tizen> 3 </since_tizen>
497 public float LengthSquared()
499 float ret = NDalicPINVOKE.Vector2_LengthSquared(swigCPtr);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
505 /// Sets the vector to be the unit length, whilst maintaining its direction.
507 /// <since_tizen> 3 </since_tizen>
508 public void Normalize()
510 NDalicPINVOKE.Vector2_Normalize(swigCPtr);
511 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
515 /// Clamps the vector between minimum and maximum vectors.
517 /// <param name="min">The minimum vector.</param>
518 /// <param name="max">The maximum vector.</param>
519 /// <since_tizen> 3 </since_tizen>
520 public void Clamp(Vector2 min, Vector2 max)
522 NDalicPINVOKE.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
523 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
526 internal SWIGTYPE_p_float AsFloat()
528 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_AsFloat__SWIG_0(swigCPtr);
529 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
530 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 /// <since_tizen> 3 </since_tizen>
542 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
543 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
548 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
556 /// <since_tizen> 3 </since_tizen>
561 NDalicPINVOKE.Vector2_Width_set(swigCPtr, value);
562 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
566 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
567 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
575 /// <since_tizen> 3 </since_tizen>
580 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
581 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
585 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
586 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594 /// <since_tizen> 3 </since_tizen>
599 NDalicPINVOKE.Vector2_Height_set(swigCPtr, value);
600 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
604 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
605 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();