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.
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
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 /// <since_tizen> 3 </since_tizen>
35 protected bool swigCMemOwn;
37 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
39 swigCMemOwn = cMemoryOwn;
40 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
45 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 //A Flag to check who called Dispose(). (By User or DisposeQueue)
49 private bool isDisposeQueued = false;
52 /// A Flat to check if it is already disposed.
54 /// <since_tizen> 3 </since_tizen>
55 protected bool disposed = false;
60 /// <since_tizen> 3 </since_tizen>
65 isDisposeQueued = true;
66 DisposeQueue.Instance.Add(this);
73 /// <since_tizen> 3 </since_tizen>
76 //Throw excpetion if Dispose() is called in separate thread.
77 if (!Window.IsInstalled())
79 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
84 Dispose(DisposeTypes.Implicit);
88 Dispose(DisposeTypes.Explicit);
89 System.GC.SuppressFinalize(this);
96 /// <param name="type">The dispose type</param>
97 /// <since_tizen> 3 </since_tizen>
98 protected virtual void Dispose(DisposeTypes type)
105 if(type == DisposeTypes.Explicit)
108 //Release your own managed resources here.
109 //You should release all of your own disposable objects here.
112 //Release your own unmanaged resources here.
113 //You should not access any managed member here except static instance.
114 //because the execution order of Finalizes is non-deterministic.
116 if (swigCPtr.Handle != global::System.IntPtr.Zero)
121 NDalicPINVOKE.delete_Vector2(swigCPtr);
123 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
129 /// The addition operator.
131 /// <param name="arg1">The first value.</param>
132 /// <param name="arg2">The second value.</param>
133 /// <returns>The vector containing the result of the addition.</returns>
134 /// <since_tizen> 3 </since_tizen>
135 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
137 return arg1.Add(arg2);
141 /// The subtraction operator.
143 /// <param name="arg1">The first value.</param>
144 /// <param name="arg2">The second value.</param>
145 /// <returns>The vector containing the result of the subtraction.</returns>
146 /// <since_tizen> 3 </since_tizen>
147 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
149 return arg1.Subtract(arg2);
153 /// The unary negation operator.
155 /// <param name="arg1">The target value.</param>
156 /// <returns>The vector containing the negation.</returns>
157 /// <since_tizen> 3 </since_tizen>
158 public static Vector2 operator -(Vector2 arg1)
160 return arg1.Subtract();
164 /// The multiplication operator.
166 /// <param name="arg1">The first value.</param>
167 /// <param name="arg2">The second value.</param>
168 /// <returns>The vector containing the result of the multiplication.</returns>
169 /// <since_tizen> 3 </since_tizen>
170 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
172 return arg1.Multiply(arg2);
176 /// Th multiplication operator.
178 /// <param name="arg1">The first value.</param>
179 /// <param name="arg2">The float value to scale the vector.</param>
180 /// <returns>The vector containing the result of the scaling.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public static Vector2 operator *(Vector2 arg1, float arg2)
184 return arg1.Multiply(arg2);
188 /// The division operator.
190 /// <param name="arg1">The first value.</param>
191 /// <param name="arg2">The second value.</param>
192 /// <returns>The vector containing the result of the division.</returns>
193 /// <since_tizen> 3 </since_tizen>
194 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
196 return arg1.Divide(arg2);
200 /// Th division operator.
202 /// <param name="arg1">The first value.</param>
203 /// <param name="arg2">The float value to scale the vector by.</param>
204 /// <returns>The vector containing the result of the scaling.</returns>
205 /// <since_tizen> 3 </since_tizen>
206 public static Vector2 operator /(Vector2 arg1, float arg2)
208 return arg1.Divide(arg2);
212 /// The array subscript operator overload.
214 /// <param name="index">The subscript index.</param>
215 /// <returns>The float at the given index.</returns>
216 /// <since_tizen> 3 </since_tizen>
217 public float this[uint index]
221 return ValueOfIndex(index);
225 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
227 Vector2 ret = new Vector2(cPtr, false);
228 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// The default constructor initializes the vector to 0.
235 /// <since_tizen> 3 </since_tizen>
236 public Vector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 /// <param name="x">The x or width component.</param>
245 /// <param name="y">The y or height component.</param>
246 /// <since_tizen> 3 </since_tizen>
247 public Vector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 /// The conversion constructor from an array of two floats.
255 /// <param name="array">The array of xy.</param>
256 /// <since_tizen> 3 </since_tizen>
257 public Vector2(float[] array) : this(NDalicPINVOKE.new_Vector2__SWIG_2(array), true)
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// <param name="vec3">Vector3 to create this vector from.</param>
266 /// <since_tizen> 3 </since_tizen>
267 public Vector2(Vector3 vec3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 /// <param name="vec4">Vector4 to create this vector from.</param>
276 /// <since_tizen> 3 </since_tizen>
277 public Vector2(Vector4 vec4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// <since_tizen> 3 </since_tizen>
286 public static Vector2 One
290 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ONE_get();
291 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 /// The vector representing the x-axis.
300 /// <since_tizen> 3 </since_tizen>
301 public static Vector2 XAxis
305 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_XAXIS_get();
306 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// The vector representing the y-axis.
315 /// <since_tizen> 3 </since_tizen>
316 public static Vector2 YAxis
320 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_YAXIS_get();
321 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 /// The vector representing the negative x-axis.
330 /// <since_tizen> 3 </since_tizen>
331 public static Vector2 NegativeXAxis
335 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_XAXIS_get();
336 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 /// The vector representing the negative y-axis.
345 /// <since_tizen> 3 </since_tizen>
346 public static Vector2 NegativeYAxis
350 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_YAXIS_get();
351 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// <since_tizen> 3 </since_tizen>
361 public static Vector2 Zero
365 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ZERO_get();
366 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 private Vector2 Add(Vector2 rhs)
374 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 private Vector2 AddAssign(Vector2 rhs)
381 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
382 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 private Vector2 Subtract(Vector2 rhs)
388 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 private Vector2 SubtractAssign(Vector2 rhs)
395 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 private Vector2 Multiply(Vector2 rhs)
402 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 private Vector2 Multiply(float rhs)
409 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 private Vector2 MultiplyAssign(Vector2 rhs)
416 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
417 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 private Vector2 MultiplyAssign(float rhs)
423 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 private Vector2 Divide(Vector2 rhs)
430 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 private Vector2 Divide(float rhs)
437 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 private Vector2 DivideAssign(Vector2 rhs)
444 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
445 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 private Vector2 DivideAssign(float rhs)
451 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 private Vector2 Subtract()
458 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 private bool EqualTo(Vector2 rhs)
465 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
466 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470 private bool NotEqualTo(Vector2 rhs)
472 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 private float ValueOfIndex(uint index)
479 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
480 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485 /// Determines whether the specified object is equal to the current object.
487 /// <param name="obj">The object to compare with the current object.</param>
488 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
489 public override bool Equals(System.Object obj)
491 Vector2 vector2 = obj as Vector2;
493 if (X == vector2?.X && Y == vector2?.Y)
501 /// Returns the length of the vector.
503 /// <returns>The length of the vector.</returns>
504 /// <since_tizen> 3 </since_tizen>
505 public float Length()
507 float ret = NDalicPINVOKE.Vector2_Length(swigCPtr);
508 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513 /// Returns the length of the vector squared.<br />
514 /// This is more efficient than Length() for threshold
515 /// testing as it avoids the use of a square root.<br />
517 /// <returns>The length of the vector squared</returns>
518 /// <since_tizen> 3 </since_tizen>
519 public float LengthSquared()
521 float ret = NDalicPINVOKE.Vector2_LengthSquared(swigCPtr);
522 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
527 /// Sets the vector to be the unit length, whilst maintaining its direction.
529 /// <since_tizen> 3 </since_tizen>
530 public void Normalize()
532 NDalicPINVOKE.Vector2_Normalize(swigCPtr);
533 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 /// Clamps the vector between minimum and maximum vectors.
539 /// <param name="min">The minimum vector.</param>
540 /// <param name="max">The maximum vector.</param>
541 /// <since_tizen> 3 </since_tizen>
542 public void Clamp(Vector2 min, Vector2 max)
544 NDalicPINVOKE.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 internal SWIGTYPE_p_float AsFloat()
550 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_AsFloat__SWIG_0(swigCPtr);
551 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
552 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
559 /// <since_tizen> 3 </since_tizen>
564 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
565 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
569 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
570 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578 /// <since_tizen> 3 </since_tizen>
583 NDalicPINVOKE.Vector2_Width_set(swigCPtr, value);
584 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
589 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597 /// <since_tizen> 3 </since_tizen>
602 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
603 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
607 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
608 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
616 /// <since_tizen> 3 </since_tizen>
621 NDalicPINVOKE.Vector2_Height_set(swigCPtr, value);
622 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
626 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
627 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();