Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector4.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  using System;
18
19 namespace Tizen.NUI
20 {
21
22     /// <summary>
23     /// RelativeVector4 is a four-dimensional vector.
24     /// All values (x, y, and z) should be between [0, 1].
25     /// </summary>
26     public class RelativeVector4 : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         protected bool swigCMemOwn;
30
31         internal RelativeVector4(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(RelativeVector4 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         ~RelativeVector4()
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_Vector4(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">The vector to add.</param>
111         /// <returns>The vector containing the result of the addition.</returns>
112         /// <since_tizen> 3 </since_tizen>
113         public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2)
114         {
115             RelativeVector4 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 RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
128         {
129             RelativeVector4 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 RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
142         {
143             RelativeVector4 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 RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
156         {
157             RelativeVector4 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 RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
170         {
171             RelativeVector4 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 RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
184         {
185             RelativeVector4 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 3 or 3.
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 RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
208         {
209             RelativeVector4 ret = new RelativeVector4(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 RelativeVector4() : this(NDalicPINVOKE.new_Vector4__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         /// <param name="w">The w component.</param>
231         /// <since_tizen> 3 </since_tizen>
232         public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(x, y, z, w), true)
233         {
234             ValueCheck(x);
235             ValueCheck(y);
236             ValueCheck(z);
237             ValueCheck(W);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         /// <summary>
242         /// The constructor.
243         /// </summary>
244         /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
245         /// <since_tizen> 3 </since_tizen>
246         public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
247         {
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249         }
250
251         /// <summary>
252         /// The constructor.
253         /// </summary>
254         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
255         /// <since_tizen> 3 </since_tizen>
256         public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
257         {
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259         }
260
261         private RelativeVector4 Add(RelativeVector4 rhs)
262         {
263             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265             return ret;
266         }
267
268         private RelativeVector4 Subtract(RelativeVector4 rhs)
269         {
270             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275         private RelativeVector4 Multiply(RelativeVector4 rhs)
276         {
277             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
278             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279             return ret;
280         }
281
282         private RelativeVector4 Multiply(float rhs)
283         {
284             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286             return ret;
287         }
288
289         private RelativeVector4 Divide(RelativeVector4 rhs)
290         {
291             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             return ret;
294         }
295
296         private RelativeVector4 Divide(float rhs)
297         {
298             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300             return ret;
301         }
302
303         private float ValueOfIndex(uint index)
304         {
305             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307             return ret;
308         }
309
310         /// <summary>
311         /// Compares if the rhs is equal to.
312         /// </summary>
313         /// <param name="rhs">The vector to compare.</param>
314         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
315         /// <since_tizen> 3 </since_tizen>
316         public bool EqualTo(RelativeVector4 rhs)
317         {
318             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
319             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320             return ret;
321         }
322
323         /// <summary>
324         /// Compares if the rhs is not equal to.
325         /// </summary>
326         /// <param name="rhs">The vector to compare.</param>
327         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
328         /// <since_tizen> 3 </since_tizen>
329         public bool NotEqualTo(RelativeVector4 rhs)
330         {
331             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
332             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             return ret;
334         }
335
336
337         /// <summary>
338         /// The x component.
339         /// </summary>
340         /// <since_tizen> 3 </since_tizen>
341         public float X
342         {
343             set
344             {
345                 ValueCheck(value);
346                 NDalicPINVOKE.Vector4_X_set(swigCPtr, value);
347                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348             }
349             get
350             {
351                 float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
352                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353                 return ret;
354             }
355         }
356
357         /// <summary>
358         /// The y component.
359         /// </summary>
360         /// <since_tizen> 3 </since_tizen>
361         public float Y
362         {
363             set
364             {
365                 ValueCheck(value);
366                 NDalicPINVOKE.Vector4_Y_set(swigCPtr, value);
367                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368             }
369             get
370             {
371                 float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
372                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373                 return ret;
374             }
375         }
376
377         /// <summary>
378         /// The z component.
379         /// </summary>
380         /// <since_tizen> 3 </since_tizen>
381         public float Z
382         {
383             set
384             {
385                 ValueCheck(value);
386                 NDalicPINVOKE.Vector4_Z_set(swigCPtr, value);
387                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388             }
389             get
390             {
391                 float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
392                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393                 return ret;
394             }
395         }
396
397         /// <summary>
398         /// The w component.
399         /// </summary>
400         /// <since_tizen> 3 </since_tizen>
401         public float W
402         {
403             set
404             {
405                 ValueCheck(value);
406                 NDalicPINVOKE.Vector4_W_set(swigCPtr, value);
407                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408             }
409             get
410             {
411                 float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
412                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413                 return ret;
414             }
415         }
416
417         /// <summary>
418         /// </summary>
419         /// <since_tizen> 3 </since_tizen>
420         public static implicit operator Vector4(RelativeVector4 relativeVector4)
421         {
422             return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
423         }
424
425         /// <summary>
426         /// </summary>
427         /// <since_tizen> 3 </since_tizen>
428         public static implicit operator RelativeVector4(Vector4 vec)
429         {
430             ValueCheck(vec.X);
431             ValueCheck(vec.Y);
432             ValueCheck(vec.Z);
433             ValueCheck(vec.W);
434             return new RelativeVector4(vec.X, vec.Y, vec.Z, vec.W);
435         }
436
437         internal static void ValueCheck(RelativeVector4 relativeVector4)
438         {
439             if(relativeVector4.X < 0.0f)
440             {
441                 relativeVector4.X = 0.0f;
442                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
443             }
444             else if(relativeVector4.X > 1.0f)
445             {
446                 relativeVector4.X = 1.0f;
447                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
448             }
449             if(relativeVector4.Y < 0.0f)
450             {
451                 relativeVector4.Y = 0.0f;
452                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
453             }
454             else if(relativeVector4.Y > 1.0f)
455             {
456                 relativeVector4.Y = 1.0f;
457                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
458             }
459             if(relativeVector4.Z < 0.0f)
460             {
461                 relativeVector4.Z = 0.0f;
462                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
463             }
464             else if(relativeVector4.Z > 1.0f)
465             {
466                 relativeVector4.Z = 1.0f;
467                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
468             }
469             if(relativeVector4.W < 0.0f)
470             {
471                 relativeVector4.W = 0.0f;
472                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
473             }
474             else if(relativeVector4.W > 1.0f)
475             {
476                 relativeVector4.W = 1.0f;
477                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
478             }
479         }
480
481         internal static void ValueCheck(float value)
482         {
483             if(value < 0.0f)
484             {
485                 value = 0.0f;
486                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
487             }
488             else if(value > 1.0f)
489             {
490                 value = 1.0f;
491                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
492             }
493         }
494
495     }
496
497 }
498