2 * Copyright(c) 2019 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.
17 using System.ComponentModel;
18 using Tizen.NUI.Binding;
24 /// A two-dimensional vector.
26 /// <since_tizen> 3 </since_tizen>
27 [Binding.TypeConverter(typeof(Vector2TypeConverter))]
28 public class Vector2 : Disposable
32 /// The default constructor initializes the vector to 0.
34 /// <since_tizen> 3 </since_tizen>
35 public Vector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 /// <param name="x">The x or width component.</param>
44 /// <param name="y">The y or height component.</param>
45 /// <since_tizen> 3 </since_tizen>
46 public Vector2(float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52 /// The conversion constructor from an array of two floats.
54 /// <param name="array">The array of xy.</param>
55 /// <since_tizen> 3 </since_tizen>
56 public Vector2(float[] array) : this(Interop.Vector2.new_Vector2__SWIG_2(array), true)
58 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64 /// <param name="vec3">Vector3 to create this vector from.</param>
65 /// <since_tizen> 3 </since_tizen>
66 public Vector2(Vector3 vec3) : this(Interop.Vector2.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 /// <param name="vec4">Vector4 to create this vector from.</param>
75 /// <since_tizen> 3 </since_tizen>
76 public Vector2(Vector4 vec4) : this(Interop.Vector2.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
78 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
85 internal Vector2(Vector2ChangedCallback cb, float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
91 internal Vector2(Vector2ChangedCallback cb, Vector2 other) : this(cb, other.X, other.Y)
95 internal delegate void Vector2ChangedCallback(float x, float y);
96 private Vector2ChangedCallback callback = null;
101 /// <since_tizen> 3 </since_tizen>
102 public static Vector2 One
106 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ONE_get();
107 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// The vector representing the x-axis.
116 /// <since_tizen> 3 </since_tizen>
117 public static Vector2 XAxis
121 global::System.IntPtr cPtr = Interop.Vector2.Vector2_XAXIS_get();
122 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129 /// The vector representing the y-axis.
131 /// <since_tizen> 3 </since_tizen>
132 public static Vector2 YAxis
136 global::System.IntPtr cPtr = Interop.Vector2.Vector2_YAXIS_get();
137 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 /// The vector representing the negative x-axis.
146 /// <since_tizen> 3 </since_tizen>
147 public static Vector2 NegativeXAxis
151 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_XAXIS_get();
152 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 /// The vector representing the negative y-axis.
161 /// <since_tizen> 3 </since_tizen>
162 public static Vector2 NegativeYAxis
166 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_YAXIS_get();
167 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176 /// <since_tizen> 3 </since_tizen>
177 public static Vector2 Zero
181 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ZERO_get();
182 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// <since_tizen> 3 </since_tizen>
196 Interop.Vector2.Vector2_X_set(swigCPtr, value);
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 callback?.Invoke(X, Y);
203 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 /// <since_tizen> 3 </since_tizen>
217 Interop.Vector2.Vector2_Width_set(swigCPtr, value);
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 callback?.Invoke(X, Y);
224 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// <since_tizen> 3 </since_tizen>
238 Interop.Vector2.Vector2_Y_set(swigCPtr, value);
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 callback?.Invoke(X, Y);
245 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// <since_tizen> 3 </since_tizen>
259 Interop.Vector2.Vector2_Height_set(swigCPtr, value);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 callback?.Invoke(X, Y);
266 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 /// The array subscript operator overload.
275 /// <param name="index">The subscript index.</param>
276 /// <returns>The float at the given index.</returns>
277 /// <since_tizen> 3 </since_tizen>
278 public float this[uint index]
282 return ValueOfIndex(index);
287 /// The addition operator.
289 /// <param name="arg1">The first value.</param>
290 /// <param name="arg2">The second value.</param>
291 /// <returns>The vector containing the result of the addition.</returns>
292 /// <since_tizen> 3 </since_tizen>
293 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
295 return arg1.Add(arg2);
299 /// The subtraction operator.
301 /// <param name="arg1">The first value.</param>
302 /// <param name="arg2">The second value.</param>
303 /// <returns>The vector containing the result of the subtraction.</returns>
304 /// <since_tizen> 3 </since_tizen>
305 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
307 return arg1.Subtract(arg2);
311 /// The unary negation operator.
313 /// <param name="arg1">The target value.</param>
314 /// <returns>The vector containing the negation.</returns>
315 /// <since_tizen> 3 </since_tizen>
316 public static Vector2 operator -(Vector2 arg1)
318 return arg1.Subtract();
322 /// The multiplication operator.
324 /// <param name="arg1">The first value.</param>
325 /// <param name="arg2">The second value.</param>
326 /// <returns>The vector containing the result of the multiplication.</returns>
327 /// <since_tizen> 3 </since_tizen>
328 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
330 return arg1.Multiply(arg2);
334 /// Th multiplication operator.
336 /// <param name="arg1">The first value.</param>
337 /// <param name="arg2">The float value to scale the vector.</param>
338 /// <returns>The vector containing the result of the scaling.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public static Vector2 operator *(Vector2 arg1, float arg2)
342 return arg1.Multiply(arg2);
346 /// The division operator.
348 /// <param name="arg1">The first value.</param>
349 /// <param name="arg2">The second value.</param>
350 /// <returns>The vector containing the result of the division.</returns>
351 /// <since_tizen> 3 </since_tizen>
352 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
354 return arg1.Divide(arg2);
358 /// Th division operator.
360 /// <param name="arg1">The first value.</param>
361 /// <param name="arg2">The float value to scale the vector by.</param>
362 /// <returns>The vector containing the result of the scaling.</returns>
363 /// <since_tizen> 3 </since_tizen>
364 public static Vector2 operator /(Vector2 arg1, float arg2)
366 return arg1.Divide(arg2);
370 /// Determines whether the specified object is equal to the current object.
372 /// <param name="obj">The object to compare with the current object.</param>
373 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
374 public override bool Equals(System.Object obj)
376 Vector2 vector2 = obj as Vector2;
378 if (X == vector2?.X && Y == vector2?.Y)
386 /// Gets the the hash code of this Vector2.
388 /// <returns>The Hash Code.</returns>
389 /// <since_tizen> 6 </since_tizen>
390 public override int GetHashCode()
392 return swigCPtr.Handle.GetHashCode();
396 /// Returns the length of the vector.
398 /// <returns>The length of the vector.</returns>
399 /// <since_tizen> 3 </since_tizen>
400 public float Length()
402 float ret = Interop.Vector2.Vector2_Length(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// Returns the length of the vector squared.<br />
409 /// This is more efficient than Length() for threshold
410 /// testing as it avoids the use of a square root.<br />
412 /// <returns>The length of the vector squared</returns>
413 /// <since_tizen> 3 </since_tizen>
414 public float LengthSquared()
416 float ret = Interop.Vector2.Vector2_LengthSquared(swigCPtr);
417 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422 /// Sets the vector to be the unit length, whilst maintaining its direction.
424 /// <since_tizen> 3 </since_tizen>
425 public void Normalize()
427 Interop.Vector2.Vector2_Normalize(swigCPtr);
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 /// Clamps the vector between minimum and maximum vectors.
434 /// <param name="min">The minimum vector.</param>
435 /// <param name="max">The maximum vector.</param>
436 /// <since_tizen> 3 </since_tizen>
437 public void Clamp(Vector2 min, Vector2 max)
439 Interop.Vector2.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
440 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
445 Vector2 ret = new Vector2(cPtr, false);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
452 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
455 internal SWIGTYPE_p_float AsFloat()
457 global::System.IntPtr cPtr = Interop.Vector2.Vector2_AsFloat__SWIG_0(swigCPtr);
458 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 /// This will not be public opened.
464 [EditorBrowsable(EditorBrowsableState.Never)]
465 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
467 Interop.Vector2.delete_Vector2(swigCPtr);
470 private Vector2 Add(Vector2 rhs)
472 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 private Vector2 AddAssign(Vector2 rhs)
479 Vector2 ret = new Vector2(Interop.Vector2.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
480 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
484 private Vector2 Subtract(Vector2 rhs)
486 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
491 private Vector2 SubtractAssign(Vector2 rhs)
493 Vector2 ret = new Vector2(Interop.Vector2.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
494 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498 private Vector2 Multiply(Vector2 rhs)
500 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
501 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
505 private Vector2 Multiply(float rhs)
507 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
508 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
512 private Vector2 MultiplyAssign(Vector2 rhs)
514 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
515 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
519 private Vector2 MultiplyAssign(float rhs)
521 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
522 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
526 private Vector2 Divide(Vector2 rhs)
528 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
529 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
533 private Vector2 Divide(float rhs)
535 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
536 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
540 private Vector2 DivideAssign(Vector2 rhs)
542 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
543 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547 private Vector2 DivideAssign(float rhs)
549 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
550 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
554 private Vector2 Subtract()
556 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
557 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
561 private bool EqualTo(Vector2 rhs)
563 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
564 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
568 private bool NotEqualTo(Vector2 rhs)
570 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
571 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
575 private float ValueOfIndex(uint index)
577 float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
578 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();