324df2af45a1d281452c55570fc66a841c4658e8
[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         ~RelativeVector3()
43         {
44             DisposeQueue.Instance.Add(this);
45         }
46
47         public virtual void Dispose()
48         {
49             if (!Window.IsInstalled())
50             {
51                 DisposeQueue.Instance.Add(this);
52                 return;
53             }
54
55             lock (this)
56             {
57                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
58                 {
59                     if (swigCMemOwn)
60                     {
61                         swigCMemOwn = false;
62                         NDalicPINVOKE.delete_Vector3(swigCPtr);
63                     }
64                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65                 }
66                 global::System.GC.SuppressFinalize(this);
67             }
68         }
69
70
71         /// <summary>
72         /// Addition operator.
73         /// </summary>
74         /// <param name="arg1">Vector to add</param>
75         /// <param name="arg2">Vector to add</param>
76         /// <returns>A vector containing the result of the addition</returns>
77         public static RelativeVector3 operator +(RelativeVector3 arg1, RelativeVector3 arg2)
78         {
79             RelativeVector3 result = arg1.Add(arg2);
80             ValueCheck(result);
81             return result;
82         }
83
84         /// <summary>
85         /// Subtraction operator.
86         /// </summary>
87         /// <param name="arg1">Vector to subtract</param>
88         /// <param name="arg2">Vector to subtract</param>
89         /// <returns>A vector containing the result of the subtraction</returns>
90         public static RelativeVector3 operator -(RelativeVector3 arg1, RelativeVector3 arg2)
91         {
92             RelativeVector3 result = arg1.Subtract(arg2);
93             ValueCheck(result);
94             return result;
95         }
96
97         /// <summary>
98         /// Multiplication operator.
99         /// </summary>
100         /// <param name="arg1">The vector to multiply</param>
101         /// <param name="arg2">The vector to multiply</param>
102         /// <returns>A vector containing the result of the multiplication</returns>
103         public static RelativeVector3 operator *(RelativeVector3 arg1, RelativeVector3 arg2)
104         {
105             RelativeVector3 result = arg1.Multiply(arg2);
106             ValueCheck(result);
107             return result;
108         }
109
110         /// <summary>
111         /// Multiplication operator.
112         /// </summary>
113         /// <param name="arg1">The vector to multiply</param>
114         /// <param name="arg2">The float value to scale the vector</param>
115         /// <returns>A vector containing the result of the scaling</returns>
116         public static RelativeVector3 operator *(RelativeVector3 arg1, float arg2)
117         {
118             RelativeVector3 result = arg1.Multiply(arg2);
119             ValueCheck(result);
120             return result;
121         }
122
123         /// <summary>
124         /// Division operator.
125         /// </summary>
126         /// <param name="arg1">The vector to divide</param>
127         /// <param name="arg2">The vector to divide</param>
128         /// <returns>A vector containing the result of the division</returns>
129         public static RelativeVector3 operator /(RelativeVector3 arg1, RelativeVector3 arg2)
130         {
131             RelativeVector3 result = arg1.Divide(arg2);
132             ValueCheck(result);
133             return result;
134         }
135
136         /// <summary>
137         /// Division operator.
138         /// </summary>
139         /// <param name="arg1">The vector to divide</param>
140         /// <param name="arg2">The float value to scale the vector by</param>
141         /// <returns>A vector containing the result of the scaling</returns>
142         public static RelativeVector3 operator /(RelativeVector3 arg1, float arg2)
143         {
144             RelativeVector3 result = arg1.Divide(arg2);
145             ValueCheck(result);
146             return result;
147         }
148
149
150         /// <summary>
151         /// Const array subscript operator overload. Should be 0, 1 or 2.
152         /// </summary>
153         /// <param name="index">Subscript index</param>
154         /// <returns>The float at the given index</returns>
155         public float this[uint index]
156         {
157             get
158             {
159                 return ValueOfIndex(index);
160             }
161         }
162
163         /// <summary>
164         /// </summary>
165         internal static RelativeVector3 GetRelativeVector3FromPtr(global::System.IntPtr cPtr)
166         {
167             RelativeVector3 ret = new RelativeVector3(cPtr, false);
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169             return ret;
170         }
171
172
173         /// <summary>
174         /// Constructor
175         /// </summary>
176         public RelativeVector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
177         {
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179         }
180
181         /// <summary>
182         /// Constructor
183         /// </summary>
184         /// <param name="x">x component</param>
185         /// <param name="y">y component</param>
186         /// <param name="z">z component</param>
187         public RelativeVector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
188         {
189             ValueCheck(x);
190             ValueCheck(y);
191             ValueCheck(z);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193         }
194
195         /// <summary>
196         /// Constructor
197         /// </summary>
198         /// <param name="relativeVector2">RelativeVector2 to create this vector from</param>
199         public RelativeVector3(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
200         {
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203
204         /// <summary>
205         /// Constructor
206         /// </summary>
207         /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
208         public RelativeVector3(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
209         {
210             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211         }
212
213
214         private RelativeVector3 Add(RelativeVector3 rhs)
215         {
216             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Add(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218             return ret;
219         }
220
221         private RelativeVector3 Subtract(RelativeVector3 rhs)
222         {
223             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225             return ret;
226         }
227
228         private RelativeVector3 Multiply(RelativeVector3 rhs)
229         {
230             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             return ret;
233         }
234
235         private RelativeVector3 Multiply(float rhs)
236         {
237             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239             return ret;
240         }
241
242         private RelativeVector3 Divide(RelativeVector3 rhs)
243         {
244             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, RelativeVector3.getCPtr(rhs)), true);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246             return ret;
247         }
248
249         private RelativeVector3 Divide(float rhs)
250         {
251             RelativeVector3 ret = new RelativeVector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         private float ValueOfIndex(uint index)
257         {
258             float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         /// <summary>
264         /// Compare if rhs is equal to
265         /// </summary>
266         /// <param name="rhs">The vector to compare</param>
267         /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
268         public bool EqualTo(RelativeVector3 rhs)
269         {
270             bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275         /// <summary>
276         /// Compare if rhs is not equal to
277         /// </summary>
278         /// <param name="rhs">The vector to compare</param>
279         /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
280         public bool NotEqualTo(RelativeVector3 rhs)
281         {
282             bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, RelativeVector3.getCPtr(rhs));
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287
288         /// <summary>
289         /// x component
290         /// </summary>
291         public float X
292         {
293             set
294             {
295                 ValueCheck(value);
296                 NDalicPINVOKE.Vector3_X_set(swigCPtr, value);
297                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298             }
299             get
300             {
301                 float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr);
302                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303                 return ret;
304             }
305         }
306
307         /// <summary>
308         /// y component
309         /// </summary>
310         public float Y
311         {
312             set
313             {
314                 ValueCheck(value);
315                 NDalicPINVOKE.Vector3_Y_set(swigCPtr, value);
316                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317             }
318             get
319             {
320                 float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr);
321                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322                 return ret;
323             }
324         }
325
326         /// <summary>
327         /// z component
328         /// </summary>
329         public float Z
330         {
331             set
332             {
333                  ValueCheck(value);
334                 NDalicPINVOKE.Vector3_Z_set(swigCPtr, value);
335                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336             }
337             get
338             {
339                 float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr);
340                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341                 return ret;
342             }
343         }
344
345         /// <summary>
346         /// </summary>
347         public static implicit operator Vector3(RelativeVector3 relativeVector3)
348         {
349             return new Vector3(relativeVector3.X, relativeVector3.Y, relativeVector3.Z);
350         }
351
352         /// <summary>
353         /// </summary>
354         public static implicit operator RelativeVector3(Vector3 vec)
355         {
356             ValueCheck(vec.X);
357             ValueCheck(vec.Y);
358             ValueCheck(vec.Z);
359             return new RelativeVector3(vec.X, vec.Y, vec.Z);
360         }
361
362         internal static void ValueCheck(RelativeVector3 relativeVector3)
363         {
364             if(relativeVector3.X < 0.0f)
365             {
366                 relativeVector3.X = 0.0f;
367                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
368             }
369             else if(relativeVector3.X > 1.0f)
370             {
371                 relativeVector3.X = 1.0f;
372                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
373             }
374             if(relativeVector3.Y < 0.0f)
375             {
376                 relativeVector3.Y = 0.0f;
377                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
378             }
379             else if(relativeVector3.Y > 1.0f)
380             {
381                 relativeVector3.Y = 1.0f;
382                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
383             }
384             if(relativeVector3.Z < 0.0f)
385             {
386                 relativeVector3.Z = 0.0f;
387                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
388             }
389             else if(relativeVector3.Z > 1.0f)
390             {
391                 relativeVector3.Z = 1.0f;
392                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
393             }
394         }
395
396         internal static void ValueCheck(float value)
397         {
398             if(value < 0.0f)
399             {
400                 value = 0.0f;
401                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
402             }
403             else if(value > 1.0f)
404             {
405                 value = 1.0f;
406                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
407             }
408         }
409     }
410
411 }
412
413