e283c540f5e9039e101ef22e8937507872e0de9f
[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.ComponentModel;
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     [Binding.TypeConverter(typeof(RelativeVector2TypeConverter))]
28     public class RelativeVector2 : Disposable
29     {
30
31         /// <summary>
32         /// The constructor.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public RelativeVector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), 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.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(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.new_Vector2__SWIG_3(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.new_Vector2__SWIG_4(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         /// <since_tizen> 3 </since_tizen>
79         public float X
80         {
81             set
82             {
83                 Interop.Vector2.Vector2_X_set(swigCPtr, ValueCheck(value));
84                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85             }
86             get
87             {
88                 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
89                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90                 return ret;
91             }
92         }
93
94         /// <summary>
95         /// The y component.
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         public float Y
99         {
100             set
101             {
102                 Interop.Vector2.Vector2_Y_set(swigCPtr, ValueCheck(value));
103                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104             }
105             get
106             {
107                 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
108                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109                 return ret;
110             }
111         }
112
113         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
114         {
115             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
116         }
117
118         /// <summary>
119         /// The addition operator.
120         /// </summary>
121         /// <param name="arg1">The vector to add.</param>
122         /// <param name="arg2">The vector to add.</param>
123         /// <returns>The vector containing the result of the addition.</returns>
124         /// <since_tizen> 3 </since_tizen>
125         public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
126         {
127             RelativeVector2 result = arg1.Add(arg2);
128             return ValueCheck(result);
129         }
130
131         /// <summary>
132         /// The subtraction operator.
133         /// </summary>
134         /// <param name="arg1">The vector to subtract.</param>
135         /// <param name="arg2">The vector to subtract.</param>
136         /// <returns>The vector containing the result of the subtraction.</returns>
137         /// <since_tizen> 3 </since_tizen>
138         public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
139         {
140             RelativeVector2 result = arg1.Subtract(arg2);
141             return ValueCheck(result);
142         }
143
144         /// <summary>
145         /// The multiplication operator.
146         /// </summary>
147         /// <param name="arg1">The vector to multiply.</param>
148         /// <param name="arg2">The vector to multiply.</param>
149         /// <returns>The vector containing the result of the multiplication.</returns>
150         /// <since_tizen> 3 </since_tizen>
151         public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
152         {
153             RelativeVector2 result = arg1.Multiply(arg2);
154             return ValueCheck(result);
155         }
156
157         /// <summary>
158         /// The multiplication operator.
159         /// </summary>
160         /// <param name="arg1">The vector to multiply.</param>
161         /// <param name="arg2">The float value to scale the vector.</param>
162         /// <returns>The vector containing the result of the scaling.</returns>
163         /// <since_tizen> 3 </since_tizen>
164         public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
165         {
166             RelativeVector2 result = arg1.Multiply(arg2);
167             return ValueCheck(result);
168         }
169
170         /// <summary>
171         /// The division operator.
172         /// </summary>
173         /// <param name="arg1">The vector to divide.</param>
174         /// <param name="arg2">The vector to divide.</param>
175         /// <returns>The vector containing the result of the division.</returns>
176         /// <since_tizen> 3 </since_tizen>
177         public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
178         {
179             RelativeVector2 result = arg1.Divide(arg2);
180             return ValueCheck(result);
181         }
182
183         /// <summary>
184         /// The division operator.
185         /// </summary>
186         /// <param name="arg1">The vector to divide.</param>
187         /// <param name="arg2">The float value to scale the vector by.</param>
188         /// <returns>The vector containing the result of the scaling.</returns>
189         /// <since_tizen> 3 </since_tizen>
190         public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
191         {
192             RelativeVector2 result = arg1.Divide(arg2);
193             return ValueCheck(result);
194         }
195
196         /// <summary>
197         /// </summary>
198         /// <since_tizen> 3 </since_tizen>
199         public static implicit operator Vector2(RelativeVector2 relativeVector2)
200         {
201             return new Vector2(relativeVector2.X, relativeVector2.Y);
202         }
203
204         /// <summary>
205         /// </summary>
206         /// <since_tizen> 3 </since_tizen>
207         public static implicit operator RelativeVector2(Vector2 vec)
208         {
209             return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
210         }
211
212         /// <summary>
213         /// The const array subscript operator overload. Should be 0, 1.
214         /// </summary>
215         /// <param name="index">The subscript index.</param>
216         /// <returns>The float at the given index.</returns>
217         /// <since_tizen> 3 </since_tizen>
218         public float this[uint index]
219         {
220             get
221             {
222                 return ValueOfIndex(index);
223             }
224         }
225
226         /// <summary>
227         /// Determines whether the specified object is equal to the current object.
228         /// </summary>
229         /// <param name="obj">The object to compare with the current object.</param>
230         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
231         public override bool Equals(System.Object obj)
232         {
233             RelativeVector2 relativeRector2 = obj as RelativeVector2;
234             bool equal = false;
235             if (X == relativeRector2?.X && Y == relativeRector2?.Y)
236             {
237                 equal = true;
238             }
239             return equal;
240         }
241
242         /// <summary>
243         /// Gets the the hash code of this RelativeVector2.
244         /// </summary>
245         /// <returns>The Hash Code.</returns>
246         /// <since_tizen> 6 </since_tizen>
247         public override int GetHashCode()
248         {
249             return swigCPtr.Handle.GetHashCode();
250         }
251
252         /// <summary>
253         /// Compares if the rhs is equal to.
254         /// </summary>
255         /// <param name="rhs">The vector to compare.</param>
256         /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
257         /// <since_tizen> 3 </since_tizen>
258         public bool EqualTo(RelativeVector2 rhs)
259         {
260             bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264
265         /// <summary>
266         /// Compares if the rhs is not equal to.
267         /// </summary>
268         /// <param name="rhs">The vector to compare.</param>
269         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
270         /// <since_tizen> 3 </since_tizen>
271         public bool NotEqualTo(RelativeVector2 rhs)
272         {
273             bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             return ret;
276         }
277
278         /// <summary>
279         /// </summary>
280         internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
281         {
282             RelativeVector2 ret = new RelativeVector2(cPtr, false);
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287         internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
288         {
289             if (relativeVector2.X < 0.0f)
290             {
291                 relativeVector2.X = 0.0f;
292                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
293             }
294             else if (relativeVector2.X > 1.0f)
295             {
296                 relativeVector2.X = 1.0f;
297                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
298             }
299             if (relativeVector2.Y < 0.0f)
300             {
301                 relativeVector2.Y = 0.0f;
302                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
303             }
304             else if (relativeVector2.Y > 1.0f)
305             {
306                 relativeVector2.Y = 1.0f;
307                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
308             }
309             return relativeVector2;
310         }
311
312         internal static float ValueCheck(float value)
313         {
314             if (value < 0.0f)
315             {
316                 value = 0.0f;
317                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
318             }
319             else if (value > 1.0f)
320             {
321                 value = 1.0f;
322                 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
323             }
324             return value;
325         }
326
327         /// This will not be public opened.
328         [EditorBrowsable(EditorBrowsableState.Never)]
329         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
330         {
331             Interop.Vector2.delete_Vector2(swigCPtr);
332         }
333
334         private RelativeVector2 Add(RelativeVector2 rhs)
335         {
336             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         private RelativeVector2 Subtract(RelativeVector2 rhs)
342         {
343             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             return ret;
346         }
347
348         private RelativeVector2 Multiply(RelativeVector2 rhs)
349         {
350             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             return ret;
353         }
354
355         private RelativeVector2 Multiply(float rhs)
356         {
357             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359             return ret;
360         }
361
362         private RelativeVector2 Divide(RelativeVector2 rhs)
363         {
364             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
365             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366             return ret;
367         }
368
369         private RelativeVector2 Divide(float rhs)
370         {
371             RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373             return ret;
374         }
375
376         private float ValueOfIndex(uint index)
377         {
378             float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
379             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380             return ret;
381         }
382     }
383 }
384
385