1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /// A two dimensional vector.
23 public class Vector2 : global::System.IDisposable
25 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 protected bool swigCMemOwn;
28 internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
30 swigCMemOwn = cMemoryOwn;
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 //A Flag to check who called Dispose(). (By User or DisposeQueue)
40 private bool isDisposeQueued = false;
41 //A Flat to check if it is already disposed.
42 protected bool disposed = false;
48 isDisposeQueued = true;
49 DisposeQueue.Instance.Add(this);
55 //Throw excpetion if Dispose() is called in separate thread.
56 if (!Window.IsInstalled())
58 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
63 Dispose(DisposeTypes.Implicit);
67 Dispose(DisposeTypes.Explicit);
68 System.GC.SuppressFinalize(this);
72 protected virtual void Dispose(DisposeTypes type)
79 if(type == DisposeTypes.Explicit)
82 //Release your own managed resources here.
83 //You should release all of your own disposable objects here.
86 //Release your own unmanaged resources here.
87 //You should not access any managed member here except static instance.
88 //because the execution order of Finalizes is non-deterministic.
90 if (swigCPtr.Handle != global::System.IntPtr.Zero)
95 NDalicPINVOKE.delete_Vector2(swigCPtr);
97 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103 /// Addition operator.
105 /// <param name="arg1">First value</param>
106 /// <param name="arg2">Second value</param>
107 /// <returns>A vector containing the result of the addition</returns>
108 public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
110 return arg1.Add(arg2);
114 /// Subtraction operator.
116 /// <param name="arg1">First value</param>
117 /// <param name="arg2">Second value</param>
118 /// <returns>A vector containing the result of the subtraction</returns>
119 public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
121 return arg1.Subtract(arg2);
125 /// Unary negation operator.
127 /// <param name="arg1">Target Value</param>
128 /// <returns>A vector containg the negation</returns>
129 public static Vector2 operator -(Vector2 arg1)
131 return arg1.Subtract();
135 /// Multiplication operator.
137 /// <param name="arg1">First Value</param>
138 /// <param name="arg2">Second Value</param>
139 /// <returns>A vector containing the result of the multiplication</returns>
140 public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
142 return arg1.Multiply(arg2);
146 /// Multiplication operator.
148 /// <param name="arg1">First Value</param>
149 /// <param name="arg2">The float value to scale the vector</param>
150 /// <returns>A vector containing the result of the scaling</returns>
151 public static Vector2 operator *(Vector2 arg1, float arg2)
153 return arg1.Multiply(arg2);
157 /// Division operator.
159 /// <param name="arg1">First Value</param>
160 /// <param name="arg2">Second Value</param>
161 /// <returns>A vector containing the result of the division</returns>
162 public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
164 return arg1.Divide(arg2);
168 /// Division operator.
170 /// <param name="arg1">First Value</param>
171 /// <param name="arg2">The float value to scale the vector by</param>
172 /// <returns>A vector containing the result of the scaling</returns>
173 public static Vector2 operator /(Vector2 arg1, float arg2)
175 return arg1.Divide(arg2);
179 /// Array subscript operator overload.
181 /// <param name="index">Subscript index</param>
182 /// <returns>The float at the given index</returns>
183 public float this[uint index]
187 return ValueOfIndex(index);
191 internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
193 Vector2 ret = new Vector2(cPtr, false);
194 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199 /// Default constructor, initializes the vector to 0.
201 public Vector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 /// <param name="x">x or width component</param>
210 /// <param name="y">y or height component</param>
211 public Vector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 /// Conversion constructor from an array of two floats.
219 /// <param name="array">Array of xy</param>
220 public Vector2(float[] array) : this(NDalicPINVOKE.new_Vector2__SWIG_2(array), true)
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// <param name="vec3">Vector3 to create this vector from</param>
229 public Vector2(Vector3 vec3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// <param name="vec4">Vector4 to create this vector from</param>
238 public Vector2(Vector4 vec4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 public static Vector2 One
250 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ONE_get();
251 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 /// Vector representing the X axis
260 public static Vector2 XAxis
264 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_XAXIS_get();
265 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 /// Vector representing the Y axis
274 public static Vector2 YAxis
278 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_YAXIS_get();
279 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Vector representing the negative X axis
288 public static Vector2 NegativeXAxis
292 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_XAXIS_get();
293 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 /// Vector representing the negative Y axis
302 public static Vector2 NegativeYAxis
306 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_NEGATIVE_YAXIS_get();
307 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 public static Vector2 Zero
320 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_ZERO_get();
321 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
322 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 private Vector2 Add(Vector2 rhs)
329 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 private Vector2 AddAssign(Vector2 rhs)
336 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 private Vector2 Subtract(Vector2 rhs)
343 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 private Vector2 SubtractAssign(Vector2 rhs)
350 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 private Vector2 Multiply(Vector2 rhs)
357 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 private Vector2 Multiply(float rhs)
364 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 private Vector2 MultiplyAssign(Vector2 rhs)
371 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 private Vector2 MultiplyAssign(float rhs)
378 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 private Vector2 Divide(Vector2 rhs)
385 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 private Vector2 Divide(float rhs)
392 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
393 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 private Vector2 DivideAssign(Vector2 rhs)
399 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 private Vector2 DivideAssign(float rhs)
406 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 private Vector2 Subtract()
413 Vector2 ret = new Vector2(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 private bool EqualTo(Vector2 rhs)
420 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 private bool NotEqualTo(Vector2 rhs)
427 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 private float ValueOfIndex(uint index)
434 float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 /// Returns the length of the vector.
442 /// <returns>The length of the vector</returns>
443 public float Length()
445 float ret = NDalicPINVOKE.Vector2_Length(swigCPtr);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451 /// Returns the length of the vector squared.<br>
452 /// This is more efficient than Length() for threshold
453 /// testing as it avoids the use of a square root.<br>
455 /// <returns>The length of the vector squared</returns>
456 public float LengthSquared()
458 float ret = NDalicPINVOKE.Vector2_LengthSquared(swigCPtr);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464 /// Sets the vector to be unit length, whilst maintaining its direction.
466 public void Normalize()
468 NDalicPINVOKE.Vector2_Normalize(swigCPtr);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 /// Clamps the vector between minimum and maximum vectors.
475 /// <param name="min">The minimum vector</param>
476 /// <param name="max">The maximum vector</param>
477 public void Clamp(Vector2 min, Vector2 max)
479 NDalicPINVOKE.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
480 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 internal SWIGTYPE_p_float AsFloat()
485 global::System.IntPtr cPtr = NDalicPINVOKE.Vector2_AsFloat__SWIG_0(swigCPtr);
486 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516 NDalicPINVOKE.Vector2_Width_set(swigCPtr, value);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
522 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
535 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
540 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
552 NDalicPINVOKE.Vector2_Height_set(swigCPtr, value);
553 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
558 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();