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.
19 using Tizen.NUI.Binding;
24 /// RelativeVector3 is a three-dimensional vector.
25 /// All values (x, y, z and w) should be between [0, 1].
27 /// <since_tizen> 3 </since_tizen>
28 [TypeConverter(typeof(RelativeVector3TypeConverter))]
29 public class RelativeVector3 : global::System.IDisposable
34 /// <since_tizen> 3 </since_tizen>
35 protected bool swigCMemOwn;
38 /// A Flat to check if it is already disposed.
40 /// <since_tizen> 3 </since_tizen>
41 protected bool disposed = false;
43 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
51 /// <since_tizen> 3 </since_tizen>
52 public RelativeVector3() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
54 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 /// <param name="x">The x component.</param>
61 /// <param name="y">The y component.</param>
62 /// <param name="z">The z component.</param>
63 /// <since_tizen> 3 </since_tizen>
64 public RelativeVector3(float x, float y, float z) : this(Interop.Vector3.new_Vector3__SWIG_1(ValueCheck(x), ValueCheck(y), ValueCheck(z)), true)
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72 /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
73 /// <since_tizen> 3 </since_tizen>
74 public RelativeVector3(RelativeVector2 relativeVector2) : this(Interop.Vector3.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
83 /// <since_tizen> 3 </since_tizen>
84 public RelativeVector3(RelativeVector4 relativeVector4) : this(Interop.Vector3.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
86 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 /// <since_tizen> 3 </since_tizen>
97 isDisposeQueued = true;
98 DisposeQueue.Instance.Add(this);
105 /// <since_tizen> 3 </since_tizen>
110 Interop.Vector3.Vector3_X_set(swigCPtr, ValueCheck(value));
111 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115 float ret = Interop.Vector3.Vector3_X_get(swigCPtr);
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// <since_tizen> 3 </since_tizen>
129 Interop.Vector3.Vector3_Y_set(swigCPtr, ValueCheck(value));
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 float ret = Interop.Vector3.Vector3_Y_get(swigCPtr);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 /// <since_tizen> 3 </since_tizen>
148 Interop.Vector3.Vector3_Z_set(swigCPtr, ValueCheck(value));
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 float ret = Interop.Vector3.Vector3_Z_get(swigCPtr);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 /// The addition operator.
162 /// <param name="arg1">The vector to add.</param>
163 /// <param name="arg2">Th vector to add.</param>
164 /// <returns>The vector containing the result of the addition.</returns>
165 /// <since_tizen> 3 </since_tizen>
166 public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2)
168 RelativeVector3 result = arg1.Add(arg2);
169 return ValueCheck(result);
173 /// The subtraction operator.
175 /// <param name="arg1">The vector to subtract.</param>
176 /// <param name="arg2">The vector to subtract.</param>
177 /// <returns>The vector containing the result of the subtraction.</returns>
178 /// <since_tizen> 3 </since_tizen>
179 public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2)
181 RelativeVector3 result = arg1.Subtract(arg2);
182 return ValueCheck(result);
186 /// The multiplication operator.
188 /// <param name="arg1">The vector to multiply.</param>
189 /// <param name="arg2">The vector to multiply.</param>
190 /// <returns>The vector containing the result of the multiplication.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2)
194 RelativeVector3 result = arg1.Multiply(arg2);
195 return ValueCheck(result);
199 /// The multiplication operator.
201 /// <param name="arg1">The vector to multiply.</param>
202 /// <param name="arg2">The float value to scale the vector.</param>
203 /// <returns>The vector containing the result of the scaling.</returns>
204 /// <since_tizen> 3 </since_tizen>
205 public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2)
207 RelativeVector3 result = arg1.Multiply(arg2);
208 return ValueCheck(result);
212 /// The division operator.
214 /// <param name="arg1">The vector to divide.</param>
215 /// <param name="arg2">The vector to divide.</param>
216 /// <returns>The vector containing the result of the division.</returns>
217 /// <since_tizen> 3 </since_tizen>
218 public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2)
220 RelativeVector3 result = arg1.Divide(arg2);
221 return ValueCheck(result);
225 /// The division operator.
227 /// <param name="arg1">The vector to divide.</param>
228 /// <param name="arg2">The float value to scale the vector by.</param>
229 /// <returns>The vector containing the result of the scaling.</returns>
230 /// <since_tizen> 3 </since_tizen>
231 public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2)
233 RelativeVector3 result = arg1.Divide(arg2);
234 return ValueCheck(result);
239 /// <since_tizen> 3 </since_tizen>
240 public static implicit operator Vector3(RelativeVector3 relativeVector3)
242 return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
247 /// <since_tizen> 3 </since_tizen>
248 public static implicit operator RelativeVector3(Vector3 vec)
250 return new RelativeVector3(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z));
256 /// <since_tizen> 3 </since_tizen>
257 public void Dispose()
259 //Throw excpetion if Dispose() is called in separate thread.
260 if (!Window.IsInstalled())
262 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
267 Dispose(DisposeTypes.Implicit);
271 Dispose(DisposeTypes.Explicit);
272 System.GC.SuppressFinalize(this);
277 /// The const array subscript operator overload. Should be 0, 1 or 2.
279 /// <param name="index">The subscript index.</param>
280 /// <returns>The float at the given index.</returns>
281 /// <since_tizen> 3 </since_tizen>
282 public float this[uint index]
286 return ValueOfIndex(index);
291 /// Determines whether the specified object is equal to the current object.
293 /// <param name="obj">The object to compare with the current object.</param>
294 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
295 public override bool Equals(System.Object obj)
297 RelativeVector3 relativeVector3 = obj as RelativeVector3;
299 if (X == relativeVector3?.X && Y == relativeVector3?.Y && Z == relativeVector3?.Z)
307 /// Gets the the hash code of this RelativeVector3.
309 /// <returns>The Hash Code.</returns>
310 /// <since_tizen> 6 </since_tizen>
311 public override int GetHashCode()
313 return swigCPtr.Handle.GetHashCode();
317 /// Compares if the rhs is equal to.
319 /// <param name="rhs">The vector to compare.</param>
320 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
321 /// <since_tizen> 3 </since_tizen>
322 public bool EqualTo(RelativeVector3 rhs)
324 bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
325 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 /// Compares if the rhs is not equal to.
332 /// <param name="rhs">The vector to compare.</param>
333 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
334 /// <since_tizen> 3 </since_tizen>
335 public bool NotEqualTo(RelativeVector3 rhs)
337 bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
338 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 internal static RelativeVector3 ValueCheck(RelativeVector3 relativeVector3)
344 if (relativeVector3.X < 0.0f)
346 relativeVector3.X = 0.0f;
347 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
349 else if (relativeVector3.X > 1.0f)
351 relativeVector3.X = 1.0f;
352 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
354 if (relativeVector3.Y < 0.0f)
356 relativeVector3.Y = 0.0f;
357 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
359 else if (relativeVector3.Y > 1.0f)
361 relativeVector3.Y = 1.0f;
362 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
364 if (relativeVector3.Z < 0.0f)
366 relativeVector3.Z = 0.0f;
367 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
369 else if (relativeVector3.Z > 1.0f)
371 relativeVector3.Z = 1.0f;
372 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
374 return relativeVector3;
377 internal static float ValueCheck(float value)
382 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
384 else if (value > 1.0f)
387 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
394 internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
396 RelativeVector3 ret = new RelativeVector3(cPtr, false);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector3 obj)
403 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
406 internal RelativeVector3(global::System.IntPtr cPtr, bool cMemoryOwn)
408 swigCMemOwn = cMemoryOwn;
409 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
415 /// <since_tizen> 3 </since_tizen>
416 protected virtual void Dispose(DisposeTypes type)
423 if(type == DisposeTypes.Explicit)
426 //Release your own managed resources here.
427 //You should release all of your own disposable objects here.
430 //Release your own unmanaged resources here.
431 //You should not access any managed member here except static instance.
432 //because the execution order of Finalizes is non-deterministic.
434 if (swigCPtr.Handle != global::System.IntPtr.Zero)
439 Interop.Vector3.delete_Vector3(swigCPtr);
441 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
446 private RelativeVector3 Add(RelativeVector3 rhs)
448 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 private RelativeVector3 Subtract(RelativeVector3 rhs)
455 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 private RelativeVector3 Multiply(RelativeVector3 rhs)
462 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
467 private RelativeVector3 Multiply(float rhs)
469 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 private RelativeVector3 Divide(RelativeVector3 rhs)
476 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 private RelativeVector3 Divide(float rhs)
483 RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
488 private float ValueOfIndex(uint index)
490 float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
491 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();