Release 4.0.0-preview1-00051
[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         /// Addition operator.
108         /// </summary>
109         /// <param name="arg1">Vector to add</param>
110         /// <param name="arg2">Vector to add</param>
111         /// <returns>A vector containing the result of the addition</returns>
112         public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2)
113         {
114             RelativeVector3 result = arg1.Add(arg2);
115             ValueCheck(result);
116             return result;
117         }
118
119         /// <summary>
120         /// Subtraction operator.
121         /// </summary>
122         /// <param name="arg1">Vector to subtract</param>
123         /// <param name="arg2">Vector to subtract</param>
124         /// <returns>A vector containing the result of the subtraction</returns>
125         public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2)
126         {
127             RelativeVector3 result = arg1.Subtract(arg2);
128             ValueCheck(result);
129             return result;
130         }
131
132         /// <summary>
133         /// Multiplication operator.
134         /// </summary>
135         /// <param name="arg1">The vector to multiply</param>
136         /// <param name="arg2">The vector to multiply</param>
137         /// <returns>A vector containing the result of the multiplication</returns>
138         public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2)
139         {
140             RelativeVector3 result = arg1.Multiply(arg2);
141             ValueCheck(result);
142             return result;
143         }
144
145         /// <summary>
146         /// 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>A vector containing the result of the scaling</returns>
151         public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2)
152         {
153             RelativeVector3 result = arg1.Multiply(arg2);
154             ValueCheck(result);
155             return result;
156         }
157
158         /// <summary>
159         /// Division operator.
160         /// </summary>
161         /// <param name="arg1">The vector to divide</param>
162         /// <param name="arg2">The vector to divide</param>
163         /// <returns>A vector containing the result of the division</returns>
164         public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2)
165         {
166             RelativeVector3 result = arg1.Divide(arg2);
167             ValueCheck(result);
168             return result;
169         }
170
171         /// <summary>
172         /// 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>A vector containing the result of the scaling</returns>
177         public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2)
178         {
179             RelativeVector3 result = arg1.Divide(arg2);
180             ValueCheck(result);
181             return result;
182         }
183
184
185         /// <summary>
186         /// Const array subscript operator overload. Should be 0, 1 or 2.
187         /// </summary>
188         /// <param name="index">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 RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
201         {
202             RelativeVector3 ret = new RelativeVector3(cPtr, false);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206
207
208         /// <summary>
209         /// Constructor
210         /// </summary>
211         public RelativeVector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
212         {
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// Constructor
218         /// </summary>
219         /// <param name="x">x component</param>
220         /// <param name="y">y component</param>
221         /// <param name="z">z component</param>
222         public RelativeVector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
223         {
224             ValueCheck(x);
225             ValueCheck(y);
226             ValueCheck(z);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229
230         /// <summary>
231         /// Constructor
232         /// </summary>
233         /// <param name="relativeVector2">RelativeVector2 to create this vector from</param>
234         public RelativeVector3(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
235         {
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237         }
238
239         /// <summary>
240         /// Constructor
241         /// </summary>
242         /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
243         public RelativeVector3(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
244         {
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248
249         private RelativeVector3 Add(RelativeVector3 rhs)
250         {
251             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         private RelativeVector3 Subtract(RelativeVector3 rhs)
257         {
258             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         private RelativeVector3 Multiply(RelativeVector3 rhs)
264         {
265             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267             return ret;
268         }
269
270         private RelativeVector3 Multiply(float rhs)
271         {
272             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private RelativeVector3 Divide(RelativeVector3 rhs)
278         {
279             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         private RelativeVector3 Divide(float rhs)
285         {
286             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         private float ValueOfIndex(uint index)
292         {
293             float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         /// <summary>
299         /// Compare if rhs is equal to
300         /// </summary>
301         /// <param name="rhs">The vector to compare</param>
302         /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
303         public bool EqualTo(RelativeVector3 rhs)
304         {
305             bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307             return ret;
308         }
309
310         /// <summary>
311         /// Compare if rhs is not equal to
312         /// </summary>
313         /// <param name="rhs">The vector to compare</param>
314         /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
315         public bool NotEqualTo(RelativeVector3 rhs)
316         {
317             bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319             return ret;
320         }
321
322
323         /// <summary>
324         /// x component
325         /// </summary>
326         public float X
327         {
328             set
329             {
330                 ValueCheck(value);
331                 NDalicPINVOKE.Vector3_X_set(swigCPtr, value);
332                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             }
334             get
335             {
336                 float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr);
337                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338                 return ret;
339             }
340         }
341
342         /// <summary>
343         /// y component
344         /// </summary>
345         public float Y
346         {
347             set
348             {
349                 ValueCheck(value);
350                 NDalicPINVOKE.Vector3_Y_set(swigCPtr, value);
351                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             }
353             get
354             {
355                 float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr);
356                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357                 return ret;
358             }
359         }
360
361         /// <summary>
362         /// z component
363         /// </summary>
364         public float Z
365         {
366             set
367             {
368                  ValueCheck(value);
369                 NDalicPINVOKE.Vector3_Z_set(swigCPtr, value);
370                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371             }
372             get
373             {
374                 float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr);
375                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376                 return ret;
377             }
378         }
379
380         /// <summary>
381         /// </summary>
382         public static implicit operator Vector3(RelativeVector3 relativeVector3)
383         {
384             return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
385         }
386
387         /// <summary>
388         /// </summary>
389         public static implicit operator RelativeVector3(Vector3 vec)
390         {
391             ValueCheck(vec.X);
392             ValueCheck(vec.Y);
393             ValueCheck(vec.Z);
394             return new RelativeVector3(vec.X, vec.Y, vec.Z);
395         }
396
397         internal static void ValueCheck(RelativeVector3 relativeVector3)
398         {
399             if(relativeVector3.X < 0.0f)
400             {
401                 relativeVector3.X = 0.0f;
402                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
403             }
404             else if(relativeVector3.X > 1.0f)
405             {
406                 relativeVector3.X = 1.0f;
407                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
408             }
409             if(relativeVector3.Y < 0.0f)
410             {
411                 relativeVector3.Y = 0.0f;
412                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
413             }
414             else if(relativeVector3.Y > 1.0f)
415             {
416                 relativeVector3.Y = 1.0f;
417                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
418             }
419             if(relativeVector3.Z < 0.0f)
420             {
421                 relativeVector3.Z = 0.0f;
422                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
423             }
424             else if(relativeVector3.Z > 1.0f)
425             {
426                 relativeVector3.Z = 1.0f;
427                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
428             }
429         }
430
431         internal static void ValueCheck(float value)
432         {
433             if(value < 0.0f)
434             {
435                 value = 0.0f;
436                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
437             }
438             else if(value > 1.0f)
439             {
440                 value = 1.0f;
441                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
442             }
443         }
444     }
445
446 }
447
448