f9c54e593a9c8408b0c9d9123803b5a3d0f17a45
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / RelativeVector2.cs
1 /*
2  * Copyright (c) 2021 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 System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// RelativeVector2 is a two-dimensional vector.
25     /// Both values (x and y) should be between [0, 1].
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     [Binding.TypeConverter(typeof(RelativeVector2TypeConverter))]
29     public class RelativeVector2 : Disposable
30     {
31         /// <summary>
32         /// The constructor.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public RelativeVector2() : this(Interop.Vector2.NewVector2(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         /// <summary>
41         /// The constructor.
42         /// </summary>
43         /// <param name="x">The x component.</param>
44         /// <param name="y">The y component.</param>
45         /// <since_tizen> 3 </since_tizen>
46         public RelativeVector2(float x, float y) : this(Interop.Vector2.NewVector2(x, y), true)
47         {
48             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49         }
50
51         /// <summary>
52         /// The constructor.
53         /// </summary>
54         /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
55         /// <since_tizen> 3 </since_tizen>
56         public RelativeVector2(RelativeVector3 relativeVector3) : this(Interop.Vector2.NewVector2WithVector3(RelativeVector3.getCPtr(relativeVector3)), true)
57         {
58             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59         }
60
61         /// <summary>
62         /// The constructor.
63         /// </summary>
64         /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
65         /// <since_tizen> 3 </since_tizen>
66         public RelativeVector2(RelativeVector4 relativeVector4) : this(Interop.Vector2.NewVector2WithVector4(RelativeVector4.getCPtr(relativeVector4)), true)
67         {
68             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69         }
70
71         internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
72         {
73         }
74
75         /// <summary>
76         /// The x component.
77         /// </summary>
78         /// <remarks>
79         /// The setter is deprecated in API8 and will be removed in API10. Please use new RelativeVector2(...) constructor.
80         /// </remarks>
81         /// <code>
82         /// // DO NOT use like the followings!
83         /// RelativeVector2 relativeVector2 = new RelativeVector2();
84         /// relativeVector2.X = 0.1f; 
85         /// // Please USE like this
86         /// float x = 0.1f, y = 0.9f;
87         /// RelativeVector2 relativeVector2 = new RelativeVector2(x, y);
88         /// </code>
89         /// <since_tizen> 3 </since_tizen>
90         public float X
91         {
92             [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new RelativeVector2(...) constructor")]
93             set
94             {
95                 Interop.Vector2.XSet(SwigCPtr, value);
96                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97             }
98             get
99             {
100                 float ret = Interop.Vector2.XGet(SwigCPtr);
101                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
102                 return ret;
103             }
104         }
105
106         /// <summary>
107         /// The y component.
108         /// </summary>
109         /// <remarks>
110         /// The setter is deprecated in API8 and will be removed in API10. Please use new RelativeVector2(...) constructor.
111         /// </remarks>
112         /// <code>
113         /// // DO NOT use like the followings!
114         /// RelativeVector2 relativeVector2 = new RelativeVector2();
115         /// relativeVector2.Y = 0.9f; 
116         /// // Please USE like this
117         /// float x = 0.1f, y = 0.9f;
118         /// RelativeVector2 relativeVector2 = new RelativeVector2(x, y);
119         /// </code>
120         /// <since_tizen> 3 </since_tizen>
121         public float Y
122         {
123             [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new RelativeVector2(...) constructor")]
124             set
125             {
126                 Interop.Vector2.YSet(SwigCPtr, value);
127                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128             }
129             get
130             {
131                 float ret = Interop.Vector2.YGet(SwigCPtr);
132                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", 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">The vector to add.</param>
142         /// <returns>The vector containing the result of the addition.</returns>
143         /// <since_tizen> 3 </since_tizen>
144         public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
145         {
146             RelativeVector2 result = arg1?.Add(arg2);
147             return 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 RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
158         {
159             RelativeVector2 result = arg1?.Subtract(arg2);
160             return 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 RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
171         {
172             RelativeVector2 result = arg1?.Multiply(arg2);
173             return 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 RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
184         {
185             RelativeVector2 result = arg1?.Multiply(arg2);
186             return 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 RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
197         {
198             RelativeVector2 result = arg1?.Divide(arg2);
199             return 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 RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
210         {
211             RelativeVector2 result = arg1?.Divide(arg2);
212             return result;
213         }
214
215         /// <summary>
216         /// </summary>
217         /// <since_tizen> 3 </since_tizen>
218         public static implicit operator Vector2(RelativeVector2 relativeVector2)
219         {
220             if (relativeVector2 == null)
221             {
222                 return null;
223             }
224             return new Vector2(relativeVector2.X, relativeVector2.Y);
225         }
226
227         /// <summary>
228         /// </summary>
229         /// <since_tizen> 3 </since_tizen>
230         public static implicit operator RelativeVector2(Vector2 vec)
231         {
232             if (vec == null)
233             {
234                 return null;
235             }
236             return new RelativeVector2(vec.X, vec.Y);
237         }
238
239         /// <summary>
240         /// The const array subscript operator overload. Should be 0, 1.
241         /// </summary>
242         /// <param name="index">The subscript index.</param>
243         /// <returns>The float at the given index.</returns>
244         /// <since_tizen> 3 </since_tizen>
245         public float this[uint index]
246         {
247             get
248             {
249                 return ValueOfIndex(index);
250             }
251         }
252
253         /// <summary>
254         /// Determines whether the specified object is equal to the current object.
255         /// </summary>
256         /// <param name="obj">The object to compare with the current object.</param>
257         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
258         public override bool Equals(System.Object obj)
259         {
260             RelativeVector2 relativeRector2 = obj as RelativeVector2;
261             bool equal = false;
262             if (X == relativeRector2?.X && Y == relativeRector2?.Y)
263             {
264                 equal = true;
265             }
266             return equal;
267         }
268
269         /// <summary>
270         /// Gets the hash code of this RelativeVector2.
271         /// </summary>
272         /// <returns>The Hash Code.</returns>
273         /// <since_tizen> 6 </since_tizen>
274         public override int GetHashCode()
275         {
276             return SwigCPtr.Handle.GetHashCode();
277         }
278
279         /// <summary>
280         /// Compares if the rhs is equal to.
281         /// </summary>
282         /// <param name="rhs">The vector to compare.</param>
283         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
284         /// <since_tizen> 3 </since_tizen>
285         public bool EqualTo(RelativeVector2 rhs)
286         {
287             bool ret = Interop.Vector2.EqualTo(SwigCPtr, RelativeVector2.getCPtr(rhs));
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289             return ret;
290         }
291
292         /// <summary>
293         /// Compares if the rhs is not equal to.
294         /// </summary>
295         /// <param name="rhs">The vector to compare.</param>
296         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
297         /// <since_tizen> 3 </since_tizen>
298         public bool NotEqualTo(RelativeVector2 rhs)
299         {
300             bool ret = Interop.Vector2.NotEqualTo(SwigCPtr, RelativeVector2.getCPtr(rhs));
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         /// <summary>
306         /// </summary>
307         internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
308         {
309             RelativeVector2 ret = new RelativeVector2(cPtr, false);
310             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311             return ret;
312         }
313
314         /// This will not be public opened.
315         [EditorBrowsable(EditorBrowsableState.Never)]
316         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
317         {
318             Interop.Vector2.DeleteVector2(swigCPtr);
319         }
320
321         private RelativeVector2 Add(RelativeVector2 rhs)
322         {
323             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Add(SwigCPtr, RelativeVector2.getCPtr(rhs)), true);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         private RelativeVector2 Subtract(RelativeVector2 rhs)
329         {
330             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Subtract(SwigCPtr, RelativeVector2.getCPtr(rhs)), true);
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332             return ret;
333         }
334
335         private RelativeVector2 Multiply(RelativeVector2 rhs)
336         {
337             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Multiply(SwigCPtr, RelativeVector2.getCPtr(rhs)), true);
338             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339             return ret;
340         }
341
342         private RelativeVector2 Multiply(float rhs)
343         {
344             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Multiply(SwigCPtr, rhs), true);
345             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346             return ret;
347         }
348
349         private RelativeVector2 Divide(RelativeVector2 rhs)
350         {
351             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Divide(SwigCPtr, RelativeVector2.getCPtr(rhs)), true);
352             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             return ret;
354         }
355
356         private RelativeVector2 Divide(float rhs)
357         {
358             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Divide(SwigCPtr, rhs), true);
359             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             return ret;
361         }
362
363         private float ValueOfIndex(uint index)
364         {
365             float ret = Interop.Vector2.ValueOfIndex(SwigCPtr, index);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367             return ret;
368         }
369     }
370 }