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