Release 4.0.0-preview1-00235
[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         public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2)
113         {
114             RelativeVector4 result = arg1.Add(arg2);
115             ValueCheck(result);
116             return result;
117         }
118
119         /// <summary>
120         /// The subtraction operator.
121         /// </summary>
122         /// <param name="arg1">The vector to subtract.</param>
123         /// <param name="arg2">The vector to subtract.</param>
124         /// <returns>The vector containing the result of the subtraction.</returns>
125         public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
126         {
127             RelativeVector4 result = arg1.Subtract(arg2);
128             ValueCheck(result);
129             return result;
130         }
131
132         /// <summary>
133         /// The multiplication operator.
134         /// </summary>
135         /// <param name="arg1">The vector to multiply.</param>
136         /// <param name="arg2">The vector to multiply.</param>
137         /// <returns>The vector containing the result of the multiplication.</returns>
138         public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
139         {
140             RelativeVector4 result = arg1.Multiply(arg2);
141             ValueCheck(result);
142             return result;
143         }
144
145         /// <summary>
146         /// The multiplication operator.
147         /// </summary>
148         /// <param name="arg1">The vector to multiply.</param>
149         /// <param name="arg2">The float value to scale the vector.</param>
150         /// <returns>The vector containing the result of the scaling.</returns>
151         public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
152         {
153             RelativeVector4 result = arg1.Multiply(arg2);
154             ValueCheck(result);
155             return result;
156         }
157
158         /// <summary>
159         /// The division operator.
160         /// </summary>
161         /// <param name="arg1">The vector to divide.</param>
162         /// <param name="arg2">The vector to divide.</param>
163         /// <returns>The vector containing the result of the division.</returns>
164         public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
165         {
166             RelativeVector4 result = arg1.Divide(arg2);
167             ValueCheck(result);
168             return result;
169         }
170
171         /// <summary>
172         /// The division operator.
173         /// </summary>
174         /// <param name="arg1">The vector to divide.</param>
175         /// <param name="arg2">The float value to scale the vector by.</param>
176         /// <returns>The vector containing the result of the scaling.</returns>
177         public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
178         {
179             RelativeVector4 result = arg1.Divide(arg2);
180             ValueCheck(result);
181             return result;
182         }
183
184
185         /// <summary>
186         /// The const array subscript operator overload. Should be 0, 1 3 or 3.
187         /// </summary>
188         /// <param name="index">The subscript index.</param>
189         /// <returns>The float at the given index.</returns>
190         public float this[uint index]
191         {
192             get
193             {
194                 return ValueOfIndex(index);
195             }
196         }
197
198         /// <summary>
199         /// </summary>
200         internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
201         {
202             RelativeVector4 ret = new RelativeVector4(cPtr, false);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206
207
208         /// <summary>
209         /// The constructor.
210         /// </summary>
211         public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
212         {
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// The constructor.
218         /// </summary>
219         /// <param name="x">The x component.</param>
220         /// <param name="y">The y component.</param>
221         /// <param name="z">The z component.</param>
222         /// <param name="w">The w component.</param>
223         public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(x, y, z, w), true)
224         {
225             ValueCheck(x);
226             ValueCheck(y);
227             ValueCheck(z);
228             ValueCheck(W);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230         }
231
232         /// <summary>
233         /// The constructor.
234         /// </summary>
235         /// <param name="relativeVector2">The RelativeVector2 to create this vector from.</param>
236         public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
237         {
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         /// <summary>
242         /// The constructor.
243         /// </summary>
244         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
245         public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
246         {
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248         }
249
250         private RelativeVector4 Add(RelativeVector4 rhs)
251         {
252             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             return ret;
255         }
256
257         private RelativeVector4 Subtract(RelativeVector4 rhs)
258         {
259             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         private RelativeVector4 Multiply(RelativeVector4 rhs)
265         {
266             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268             return ret;
269         }
270
271         private RelativeVector4 Multiply(float rhs)
272         {
273             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             return ret;
276         }
277
278         private RelativeVector4 Divide(RelativeVector4 rhs)
279         {
280             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             return ret;
283         }
284
285         private RelativeVector4 Divide(float rhs)
286         {
287             RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289             return ret;
290         }
291
292         private float ValueOfIndex(uint index)
293         {
294             float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
295             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296             return ret;
297         }
298
299         /// <summary>
300         /// Compares if the rhs is equal to.
301         /// </summary>
302         /// <param name="rhs">The vector to compare.</param>
303         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
304         public bool EqualTo(RelativeVector4 rhs)
305         {
306             bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         /// <summary>
312         /// Compares if the rhs is not equal to.
313         /// </summary>
314         /// <param name="rhs">The vector to compare.</param>
315         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
316         public bool NotEqualTo(RelativeVector4 rhs)
317         {
318             bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
319             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320             return ret;
321         }
322
323
324         /// <summary>
325         /// The x component.
326         /// </summary>
327         public float X
328         {
329             set
330             {
331                 ValueCheck(value);
332                 NDalicPINVOKE.Vector4_X_set(swigCPtr, value);
333                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334             }
335             get
336             {
337                 float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
338                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339                 return ret;
340             }
341         }
342
343         /// <summary>
344         /// The y component.
345         /// </summary>
346         public float Y
347         {
348             set
349             {
350                 ValueCheck(value);
351                 NDalicPINVOKE.Vector4_Y_set(swigCPtr, value);
352                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             }
354             get
355             {
356                 float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
357                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358                 return ret;
359             }
360         }
361
362         /// <summary>
363         /// The z component.
364         /// </summary>
365         public float Z
366         {
367             set
368             {
369                 ValueCheck(value);
370                 NDalicPINVOKE.Vector4_Z_set(swigCPtr, value);
371                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372             }
373             get
374             {
375                 float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
376                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377                 return ret;
378             }
379         }
380
381         /// <summary>
382         /// The w component.
383         /// </summary>
384         public float W
385         {
386             set
387             {
388                 ValueCheck(value);
389                 NDalicPINVOKE.Vector4_W_set(swigCPtr, value);
390                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391             }
392             get
393             {
394                 float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
395                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396                 return ret;
397             }
398         }
399
400         /// <summary>
401         /// </summary>
402         public static implicit operator Vector4(RelativeVector4 relativeVector4)
403         {
404             return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
405         }
406
407         /// <summary>
408         /// </summary>
409         public static implicit operator RelativeVector4(Vector4 vec)
410         {
411             ValueCheck(vec.X);
412             ValueCheck(vec.Y);
413             ValueCheck(vec.Z);
414             ValueCheck(vec.W);
415             return new RelativeVector4(vec.X, vec.Y, vec.Z, vec.W);
416         }
417
418         internal static void ValueCheck(RelativeVector4 relativeVector4)
419         {
420             if(relativeVector4.X < 0.0f)
421             {
422                 relativeVector4.X = 0.0f;
423                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
424             }
425             else if(relativeVector4.X > 1.0f)
426             {
427                 relativeVector4.X = 1.0f;
428                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
429             }
430             if(relativeVector4.Y < 0.0f)
431             {
432                 relativeVector4.Y = 0.0f;
433                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
434             }
435             else if(relativeVector4.Y > 1.0f)
436             {
437                 relativeVector4.Y = 1.0f;
438                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
439             }
440             if(relativeVector4.Z < 0.0f)
441             {
442                 relativeVector4.Z = 0.0f;
443                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
444             }
445             else if(relativeVector4.Z > 1.0f)
446             {
447                 relativeVector4.Z = 1.0f;
448                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
449             }
450             if(relativeVector4.W < 0.0f)
451             {
452                 relativeVector4.W = 0.0f;
453                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
454             }
455             else if(relativeVector4.W > 1.0f)
456             {
457                 relativeVector4.W = 1.0f;
458                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
459             }
460         }
461
462         internal static void ValueCheck(float value)
463         {
464             if(value < 0.0f)
465             {
466                 value = 0.0f;
467                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
468             }
469             else if(value > 1.0f)
470             {
471                 value = 1.0f;
472                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
473             }
474         }
475
476     }
477
478 }
479
480