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