2 * Copyright(c) 2018 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.
18 using Tizen.NUI.Binding;
24 /// A two-dimensional vector.
26 /// <since_tizen> 3 </since_tizen>
27 [TypeConverter(typeof(Vector2TypeConverter))]
28 public class Vector2 : global::System.IDisposable
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
37 /// A Flat to check if it is already disposed.
39 /// <since_tizen> 3 </since_tizen>
40 protected bool disposed = false;
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
42 //A Flag to check who called Dispose(). (By User or DisposeQueue)
43 private bool isDisposeQueued = false;
46 /// The default constructor initializes the vector to 0.
48 /// <since_tizen> 3 </since_tizen>
49 public Vector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
51 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
57 /// <param name="x">The x or width component.</param>
58 /// <param name="y">The y or height component.</param>
59 /// <since_tizen> 3 </since_tizen>
60 public Vector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// The conversion constructor from an array of two floats.
68 /// <param name="array">The array of xy.</param>
69 /// <since_tizen> 3 </since_tizen>
70 public Vector2(float[] array) : this(NDalicPINVOKE.new_Vector2__SWIG_2(array), true)
72 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78 /// <param name="vec3">Vector3 to create this vector from.</param>
79 /// <since_tizen> 3 </since_tizen>
80 public Vector2(Vector3 vec3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
82 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 /// <param name="vec4">Vector4 to create this vector from.</param>
89 /// <since_tizen> 3 </since_tizen>
90 public Vector2(Vector4 vec4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
97 swigCMemOwn = cMemoryOwn;
98 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
104 /// <since_tizen> 3 </since_tizen>
109 isDisposeQueued = true;
110 DisposeQueue.Instance.Add(this);
117 /// <since_tizen> 3 </since_tizen>
118 public static Vector2 One
122 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ONE_get();
123 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
124 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 /// The vector representing the x-axis.
132 /// <since_tizen> 3 </since_tizen>
133 public static Vector2 XAxis
137 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_XAXIS_get();
138 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 /// The vector representing the y-axis.
147 /// <since_tizen> 3 </since_tizen>
148 public static Vector2 YAxis
152 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_YAXIS_get();
153 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 /// The vector representing the negative x-axis.
162 /// <since_tizen> 3 </since_tizen>
163 public static Vector2 NegativeXAxis
167 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_XAXIS_get();
168 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175 /// The vector representing the negative y-axis.
177 /// <since_tizen> 3 </since_tizen>
178 public static Vector2 NegativeYAxis
182 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_YAXIS_get();
183 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192 /// <since_tizen> 3 </since_tizen>
193 public static Vector2 Zero
197 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ZERO_get();
198 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// <since_tizen> 3 </since_tizen>
212 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 /// <since_tizen> 3 </since_tizen>
231 NDalicPINVOKE.Vector2_Width_set(swigCPtr, value);
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 /// <since_tizen> 3 </since_tizen>
250 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 /// <since_tizen> 3 </since_tizen>
269 NDalicPINVOKE.Vector2_Height_set(swigCPtr, value);
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 /// The array subscript operator overload.
283 /// <param name="index">The subscript index.</param>
284 /// <returns>The float at the given index.</returns>
285 /// <since_tizen> 3 </since_tizen>
286 public float this[uint index]
290 return ValueOfIndex(index);
295 /// The addition operator.
297 /// <param name="arg1">The first value.</param>
298 /// <param name="arg2">The second value.</param>
299 /// <returns>The vector containing the result of the addition.</returns>
300 /// <since_tizen> 3 </since_tizen>
301 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
303 return arg1.Add(arg2);
307 /// The subtraction operator.
309 /// <param name="arg1">The first value.</param>
310 /// <param name="arg2">The second value.</param>
311 /// <returns>The vector containing the result of the subtraction.</returns>
312 /// <since_tizen> 3 </since_tizen>
313 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
315 return arg1.Subtract(arg2);
319 /// The unary negation operator.
321 /// <param name="arg1">The target value.</param>
322 /// <returns>The vector containing the negation.</returns>
323 /// <since_tizen> 3 </since_tizen>
324 public static Vector2 operator -(Vector2 arg1)
326 return arg1.Subtract();
330 /// The multiplication operator.
332 /// <param name="arg1">The first value.</param>
333 /// <param name="arg2">The second value.</param>
334 /// <returns>The vector containing the result of the multiplication.</returns>
335 /// <since_tizen> 3 </since_tizen>
336 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
338 return arg1.Multiply(arg2);
342 /// Th multiplication operator.
344 /// <param name="arg1">The first value.</param>
345 /// <param name="arg2">The float value to scale the vector.</param>
346 /// <returns>The vector containing the result of the scaling.</returns>
347 /// <since_tizen> 3 </since_tizen>
348 public static Vector2 operator *(Vector2 arg1, float arg2)
350 return arg1.Multiply(arg2);
354 /// The division operator.
356 /// <param name="arg1">The first value.</param>
357 /// <param name="arg2">The second value.</param>
358 /// <returns>The vector containing the result of the division.</returns>
359 /// <since_tizen> 3 </since_tizen>
360 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
362 return arg1.Divide(arg2);
366 /// Th division operator.
368 /// <param name="arg1">The first value.</param>
369 /// <param name="arg2">The float value to scale the vector by.</param>
370 /// <returns>The vector containing the result of the scaling.</returns>
371 /// <since_tizen> 3 </since_tizen>
372 public static Vector2 operator /(Vector2 arg1, float arg2)
374 return arg1.Divide(arg2);
378 /// Determines whether the specified object is equal to the current object.
380 /// <param name="obj">The object to compare with the current object.</param>
381 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
382 public override bool Equals(System.Object obj)
384 Vector2 vector2 = obj as Vector2;
386 if (X == vector2?.X && Y == vector2?.Y)
394 /// Gets the the hash code of this Vector2.
396 /// <returns>The Hash Code.</returns>
397 /// <since_tizen> 5 </since_tizen>
398 public override int GetHashCode()
400 return swigCPtr.Handle.GetHashCode();
404 /// Returns the length of the vector.
406 /// <returns>The length of the vector.</returns>
407 /// <since_tizen> 3 </since_tizen>
408 public float Length()
410 float ret = NDalicPINVOKE.Vector2_Length(swigCPtr);
411 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 /// Returns the length of the vector squared.<br />
417 /// This is more efficient than Length() for threshold
418 /// testing as it avoids the use of a square root.<br />
420 /// <returns>The length of the vector squared</returns>
421 /// <since_tizen> 3 </since_tizen>
422 public float LengthSquared()
424 float ret = NDalicPINVOKE.Vector2_LengthSquared(swigCPtr);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 /// Sets the vector to be the unit length, whilst maintaining its direction.
432 /// <since_tizen> 3 </since_tizen>
433 public void Normalize()
435 NDalicPINVOKE.Vector2_Normalize(swigCPtr);
436 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 /// Clamps the vector between minimum and maximum vectors.
442 /// <param name="min">The minimum vector.</param>
443 /// <param name="max">The maximum vector.</param>
444 /// <since_tizen> 3 </since_tizen>
445 public void Clamp(Vector2 min, Vector2 max)
447 NDalicPINVOKE.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 /// <since_tizen> 3 </since_tizen>
455 public void Dispose()
457 //Throw excpetion if Dispose() is called in separate thread.
458 if (!Window.IsInstalled())
460 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
465 Dispose(DisposeTypes.Implicit);
469 Dispose(DisposeTypes.Explicit);
470 System.GC.SuppressFinalize(this);
474 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
476 Vector2 ret = new Vector2(cPtr, false);
477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
483 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
486 internal SWIGTYPE_p_float AsFloat()
488 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_AsFloat__SWIG_0(swigCPtr);
489 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497 /// <param name="type">The dispose type</param>
498 /// <since_tizen> 3 </since_tizen>
499 protected virtual void Dispose(DisposeTypes type)
506 if (type == DisposeTypes.Explicit)
509 //Release your own managed resources here.
510 //You should release all of your own disposable objects here.
513 //Release your own unmanaged resources here.
514 //You should not access any managed member here except static instance.
515 //because the execution order of Finalizes is non-deterministic.
517 if (swigCPtr.Handle != global::System.IntPtr.Zero)
522 NDalicPINVOKE.delete_Vector2(swigCPtr);
524 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
529 private Vector2 Add(Vector2 rhs)
531 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
532 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536 private Vector2 AddAssign(Vector2 rhs)
538 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
539 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543 private Vector2 Subtract(Vector2 rhs)
545 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
546 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 private Vector2 SubtractAssign(Vector2 rhs)
552 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
553 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557 private Vector2 Multiply(Vector2 rhs)
559 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
560 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
564 private Vector2 Multiply(float rhs)
566 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
567 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
571 private Vector2 MultiplyAssign(Vector2 rhs)
573 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
574 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578 private Vector2 MultiplyAssign(float rhs)
580 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
581 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
585 private Vector2 Divide(Vector2 rhs)
587 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
588 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
592 private Vector2 Divide(float rhs)
594 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
595 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
599 private Vector2 DivideAssign(Vector2 rhs)
601 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
602 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606 private Vector2 DivideAssign(float rhs)
608 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
609 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 private Vector2 Subtract()
615 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
616 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620 private bool EqualTo(Vector2 rhs)
622 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
623 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
627 private bool NotEqualTo(Vector2 rhs)
629 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
630 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
634 private float ValueOfIndex(uint index)
636 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
637 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();