2 * Copyright (c) 2017 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;
25 /// RelativeVector3 is a three-dimensional vector.
26 /// All values (x, y, z and w) should be between [0, 1].
28 /// <since_tizen> 3 </since_tizen>
29 [TypeConverter(typeof(RelativeVector3TypeConverter))]
30 public class RelativeVector3 : global::System.IDisposable
32 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36 /// <since_tizen> 3 </since_tizen>
37 protected bool swigCMemOwn;
39 internal RelativeVector3(global::System.IntPtr cPtr, bool cMemoryOwn)
41 swigCMemOwn = cMemoryOwn;
42 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
45 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector3 obj)
47 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
50 //A Flag to check who called Dispose(). (By User or DisposeQueue)
51 private bool isDisposeQueued = false;
53 /// A Flat to check if it is already disposed.
55 /// <since_tizen> 3 </since_tizen>
56 protected bool disposed = false;
61 /// <since_tizen> 3 </since_tizen>
66 isDisposeQueued = true;
67 DisposeQueue.Instance.Add(this);
74 /// <since_tizen> 3 </since_tizen>
77 //Throw excpetion if Dispose() is called in separate thread.
78 if (!Window.IsInstalled())
80 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
85 Dispose(DisposeTypes.Implicit);
89 Dispose(DisposeTypes.Explicit);
90 System.GC.SuppressFinalize(this);
97 /// <since_tizen> 3 </since_tizen>
98 protected virtual void Dispose(DisposeTypes type)
105 if(type == DisposeTypes.Explicit)
108 //Release your own managed resources here.
109 //You should release all of your own disposable objects here.
112 //Release your own unmanaged resources here.
113 //You should not access any managed member here except static instance.
114 //because the execution order of Finalizes is non-deterministic.
116 if (swigCPtr.Handle != global::System.IntPtr.Zero)
121 NDalicPINVOKE.delete_Vector3(swigCPtr);
123 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
130 /// The addition operator.
132 /// <param name="arg1">The vector to add.</param>
133 /// <param name="arg2">Th vector to add.</param>
134 /// <returns>The vector containing the result of the addition.</returns>
135 /// <since_tizen> 3 </since_tizen>
136 public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2)
138 RelativeVector3 result = arg1.Add(arg2);
139 return ValueCheck(result);
143 /// The subtraction operator.
145 /// <param name="arg1">The vector to subtract.</param>
146 /// <param name="arg2">The vector to subtract.</param>
147 /// <returns>The vector containing the result of the subtraction.</returns>
148 /// <since_tizen> 3 </since_tizen>
149 public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2)
151 RelativeVector3 result = arg1.Subtract(arg2);
152 return ValueCheck(result);
156 /// The multiplication operator.
158 /// <param name="arg1">The vector to multiply.</param>
159 /// <param name="arg2">The vector to multiply.</param>
160 /// <returns>The vector containing the result of the multiplication.</returns>
161 /// <since_tizen> 3 </since_tizen>
162 public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2)
164 RelativeVector3 result = arg1.Multiply(arg2);
165 return ValueCheck(result);
169 /// The multiplication operator.
171 /// <param name="arg1">The vector to multiply.</param>
172 /// <param name="arg2">The float value to scale the vector.</param>
173 /// <returns>The vector containing the result of the scaling.</returns>
174 /// <since_tizen> 3 </since_tizen>
175 public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2)
177 RelativeVector3 result = arg1.Multiply(arg2);
178 return ValueCheck(result);
182 /// The division operator.
184 /// <param name="arg1">The vector to divide.</param>
185 /// <param name="arg2">The vector to divide.</param>
186 /// <returns>The vector containing the result of the division.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2)
190 RelativeVector3 result = arg1.Divide(arg2);
191 return ValueCheck(result);
195 /// The division operator.
197 /// <param name="arg1">The vector to divide.</param>
198 /// <param name="arg2">The float value to scale the vector by.</param>
199 /// <returns>The vector containing the result of the scaling.</returns>
200 /// <since_tizen> 3 </since_tizen>
201 public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2)
203 RelativeVector3 result = arg1.Divide(arg2);
204 return ValueCheck(result);
209 /// The const array subscript operator overload. Should be 0, 1 or 2.
211 /// <param name="index">The subscript index.</param>
212 /// <returns>The float at the given index.</returns>
213 /// <since_tizen> 3 </since_tizen>
214 public float this[uint index]
218 return ValueOfIndex(index);
224 internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
226 RelativeVector3 ret = new RelativeVector3(cPtr, false);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// <since_tizen> 3 </since_tizen>
236 public RelativeVector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 /// <param name="x">The x component.</param>
245 /// <param name="y">The y component.</param>
246 /// <param name="z">The z component.</param>
247 /// <since_tizen> 3 </since_tizen>
248 public RelativeVector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(ValueCheck(x), ValueCheck(y), ValueCheck(z)), true)
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
257 /// <since_tizen> 3 </since_tizen>
258 public RelativeVector3(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
267 /// <since_tizen> 3 </since_tizen>
268 public RelativeVector3(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 private RelativeVector3 Add(RelativeVector3 rhs)
276 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 private RelativeVector3 Subtract(RelativeVector3 rhs)
283 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 private RelativeVector3 Multiply(RelativeVector3 rhs)
290 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 private RelativeVector3 Multiply(float rhs)
297 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 private RelativeVector3 Divide(RelativeVector3 rhs)
304 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 private RelativeVector3 Divide(float rhs)
311 RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 private float ValueOfIndex(uint index)
318 float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 /// Determines whether the specified object is equal to the current object.
326 /// <param name="obj">The object to compare with the current object.</param>
327 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
328 public override bool Equals(System.Object obj)
330 RelativeVector3 relativeVector3 = obj as RelativeVector3;
332 if (X == relativeVector3?.X && Y == relativeVector3?.Y && Z == relativeVector3?.Z)
340 /// Compares if the rhs is equal to.
342 /// <param name="rhs">The vector to compare.</param>
343 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
344 /// <since_tizen> 3 </since_tizen>
345 public bool EqualTo(RelativeVector3 rhs)
347 bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 /// Compares if the rhs is not equal to.
355 /// <param name="rhs">The vector to compare.</param>
356 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
357 /// <since_tizen> 3 </since_tizen>
358 public bool NotEqualTo(RelativeVector3 rhs)
360 bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 /// <since_tizen> 3 </since_tizen>
374 NDalicPINVOKE.Vector3_X_set(swigCPtr, ValueCheck(value));
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379 float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr);
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// <since_tizen> 3 </since_tizen>
393 NDalicPINVOKE.Vector3_Y_set(swigCPtr, ValueCheck(value));
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 /// <since_tizen> 3 </since_tizen>
412 NDalicPINVOKE.Vector3_Z_set(swigCPtr, ValueCheck(value));
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 /// <since_tizen> 3 </since_tizen>
426 public static implicit operator Vector3(RelativeVector3 relativeVector3)
428 return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
433 /// <since_tizen> 3 </since_tizen>
434 public static implicit operator RelativeVector3(Vector3 vec)
436 return new RelativeVector3(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z));
439 internal static RelativeVector3 ValueCheck(RelativeVector3 relativeVector3)
441 if(relativeVector3.X < 0.0f)
443 relativeVector3.X = 0.0f;
444 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
446 else if(relativeVector3.X > 1.0f)
448 relativeVector3.X = 1.0f;
449 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
451 if(relativeVector3.Y < 0.0f)
453 relativeVector3.Y = 0.0f;
454 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
456 else if(relativeVector3.Y > 1.0f)
458 relativeVector3.Y = 1.0f;
459 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
461 if(relativeVector3.Z < 0.0f)
463 relativeVector3.Z = 0.0f;
464 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
466 else if(relativeVector3.Z > 1.0f)
468 relativeVector3.Z = 1.0f;
469 NUILog.Error( "The value of Result is invalid! Should be between [0, 1].");
471 return relativeVector3;
474 internal static float ValueCheck(float value)
479 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");
481 else if(value > 1.0f)
484 NUILog.Error( "The value of Parameters is invalid! Should be between [0, 1].");