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