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 : Disposable
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
36 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
39 /// The default constructor initializes the vector to 0.
41 /// <since_tizen> 3 </since_tizen>
42 public Vector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50 /// <param name="x">The x or width component.</param>
51 /// <param name="y">The y or height component.</param>
52 /// <since_tizen> 3 </since_tizen>
53 public Vector2(float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
55 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 /// The conversion constructor from an array of two floats.
61 /// <param name="array">The array of xy.</param>
62 /// <since_tizen> 3 </since_tizen>
63 public Vector2(float[] array) : this(Interop.Vector2.new_Vector2__SWIG_2(array), true)
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 /// <param name="vec3">Vector3 to create this vector from.</param>
72 /// <since_tizen> 3 </since_tizen>
73 public Vector2(Vector3 vec3) : this(Interop.Vector2.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
75 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81 /// <param name="vec4">Vector4 to create this vector from.</param>
82 /// <since_tizen> 3 </since_tizen>
83 public Vector2(Vector4 vec4) : this(Interop.Vector2.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
85 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
90 swigCMemOwn = cMemoryOwn;
91 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
97 /// <since_tizen> 3 </since_tizen>
98 public static Vector2 One
102 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ONE_get();
103 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
104 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 /// The vector representing the x-axis.
112 /// <since_tizen> 3 </since_tizen>
113 public static Vector2 XAxis
117 global::System.IntPtr cPtr = Interop.Vector2.Vector2_XAXIS_get();
118 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// The vector representing the y-axis.
127 /// <since_tizen> 3 </since_tizen>
128 public static Vector2 YAxis
132 global::System.IntPtr cPtr = Interop.Vector2.Vector2_YAXIS_get();
133 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// The vector representing the negative x-axis.
142 /// <since_tizen> 3 </since_tizen>
143 public static Vector2 NegativeXAxis
147 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_XAXIS_get();
148 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155 /// The vector representing the negative y-axis.
157 /// <since_tizen> 3 </since_tizen>
158 public static Vector2 NegativeYAxis
162 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_YAXIS_get();
163 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172 /// <since_tizen> 3 </since_tizen>
173 public static Vector2 Zero
177 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ZERO_get();
178 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 /// <since_tizen> 3 </since_tizen>
192 Interop.Vector2.Vector2_X_set(swigCPtr, value);
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 /// <since_tizen> 3 </since_tizen>
211 Interop.Vector2.Vector2_Width_set(swigCPtr, value);
212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 /// <since_tizen> 3 </since_tizen>
230 Interop.Vector2.Vector2_Y_set(swigCPtr, value);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 /// <since_tizen> 3 </since_tizen>
249 Interop.Vector2.Vector2_Height_set(swigCPtr, value);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// The array subscript operator overload.
263 /// <param name="index">The subscript index.</param>
264 /// <returns>The float at the given index.</returns>
265 /// <since_tizen> 3 </since_tizen>
266 public float this[uint index]
270 return ValueOfIndex(index);
275 /// The addition operator.
277 /// <param name="arg1">The first value.</param>
278 /// <param name="arg2">The second value.</param>
279 /// <returns>The vector containing the result of the addition.</returns>
280 /// <since_tizen> 3 </since_tizen>
281 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
283 return arg1.Add(arg2);
287 /// The subtraction 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 subtraction.</returns>
292 /// <since_tizen> 3 </since_tizen>
293 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
295 return arg1.Subtract(arg2);
299 /// The unary negation operator.
301 /// <param name="arg1">The target value.</param>
302 /// <returns>The vector containing the negation.</returns>
303 /// <since_tizen> 3 </since_tizen>
304 public static Vector2 operator -(Vector2 arg1)
306 return arg1.Subtract();
310 /// The multiplication operator.
312 /// <param name="arg1">The first value.</param>
313 /// <param name="arg2">The second value.</param>
314 /// <returns>The vector containing the result of the multiplication.</returns>
315 /// <since_tizen> 3 </since_tizen>
316 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
318 return arg1.Multiply(arg2);
322 /// Th multiplication operator.
324 /// <param name="arg1">The first value.</param>
325 /// <param name="arg2">The float value to scale the vector.</param>
326 /// <returns>The vector containing the result of the scaling.</returns>
327 /// <since_tizen> 3 </since_tizen>
328 public static Vector2 operator *(Vector2 arg1, float arg2)
330 return arg1.Multiply(arg2);
334 /// The division operator.
336 /// <param name="arg1">The first value.</param>
337 /// <param name="arg2">The second value.</param>
338 /// <returns>The vector containing the result of the division.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
342 return arg1.Divide(arg2);
346 /// Th division operator.
348 /// <param name="arg1">The first value.</param>
349 /// <param name="arg2">The float value to scale the vector by.</param>
350 /// <returns>The vector containing the result of the scaling.</returns>
351 /// <since_tizen> 3 </since_tizen>
352 public static Vector2 operator /(Vector2 arg1, float arg2)
354 return arg1.Divide(arg2);
358 /// Determines whether the specified object is equal to the current object.
360 /// <param name="obj">The object to compare with the current object.</param>
361 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
362 public override bool Equals(System.Object obj)
364 Vector2 vector2 = obj as Vector2;
366 if (X == vector2?.X && Y == vector2?.Y)
374 /// Gets the the hash code of this Vector2.
376 /// <returns>The Hash Code.</returns>
377 /// <since_tizen> 6 </since_tizen>
378 public override int GetHashCode()
380 return swigCPtr.Handle.GetHashCode();
384 /// Returns the length of the vector.
386 /// <returns>The length of the vector.</returns>
387 /// <since_tizen> 3 </since_tizen>
388 public float Length()
390 float ret = Interop.Vector2.Vector2_Length(swigCPtr);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 /// Returns the length of the vector squared.<br />
397 /// This is more efficient than Length() for threshold
398 /// testing as it avoids the use of a square root.<br />
400 /// <returns>The length of the vector squared</returns>
401 /// <since_tizen> 3 </since_tizen>
402 public float LengthSquared()
404 float ret = Interop.Vector2.Vector2_LengthSquared(swigCPtr);
405 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410 /// Sets the vector to be the unit length, whilst maintaining its direction.
412 /// <since_tizen> 3 </since_tizen>
413 public void Normalize()
415 Interop.Vector2.Vector2_Normalize(swigCPtr);
416 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 /// Clamps the vector between minimum and maximum vectors.
422 /// <param name="min">The minimum vector.</param>
423 /// <param name="max">The maximum vector.</param>
424 /// <since_tizen> 3 </since_tizen>
425 public void Clamp(Vector2 min, Vector2 max)
427 Interop.Vector2.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
433 Vector2 ret = new Vector2(cPtr, false);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
440 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
443 internal SWIGTYPE_p_float AsFloat()
445 global::System.IntPtr cPtr = Interop.Vector2.Vector2_AsFloat__SWIG_0(swigCPtr);
446 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
447 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 /// <param name="type">The dispose type</param>
455 /// <since_tizen> 3 </since_tizen>
456 protected override void Dispose(DisposeTypes type)
463 //Release your own unmanaged resources here.
464 //You should not access any managed member here except static instance.
465 //because the execution order of Finalizes is non-deterministic.
467 if (swigCPtr.Handle != global::System.IntPtr.Zero)
472 Interop.Vector2.delete_Vector2(swigCPtr);
474 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
479 private Vector2 Add(Vector2 rhs)
481 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
482 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486 private Vector2 AddAssign(Vector2 rhs)
488 Vector2 ret = new Vector2(Interop.Vector2.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493 private Vector2 Subtract(Vector2 rhs)
495 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
496 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500 private Vector2 SubtractAssign(Vector2 rhs)
502 Vector2 ret = new Vector2(Interop.Vector2.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
503 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 private Vector2 Multiply(Vector2 rhs)
509 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514 private Vector2 Multiply(float rhs)
516 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521 private Vector2 MultiplyAssign(Vector2 rhs)
523 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
524 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528 private Vector2 MultiplyAssign(float rhs)
530 Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
531 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
535 private Vector2 Divide(Vector2 rhs)
537 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
538 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542 private Vector2 Divide(float rhs)
544 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
549 private Vector2 DivideAssign(Vector2 rhs)
551 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
552 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
556 private Vector2 DivideAssign(float rhs)
558 Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
563 private Vector2 Subtract()
565 Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
566 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
570 private bool EqualTo(Vector2 rhs)
572 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
573 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
577 private bool NotEqualTo(Vector2 rhs)
579 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
580 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
584 private float ValueOfIndex(uint index)
586 float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
587 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();