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();
90 internal delegate void Vector2ChangedCallback(float x, float y);
91 private Vector2ChangedCallback callback = null;
96 /// <since_tizen> 3 </since_tizen>
97 public static Vector2 One
101 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ONE_get();
102 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109 /// The vector representing the x-axis.
111 /// <since_tizen> 3 </since_tizen>
112 public static Vector2 XAxis
116 global::System.IntPtr cPtr = Interop.Vector2.Vector2_XAXIS_get();
117 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// The vector representing the y-axis.
126 /// <since_tizen> 3 </since_tizen>
127 public static Vector2 YAxis
131 global::System.IntPtr cPtr = Interop.Vector2.Vector2_YAXIS_get();
132 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 /// The vector representing the negative x-axis.
141 /// <since_tizen> 3 </since_tizen>
142 public static Vector2 NegativeXAxis
146 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_XAXIS_get();
147 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// The vector representing the negative y-axis.
156 /// <since_tizen> 3 </since_tizen>
157 public static Vector2 NegativeYAxis
161 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_YAXIS_get();
162 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// <since_tizen> 3 </since_tizen>
172 public static Vector2 Zero
176 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ZERO_get();
177 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 /// <since_tizen> 3 </since_tizen>
191 Interop.Vector2.Vector2_X_set(swigCPtr, value);
192 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 callback?.Invoke(X, Y);
198 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// <since_tizen> 3 </since_tizen>
212 Interop.Vector2.Vector2_Width_set(swigCPtr, value);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 callback?.Invoke(X, Y);
219 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// <since_tizen> 3 </since_tizen>
233 Interop.Vector2.Vector2_Y_set(swigCPtr, value);
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 callback?.Invoke(X, Y);
240 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// <since_tizen> 3 </since_tizen>
254 Interop.Vector2.Vector2_Height_set(swigCPtr, value);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 callback?.Invoke(X, Y);
261 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 /// The array subscript operator overload.
270 /// <param name="index">The subscript index.</param>
271 /// <returns>The float at the given index.</returns>
272 /// <since_tizen> 3 </since_tizen>
273 public float this[uint index]
277 return ValueOfIndex(index);
282 /// The addition operator.
284 /// <param name="arg1">The first value.</param>
285 /// <param name="arg2">The second value.</param>
286 /// <returns>The vector containing the result of the addition.</returns>
287 /// <since_tizen> 3 </since_tizen>
288 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
290 return arg1.Add(arg2);
294 /// The subtraction operator.
296 /// <param name="arg1">The first value.</param>
297 /// <param name="arg2">The second value.</param>
298 /// <returns>The vector containing the result of the subtraction.</returns>
299 /// <since_tizen> 3 </since_tizen>
300 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
302 return arg1.Subtract(arg2);
306 /// The unary negation operator.
308 /// <param name="arg1">The target value.</param>
309 /// <returns>The vector containing the negation.</returns>
310 /// <since_tizen> 3 </since_tizen>
311 public static Vector2 operator -(Vector2 arg1)
313 return arg1.Subtract();
317 /// The multiplication operator.
319 /// <param name="arg1">The first value.</param>
320 /// <param name="arg2">The second value.</param>
321 /// <returns>The vector containing the result of the multiplication.</returns>
322 /// <since_tizen> 3 </since_tizen>
323 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
325 return arg1.Multiply(arg2);
329 /// Th multiplication operator.
331 /// <param name="arg1">The first value.</param>
332 /// <param name="arg2">The float value to scale the vector.</param>
333 /// <returns>The vector containing the result of the scaling.</returns>
334 /// <since_tizen> 3 </since_tizen>
335 public static Vector2 operator *(Vector2 arg1, float arg2)
337 return arg1.Multiply(arg2);
341 /// The division operator.
343 /// <param name="arg1">The first value.</param>
344 /// <param name="arg2">The second value.</param>
345 /// <returns>The vector containing the result of the division.</returns>
346 /// <since_tizen> 3 </since_tizen>
347 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
349 return arg1.Divide(arg2);
353 /// Th division operator.
355 /// <param name="arg1">The first value.</param>
356 /// <param name="arg2">The float value to scale the vector by.</param>
357 /// <returns>The vector containing the result of the scaling.</returns>
358 /// <since_tizen> 3 </since_tizen>
359 public static Vector2 operator /(Vector2 arg1, float arg2)
361 return arg1.Divide(arg2);
365 /// Determines whether the specified object is equal to the current object.
367 /// <param name="obj">The object to compare with the current object.</param>
368 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
369 public override bool Equals(System.Object obj)
371 Vector2 vector2 = obj as Vector2;
373 if (X == vector2?.X && Y == vector2?.Y)
381 /// Gets the the hash code of this Vector2.
383 /// <returns>The Hash Code.</returns>
384 /// <since_tizen> 6 </since_tizen>
385 public override int GetHashCode()
387 return swigCPtr.Handle.GetHashCode();
391 /// Returns the length of the vector.
393 /// <returns>The length of the vector.</returns>
394 /// <since_tizen> 3 </since_tizen>
395 public float Length()
397 float ret = Interop.Vector2.Vector2_Length(swigCPtr);
398 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403 /// Returns the length of the vector squared.<br />
404 /// This is more efficient than Length() for threshold
405 /// testing as it avoids the use of a square root.<br />
407 /// <returns>The length of the vector squared</returns>
408 /// <since_tizen> 3 </since_tizen>
409 public float LengthSquared()
411 float ret = Interop.Vector2.Vector2_LengthSquared(swigCPtr);
412 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 /// Sets the vector to be the unit length, whilst maintaining its direction.
419 /// <since_tizen> 3 </since_tizen>
420 public void Normalize()
422 Interop.Vector2.Vector2_Normalize(swigCPtr);
423 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
427 /// Clamps the vector between minimum and maximum vectors.
429 /// <param name="min">The minimum vector.</param>
430 /// <param name="max">The maximum vector.</param>
431 /// <since_tizen> 3 </since_tizen>
432 public void Clamp(Vector2 min, Vector2 max)
434 Interop.Vector2.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
440 Vector2 ret = new Vector2(cPtr, false);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
447 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
450 internal SWIGTYPE_p_float AsFloat()
452 global::System.IntPtr cPtr = Interop.Vector2.Vector2_AsFloat__SWIG_0(swigCPtr);
453 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
454 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 /// This will not be public opened.
459 [EditorBrowsable(EditorBrowsableState.Never)]
460 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
462 Interop.Vector2.delete_Vector2(swigCPtr);
465 private Vector2 Add(Vector2 rhs)
467 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
468 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 private Vector2 AddAssign(Vector2 rhs)
474 Vector2 ret = new Vector2(Interop.Vector2.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
475 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
479 private Vector2 Subtract(Vector2 rhs)
481 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
482 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486 private Vector2 SubtractAssign(Vector2 rhs)
488 Vector2 ret = new Vector2(Interop.Vector2.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493 private Vector2 Multiply(Vector2 rhs)
495 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
496 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500 private Vector2 Multiply(float rhs)
502 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
503 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 private Vector2 MultiplyAssign(Vector2 rhs)
509 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514 private Vector2 MultiplyAssign(float rhs)
516 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521 private Vector2 Divide(Vector2 rhs)
523 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
524 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528 private Vector2 Divide(float rhs)
530 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
531 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
535 private Vector2 DivideAssign(Vector2 rhs)
537 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
538 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542 private Vector2 DivideAssign(float rhs)
544 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
549 private Vector2 Subtract()
551 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
552 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
556 private bool EqualTo(Vector2 rhs)
558 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
563 private bool NotEqualTo(Vector2 rhs)
565 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
566 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
570 private float ValueOfIndex(uint index)
572 float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
573 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();