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