Revert "[Tizen] Remove multiple ..."
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / RelativeVector2.cs
1 /*
2  * Copyright (c) 2017 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
19 namespace Tizen.NUI
20 {
21
22     /// <summary>
23     /// RelativeVector2 is a two dimensional vector.
24     /// Both values(x and y) should be between [0, 1].
25     /// </summary>
26     public class RelativeVector2 : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         protected bool swigCMemOwn;
30
31         internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
32         {
33             swigCMemOwn = cMemoryOwn;
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam) 
43
44         //A Flag to check who called Dispose(). (By User or DisposeQueue)
45         private bool isDisposeQueued = false;
46         //A Flat to check if it is already disposed.
47         protected bool disposed = false;
48
49         ~RelativeVector2()
50         {
51             if(!isDisposeQueued)
52             {
53                 isDisposeQueued = true;
54                 DisposeQueue.Instance.Add(this);
55             }
56         }
57
58         public void Dispose()
59         {
60             //Throw excpetion if Dispose() is called in separate thread.
61             if (!Window.IsInstalled())
62             {
63                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
64             }
65
66             if (isDisposeQueued)
67             {
68                 Dispose(DisposeTypes.Implicit);
69             }
70             else
71             {
72                 Dispose(DisposeTypes.Explicit);
73                 System.GC.SuppressFinalize(this);
74             }
75         }
76
77         protected virtual void Dispose(DisposeTypes type)
78         {
79             if (disposed)
80             {
81                 return;
82             }
83
84             if(type == DisposeTypes.Explicit)
85             {
86                 //Called by User
87                 //Release your own managed resources here.
88                 //You should release all of your own disposable objects here.
89             }
90
91             //Release your own unmanaged resources here.
92             //You should not access any managed member here except static instance.
93             //because the execution order of Finalizes is non-deterministic.
94
95             if (swigCPtr.Handle != global::System.IntPtr.Zero)
96             {
97                 if (swigCMemOwn)
98                 {
99                     swigCMemOwn = false;
100                     NDalicPINVOKE.delete_Vector2(swigCPtr);
101                 }
102                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103             }
104             disposed = true;
105         }
106
107
108         /// <summary>
109         /// Addition operator.
110         /// </summary>
111         /// <param name="arg1">Vector to add</param>
112         /// <param name="arg2">Vector to add</param>
113         /// <returns>A vector containing the result of the addition</returns>
114         public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
115         {
116             RelativeVector2 result = arg1.Add(arg2);
117             ValueCheck(result);
118             return result;
119         }
120
121         /// <summary>
122         /// Subtraction operator.
123         /// </summary>
124         /// <param name="arg1">Vector to subtract</param>
125         /// <param name="arg2">Vector to subtract</param>
126         /// <returns>A vector containing the result of the subtraction</returns>
127         public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
128         {
129             RelativeVector2 result = arg1.Subtract(arg2);
130             ValueCheck(result);
131             return result;
132         }
133
134         /// <summary>
135         /// Multiplication operator.
136         /// </summary>
137         /// <param name="arg1">The vector to multiply</param>
138         /// <param name="arg2">The vector to multiply</param>
139         /// <returns>A vector containing the result of the multiplication</returns>
140         public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
141         {
142             RelativeVector2 result = arg1.Multiply(arg2);
143             ValueCheck(result);
144             return result;
145         }
146
147         /// <summary>
148         /// Multiplication operator.
149         /// </summary>
150         /// <param name="arg1">The vector to multiply</param>
151         /// <param name="arg2">The float value to scale the vector</param>
152         /// <returns>A vector containing the result of the scaling</returns>
153         public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
154         {
155             RelativeVector2 result = arg1.Multiply(arg2);
156             ValueCheck(result);
157             return result;
158         }
159
160         /// <summary>
161         /// Division operator.
162         /// </summary>
163         /// <param name="arg1">The vector to divide</param>
164         /// <param name="arg2">The vector to divide</param>
165         /// <returns>A vector containing the result of the division</returns>
166         public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
167         {
168             RelativeVector2 result = arg1.Divide(arg2);
169             ValueCheck(result);
170             return result;
171         }
172
173         /// <summary>
174         /// Division operator.
175         /// </summary>
176         /// <param name="arg1">The vector to divide</param>
177         /// <param name="arg2">The float value to scale the vector by</param>
178         /// <returns>A vector containing the result of the scaling</returns>
179         public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
180         {
181             RelativeVector2 result = arg1.Divide(arg2);
182             ValueCheck(result);
183             return result;
184         }
185
186
187         /// <summary>
188         /// Const array subscript operator overload. Should be 0, 1.
189         /// </summary>
190         /// <param name="index">Subscript index</param>
191         /// <returns>The float at the given index</returns>
192         public float this[uint index]
193         {
194             get
195             {
196                 return ValueOfIndex(index);
197             }
198         }
199
200         /// <summary>
201         /// </summary>
202         internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
203         {
204             RelativeVector2 ret = new RelativeVector2(cPtr, false);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209
210         /// <summary>
211         /// Constructor
212         /// </summary>
213         public RelativeVector2() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
214         {
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216         }
217
218         /// <summary>
219         /// Constructor
220         /// </summary>
221         /// <param name="x">x component</param>
222         /// <param name="y">y component</param>
223         public RelativeVector2(float x, float y) : this(NDalicPINVOKE.new_Vector2__SWIG_1(x, y), true)
224         {
225             ValueCheck(x);
226             ValueCheck(y);
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229
230         /// <summary>
231         /// Constructor
232         /// </summary>
233         /// <param name="relativeVector3">RelativeVector3 to create this vector from</param>
234         public RelativeVector2(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
235         {
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237         }
238
239         /// <summary>
240         /// Constructor
241         /// </summary>
242         /// <param name="relativeVector4">RelativeVector4 to create this vector from</param>
243         public RelativeVector2(RelativeVector4 relativeVector4) : this(NDalicPINVOKE.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
244         {
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248
249         private RelativeVector2 Add(RelativeVector2 rhs)
250         {
251             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         private RelativeVector2 Subtract(RelativeVector2 rhs)
257         {
258             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         private RelativeVector2 Multiply(RelativeVector2 rhs)
264         {
265             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267             return ret;
268         }
269
270         private RelativeVector2 Multiply(float rhs)
271         {
272             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private RelativeVector2 Divide(RelativeVector2 rhs)
278         {
279             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         private RelativeVector2 Divide(float rhs)
285         {
286             RelativeVector2 ret = new RelativeVector2(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         private float ValueOfIndex(uint index)
292         {
293             float ret = NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         /// <summary>
299         /// Compare if rhs is equal to
300         /// </summary>
301         /// <param name="rhs">The vector to compare</param>
302         /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
303         public bool EqualTo(RelativeVector2 rhs)
304         {
305             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307             return ret;
308         }
309
310         /// <summary>
311         /// Compare if rhs is not equal to
312         /// </summary>
313         /// <param name="rhs">The vector to compare</param>
314         /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
315         public bool NotEqualTo(RelativeVector2 rhs)
316         {
317             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319             return ret;
320         }
321
322
323         /// <summary>
324         /// x component
325         /// </summary>
326         public float X
327         {
328             set
329             {
330                 ValueCheck(value);
331                 NDalicPINVOKE.Vector2_X_set(swigCPtr, value);
332                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             }
334             get
335             {
336                 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
337                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338                 return ret;
339             }
340         }
341
342         /// <summary>
343         /// y component
344         /// </summary>
345         public float Y
346         {
347             set
348             {
349                 ValueCheck(value);
350                 NDalicPINVOKE.Vector2_Y_set(swigCPtr, value);
351                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             }
353             get
354             {
355                 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
356                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357                 return ret;
358             }
359         }
360
361         /// <summary>
362         /// </summary>
363         public static implicit operator Vector2(RelativeVector2 relativeVector2)
364         {
365             return new Vector2(relativeVector2.X, relativeVector2.Y);
366         }
367
368         /// <summary>
369         /// </summary>
370         public static implicit operator RelativeVector2(Vector2 vec)
371         {
372             ValueCheck(vec.X);
373             ValueCheck(vec.Y);
374             return new RelativeVector2(vec.X, vec.Y);
375         }
376
377         internal static void ValueCheck(RelativeVector2 relativeVector2)
378         {
379             if(relativeVector2.X < 0.0f)
380             {
381                 relativeVector2.X = 0.0f;
382                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
383             }
384             else if(relativeVector2.X > 1.0f)
385             {
386                 relativeVector2.X = 1.0f;
387                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
388             }
389             if(relativeVector2.Y < 0.0f)
390             {
391                 relativeVector2.Y = 0.0f;
392                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
393             }
394             else if(relativeVector2.Y > 1.0f)
395             {
396                 relativeVector2.Y = 1.0f;
397                 Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
398             }
399         }
400
401         internal static void ValueCheck(float value)
402         {
403             if(value < 0.0f)
404             {
405                 value = 0.0f;
406                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
407             }
408             else if(value > 1.0f)
409             {
410                 value = 1.0f;
411                 Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
412             }
413         }
414     }
415
416 }
417
418