fd03f700a83e99c7614cd3adcbec5bab02eaf43b
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector3.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// RelativeVector3 is a three-dimensional vector.
25     /// All values (x, y, z and w) should be between [0, 1].
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     [TypeConverter(typeof(RelativeVector3TypeConverter))]
29     public class RelativeVector3 : global::System.IDisposable
30     {
31         /// <summary>
32         /// swigCMemOwn
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         protected bool swigCMemOwn;
36
37         /// <summary>
38         /// A Flat to check if it is already disposed.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         protected bool disposed = false;
42
43         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
44
45         //A Flag to check who called Dispose(). (By User or DisposeQueue)
46         private bool isDisposeQueued = false;
47
48         /// <summary>
49         /// The constructor.
50         /// </summary>
51         /// <since_tizen> 3 </since_tizen>
52         public RelativeVector3() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
53         {
54             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55         }
56
57         /// <summary>
58         /// The constructor.
59         /// </summary>
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)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// The constructor.
71         /// </summary>
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)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// The constructor.
81         /// </summary>
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)
85         {
86             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87         }
88
89         /// <summary>
90         /// Dispose.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         ~RelativeVector3()
94         {
95             if (!isDisposeQueued)
96             {
97                 isDisposeQueued = true;
98                 DisposeQueue.Instance.Add(this);
99             }
100         }
101
102         /// <summary>
103         /// The x component.
104         /// </summary>
105         /// <since_tizen> 3 </since_tizen>
106         public float X
107         {
108             set
109             {
110                 Interop.Vector3.Vector3_X_set(swigCPtr, ValueCheck(value));
111                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             }
113             get
114             {
115                 float ret = Interop.Vector3.Vector3_X_get(swigCPtr);
116                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117                 return ret;
118             }
119         }
120
121         /// <summary>
122         /// The y component.
123         /// </summary>
124         /// <since_tizen> 3 </since_tizen>
125         public float Y
126         {
127             set
128             {
129                 Interop.Vector3.Vector3_Y_set(swigCPtr, ValueCheck(value));
130                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131             }
132             get
133             {
134                 float ret = Interop.Vector3.Vector3_Y_get(swigCPtr);
135                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136                 return ret;
137             }
138         }
139
140         /// <summary>
141         /// The z component.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         public float Z
145         {
146             set
147             {
148                 Interop.Vector3.Vector3_Z_set(swigCPtr, ValueCheck(value));
149                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             }
151             get
152             {
153                 float ret = Interop.Vector3.Vector3_Z_get(swigCPtr);
154                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155                 return ret;
156             }
157         }
158
159         /// <summary>
160         /// The addition operator.
161         /// </summary>
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)
167         {
168             RelativeVector3 result = arg1.Add(arg2);
169             return ValueCheck(result);
170         }
171
172         /// <summary>
173         /// The subtraction operator.
174         /// </summary>
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)
180         {
181             RelativeVector3 result = arg1.Subtract(arg2);
182             return ValueCheck(result);
183         }
184
185         /// <summary>
186         /// The multiplication operator.
187         /// </summary>
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)
193         {
194             RelativeVector3 result = arg1.Multiply(arg2);
195             return ValueCheck(result);
196         }
197
198         /// <summary>
199         /// The multiplication operator.
200         /// </summary>
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)
206         {
207             RelativeVector3 result = arg1.Multiply(arg2);
208             return ValueCheck(result);
209         }
210
211         /// <summary>
212         /// The division operator.
213         /// </summary>
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)
219         {
220             RelativeVector3 result = arg1.Divide(arg2);
221             return ValueCheck(result);
222         }
223
224         /// <summary>
225         /// The division operator.
226         /// </summary>
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)
232         {
233             RelativeVector3 result = arg1.Divide(arg2);
234             return ValueCheck(result);
235         }
236
237         /// <summary>
238         /// </summary>
239         /// <since_tizen> 3 </since_tizen>
240         public static implicit operator Vector3(RelativeVector3 relativeVector3)
241         {
242             return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
243         }
244
245         /// <summary>
246         /// </summary>
247         /// <since_tizen> 3 </since_tizen>
248         public static implicit operator RelativeVector3(Vector3 vec)
249         {
250             return new RelativeVector3(ValueCheck(vec.X), ValueCheck(vec.Y), ValueCheck(vec.Z));
251         }
252
253         /// <summary>
254         /// Dispose.
255         /// </summary>
256         /// <since_tizen> 3 </since_tizen>
257         public void Dispose()
258         {
259             //Throw excpetion if Dispose() is called in separate thread.
260             if (!Window.IsInstalled())
261             {
262                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
263             }
264
265             if (isDisposeQueued)
266             {
267                 Dispose(DisposeTypes.Implicit);
268             }
269             else
270             {
271                 Dispose(DisposeTypes.Explicit);
272                 System.GC.SuppressFinalize(this);
273             }
274         }
275
276         /// <summary>
277         /// The const array subscript operator overload. Should be 0, 1 or 2.
278         /// </summary>
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]
283         {
284             get
285             {
286                 return ValueOfIndex(index);
287             }
288         }
289
290         /// <summary>
291         /// Determines whether the specified object is equal to the current object.
292         /// </summary>
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)
296         {
297             RelativeVector3 relativeVector3 = obj as RelativeVector3;
298             bool equal = false;
299             if (X == relativeVector3?.X && Y == relativeVector3?.Y && Z == relativeVector3?.Z)
300             {
301                 equal = true;
302             }
303             return equal;
304         }
305
306         /// <summary>
307         /// Gets the the hash code of this RelativeVector3.
308         /// </summary>
309         /// <returns>The Hash Code.</returns>
310         /// <since_tizen> 6 </since_tizen>
311         public override int GetHashCode()
312         {
313             return swigCPtr.Handle.GetHashCode();
314         }
315
316         /// <summary>
317         /// Compares if the rhs is equal to.
318         /// </summary>
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)
323         {
324             bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
325             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326             return ret;
327         }
328
329         /// <summary>
330         /// Compares if the rhs is not equal to.
331         /// </summary>
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)
336         {
337             bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
338             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339             return ret;
340         }
341
342         internal static RelativeVector3 ValueCheck(RelativeVector3 relativeVector3)
343         {
344             if (relativeVector3.X < 0.0f)
345             {
346                 relativeVector3.X = 0.0f;
347                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
348             }
349             else if (relativeVector3.X > 1.0f)
350             {
351                 relativeVector3.X = 1.0f;
352                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
353             }
354             if (relativeVector3.Y < 0.0f)
355             {
356                 relativeVector3.Y = 0.0f;
357                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
358             }
359             else if (relativeVector3.Y > 1.0f)
360             {
361                 relativeVector3.Y = 1.0f;
362                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
363             }
364             if (relativeVector3.Z < 0.0f)
365             {
366                 relativeVector3.Z = 0.0f;
367                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
368             }
369             else if (relativeVector3.Z > 1.0f)
370             {
371                 relativeVector3.Z = 1.0f;
372                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
373             }
374             return relativeVector3;
375         }
376
377         internal static float ValueCheck(float value)
378         {
379             if (value < 0.0f)
380             {
381                 value = 0.0f;
382                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
383             }
384             else if (value > 1.0f)
385             {
386                 value = 1.0f;
387                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
388             }
389             return value;
390         }
391
392         /// <summary>
393         /// </summary>
394         internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
395         {
396             RelativeVector3 ret = new RelativeVector3(cPtr, false);
397             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398             return ret;
399         }
400
401         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector3 obj)
402         {
403             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
404         }
405
406         internal RelativeVector3(global::System.IntPtr cPtr, bool cMemoryOwn)
407         {
408             swigCMemOwn = cMemoryOwn;
409             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
410         }
411
412         /// <summary>
413         /// Dispose.
414         /// </summary>
415         /// <since_tizen> 3 </since_tizen>
416         protected virtual void Dispose(DisposeTypes type)
417         {
418             if (disposed)
419             {
420                 return;
421             }
422
423             if(type == DisposeTypes.Explicit)
424             {
425                 //Called by User
426                 //Release your own managed resources here.
427                 //You should release all of your own disposable objects here.
428             }
429
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.
433
434             if (swigCPtr.Handle != global::System.IntPtr.Zero)
435             {
436                 if (swigCMemOwn)
437                 {
438                     swigCMemOwn = false;
439                     Interop.Vector3.delete_Vector3(swigCPtr);
440                 }
441                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
442             }
443             disposed = true;
444         }
445
446         private RelativeVector3 Add(RelativeVector3 rhs)
447         {
448             RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
449             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450             return ret;
451         }
452
453         private RelativeVector3 Subtract(RelativeVector3 rhs)
454         {
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();
457             return ret;
458         }
459
460         private RelativeVector3 Multiply(RelativeVector3 rhs)
461         {
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();
464             return ret;
465         }
466
467         private RelativeVector3 Multiply(float rhs)
468         {
469             RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
470             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471             return ret;
472         }
473
474         private RelativeVector3 Divide(RelativeVector3 rhs)
475         {
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();
478             return ret;
479         }
480
481         private RelativeVector3 Divide(float rhs)
482         {
483             RelativeVector3 ret = new RelativeVector3(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485             return ret;
486         }
487
488         private float ValueOfIndex(uint index)
489         {
490             float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
491             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492             return ret;
493         }
494     }
495
496 }
497
498