Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector3.cs
1 /*
2  * Copyright (c) 2017 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 namespace Tizen.NUI
20 {
21
22     /// <summary>
23     /// RelativeVector3 is a three-dimensional vector.
24     /// All values (x, y, z and w) should be between [0, 1].
25     /// </summary>
26     public class RelativeVector3 : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         protected bool swigCMemOwn;
30
31         internal RelativeVector3(global::System.IntPtr cPtr, bool cMemoryOwn)
32         {
33             swigCMemOwn = cMemoryOwn;
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector3 obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         //A Flag to check who called Dispose(). (By User or DisposeQueue)
43         private bool isDisposeQueued = false;
44         //A Flat to check if it is already disposed.
45         protected bool disposed = false;
46
47         ~RelativeVector3()
48         {
49             if(!isDisposeQueued)
50             {
51                 isDisposeQueued = true;
52                 DisposeQueue.Instance.Add(this);
53             }
54         }
55
56         public void Dispose()
57         {
58             //Throw excpetion if Dispose() is called in separate thread.
59             if (!Window.IsInstalled())
60             {
61                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
62             }
63
64             if (isDisposeQueued)
65             {
66                 Dispose(DisposeTypes.Implicit);
67             }
68             else
69             {
70                 Dispose(DisposeTypes.Explicit);
71                 System.GC.SuppressFinalize(this);
72             }
73         }
74
75         protected virtual void Dispose(DisposeTypes type)
76         {
77             if (disposed)
78             {
79                 return;
80             }
81
82             if(type == DisposeTypes.Explicit)
83             {
84                 //Called by User
85                 //Release your own managed resources here.
86                 //You should release all of your own disposable objects here.
87             }
88
89             //Release your own unmanaged resources here.
90             //You should not access any managed member here except static instance.
91             //because the execution order of Finalizes is non-deterministic.
92
93             if (swigCPtr.Handle != global::System.IntPtr.Zero)
94             {
95                 if (swigCMemOwn)
96                 {
97                     swigCMemOwn = false;
98                     NDalicPINVOKE.delete_Vector3(swigCPtr);
99                 }
100                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
101             }
102             disposed = true;
103         }
104
105
106         /// <summary>
107         /// The addition operator.
108         /// </summary>
109         /// <param name="arg1">The vector to add.</param>
110         /// <param name="arg2">Th vector to add.</param>
111         /// <returns>The vector containing the result of the addition.</returns>
112         /// <since_tizen> 3 </since_tizen>
113         public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2)
114         {
115             RelativeVector3 result = arg1.Add(arg2);
116             ValueCheck(result);
117             return result;
118         }
119
120         /// <summary>
121         /// The subtraction operator.
122         /// </summary>
123         /// <param name="arg1">The vector to subtract.</param>
124         /// <param name="arg2">The vector to subtract.</param>
125         /// <returns>The vector containing the result of the subtraction.</returns>
126         /// <since_tizen> 3 </since_tizen>
127         public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2)
128         {
129             RelativeVector3 result = arg1.Subtract(arg2);
130             ValueCheck(result);
131             return result;
132         }
133
134         /// <summary>
135         /// The multiplication operator.
136         /// </summary>
137         /// <param name="arg1">The vector to multiply.</param>
138         /// <param name="arg2">The vector to multiply.</param>
139         /// <returns>The vector containing the result of the multiplication.</returns>
140         /// <since_tizen> 3 </since_tizen>
141         public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2)
142         {
143             RelativeVector3 result = arg1.Multiply(arg2);
144             ValueCheck(result);
145             return result;
146         }
147
148         /// <summary>
149         /// The multiplication operator.
150         /// </summary>
151         /// <param name="arg1">The vector to multiply.</param>
152         /// <param name="arg2">The float value to scale the vector.</param>
153         /// <returns>The vector containing the result of the scaling.</returns>
154         /// <since_tizen> 3 </since_tizen>
155         public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2)
156         {
157             RelativeVector3 result = arg1.Multiply(arg2);
158             ValueCheck(result);
159             return result;
160         }
161
162         /// <summary>
163         /// The division operator.
164         /// </summary>
165         /// <param name="arg1">The vector to divide.</param>
166         /// <param name="arg2">The vector to divide.</param>
167         /// <returns>The vector containing the result of the division.</returns>
168         /// <since_tizen> 3 </since_tizen>
169         public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2)
170         {
171             RelativeVector3 result = arg1.Divide(arg2);
172             ValueCheck(result);
173             return result;
174         }
175
176         /// <summary>
177         /// The division operator.
178         /// </summary>
179         /// <param name="arg1">The vector to divide.</param>
180         /// <param name="arg2">The float value to scale the vector by.</param>
181         /// <returns>The vector containing the result of the scaling.</returns>
182         /// <since_tizen> 3 </since_tizen>
183         public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2)
184         {
185             RelativeVector3 result = arg1.Divide(arg2);
186             ValueCheck(result);
187             return result;
188         }
189
190
191         /// <summary>
192         /// The const array subscript operator overload. Should be 0, 1 or 2.
193         /// </summary>
194         /// <param name="index">The subscript index.</param>
195         /// <returns>The float at the given index.</returns>
196         /// <since_tizen> 3 </since_tizen>
197         public float this[uint index]
198         {
199             get
200             {
201                 return ValueOfIndex(index);
202             }
203         }
204
205         /// <summary>
206         /// </summary>
207         internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
208         {
209             RelativeVector3 ret = new RelativeVector3(cPtr, false);
210             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211             return ret;
212         }
213
214
215         /// <summary>
216         /// The constructor.
217         /// </summary>
218         /// <since_tizen> 3 </since_tizen>
219         public RelativeVector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
220         {
221             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222         }
223
224         /// <summary>
225         /// The constructor.
226         /// </summary>
227         /// <param name="x">The x component.</param>
228         /// <param name="y">The y component.</param>
229         /// <param name="z">The z component.</param>
230         /// <since_tizen> 3 </since_tizen>
231         public RelativeVector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
232         {
233             ValueCheck(x);
234             ValueCheck(y);
235             ValueCheck(z);
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237         }
238
239         /// <summary>
240         /// The constructor.
241         /// </summary>
242         /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
243         /// <since_tizen> 3 </since_tizen>
244         public RelativeVector3(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
245         {
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247         }
248
249         /// <summary>
250         /// The constructor.
251         /// </summary>
252         /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
253         /// <since_tizen> 3 </since_tizen>
254         public RelativeVector3(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
255         {
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257         }
258
259
260         private RelativeVector3 Add(RelativeVector3 rhs)
261         {
262             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264             return ret;
265         }
266
267         private RelativeVector3 Subtract(RelativeVector3 rhs)
268         {
269             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         private RelativeVector3 Multiply(RelativeVector3 rhs)
275         {
276             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278             return ret;
279         }
280
281         private RelativeVector3 Multiply(float rhs)
282         {
283             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         private RelativeVector3 Divide(RelativeVector3 rhs)
289         {
290             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         private RelativeVector3 Divide(float rhs)
296         {
297             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299             return ret;
300         }
301
302         private float ValueOfIndex(uint index)
303         {
304             float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306             return ret;
307         }
308
309         /// <summary>
310         /// Compares if the rhs is equal to.
311         /// </summary>
312         /// <param name="rhs">The vector to compare.</param>
313         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
314         /// <since_tizen> 3 </since_tizen>
315         public bool EqualTo(RelativeVector3 rhs)
316         {
317             bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319             return ret;
320         }
321
322         /// <summary>
323         /// Compares if the rhs is not equal to.
324         /// </summary>
325         /// <param name="rhs">The vector to compare.</param>
326         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
327         /// <since_tizen> 3 </since_tizen>
328         public bool NotEqualTo(RelativeVector3 rhs)
329         {
330             bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332             return ret;
333         }
334
335
336         /// <summary>
337         /// The x component.
338         /// </summary>
339         /// <since_tizen> 3 </since_tizen>
340         public float X
341         {
342             set
343             {
344                 ValueCheck(value);
345                 NDalicPINVOKE.Vector3_X_set(swigCPtr, value);
346                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347             }
348             get
349             {
350                 float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr);
351                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352                 return ret;
353             }
354         }
355
356         /// <summary>
357         /// The y component.
358         /// </summary>
359         /// <since_tizen> 3 </since_tizen>
360         public float Y
361         {
362             set
363             {
364                 ValueCheck(value);
365                 NDalicPINVOKE.Vector3_Y_set(swigCPtr, value);
366                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367             }
368             get
369             {
370                 float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr);
371                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372                 return ret;
373             }
374         }
375
376         /// <summary>
377         /// The z component.
378         /// </summary>
379         /// <since_tizen> 3 </since_tizen>
380         public float Z
381         {
382             set
383             {
384                  ValueCheck(value);
385                 NDalicPINVOKE.Vector3_Z_set(swigCPtr, value);
386                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387             }
388             get
389             {
390                 float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr);
391                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392                 return ret;
393             }
394         }
395
396         /// <summary>
397         /// </summary>
398         /// <since_tizen> 3 </since_tizen>
399         public static implicit operator Vector3(RelativeVector3 relativeVector3)
400         {
401             return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
402         }
403
404         /// <summary>
405         /// </summary>
406         /// <since_tizen> 3 </since_tizen>
407         public static implicit operator RelativeVector3(Vector3 vec)
408         {
409             ValueCheck(vec.X);
410             ValueCheck(vec.Y);
411             ValueCheck(vec.Z);
412             return new RelativeVector3(vec.X, vec.Y, vec.Z);
413         }
414
415         internal static void ValueCheck(RelativeVector3 relativeVector3)
416         {
417             if(relativeVector3.X < 0.0f)
418             {
419                 relativeVector3.X = 0.0f;
420                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
421             }
422             else if(relativeVector3.X > 1.0f)
423             {
424                 relativeVector3.X = 1.0f;
425                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
426             }
427             if(relativeVector3.Y < 0.0f)
428             {
429                 relativeVector3.Y = 0.0f;
430                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
431             }
432             else if(relativeVector3.Y > 1.0f)
433             {
434                 relativeVector3.Y = 1.0f;
435                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
436             }
437             if(relativeVector3.Z < 0.0f)
438             {
439                 relativeVector3.Z = 0.0f;
440                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
441             }
442             else if(relativeVector3.Z > 1.0f)
443             {
444                 relativeVector3.Z = 1.0f;
445                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
446             }
447         }
448
449         internal static void ValueCheck(float value)
450         {
451             if(value < 0.0f)
452             {
453                 value = 0.0f;
454                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
455             }
456             else if(value > 1.0f)
457             {
458                 value = 1.0f;
459                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
460             }
461         }
462     }
463
464 }
465