[NUI] Reduce code duplication - refactor dispose codes (#1010)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rotation.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  using Tizen.NUI.Binding;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// The Rotation class.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     [TypeConverter(typeof(RotationTypeConverter))]
27     public class Rotation : Disposable
28     {
29         /// <summary>
30         /// swigCMemOwn
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         protected bool swigCMemOwn;
34
35         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36
37         /// <summary>
38         /// The default constructor.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         public Rotation() : this(Interop.Rotation.new_Rotation__SWIG_0(), true)
42         {
43             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
44         }
45
46         /// <summary>
47         /// The constructor from an axis and angle.
48         /// </summary>
49         /// <param name="angle">The angle around the axis.</param>
50         /// <param name="axis">The vector of the axis.</param>
51         /// <since_tizen> 3 </since_tizen>
52         public Rotation(Radian angle, Vector3 axis) : this(Interop.Rotation.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
53         {
54             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55         }
56
57         /// <summary>
58         /// (0.0f,0.0f,0.0f,1.0f).
59         /// </summary>
60         /// <since_tizen> 3 </since_tizen>
61         public static Rotation IDENTITY
62         {
63             get
64             {
65                 global::System.IntPtr cPtr = Interop.Rotation.Rotation_IDENTITY_get();
66                 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
67                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68                 return ret;
69             }
70         }
71
72         /// <summary>
73         /// The addition operator.
74         /// </summary>
75         /// <param name="arg1">The first rotation.</param>
76         /// <param name="arg2">The second rotation.</param>
77         /// <returns>The rotation containing the result of the addition.</returns>
78         /// <since_tizen> 3 </since_tizen>
79         public static Rotation operator +(Rotation arg1, Rotation arg2)
80         {
81             return arg1.Add(arg2);
82         }
83
84         /// <summary>
85         /// The subtraction operator.
86         /// </summary>
87         /// <param name="arg1">The first rotation.</param>
88         /// <param name="arg2">The second rotation.</param>
89         /// <returns>The rotation containing the result of the subtraction.</returns>
90         /// <since_tizen> 3 </since_tizen>
91         public static Rotation operator -(Rotation arg1, Rotation arg2)
92         {
93             return arg1.Subtract(arg2);
94         }
95
96         /// <summary>
97         /// The unary negation operator.
98         /// </summary>
99         /// <param name="arg1">The first rotation.</param>
100         /// <returns>The rotation containing the negated result.</returns>
101         /// <since_tizen> 3 </since_tizen>
102         public static Rotation operator -(Rotation arg1)
103         {
104             return arg1.Subtract();
105         }
106
107         /// <summary>
108         /// The multiplication operator.
109         /// </summary>
110         /// <param name="arg1">The first rotation.</param>
111         /// <param name="arg2">The second rotation.</param>
112         /// <returns>The rotation containing the result of the multiplication.</returns>
113         /// <since_tizen> 3 </since_tizen>
114         public static Rotation operator *(Rotation arg1, Rotation arg2)
115         {
116             return arg1.Multiply(arg2);
117         }
118
119         /// <summary>
120         /// The multiplication operator.
121         /// </summary>
122         /// <param name="arg1">Rotation.</param>
123         /// <param name="arg2">The vector to multiply.</param>
124         /// <returns>The rotation containing the result of the multiplication.</returns>
125         /// <since_tizen> 3 </since_tizen>
126         public static Vector3 operator *(Rotation arg1, Vector3 arg2)
127         {
128             return arg1.Multiply(arg2);
129         }
130
131         /// <summary>
132         /// The scale operator.
133         /// </summary>
134         /// <param name="arg1">Rotation.</param>
135         /// <param name="arg2">A value to scale by.</param>
136         /// <returns>The rotation containing the result of scaling.</returns>
137         /// <since_tizen> 3 </since_tizen>
138         public static Rotation operator *(Rotation arg1, float arg2)
139         {
140             return arg1.Multiply(arg2);
141         }
142
143         /// <summary>
144         /// The division operator.
145         /// </summary>
146         /// <param name="arg1">The first rotation.</param>
147         /// <param name="arg2">The second rotation.</param>
148         /// <returns>The rotation containing the result of scaling.</returns>
149         /// <since_tizen> 3 </since_tizen>
150         public static Rotation operator /(Rotation arg1, Rotation arg2)
151         {
152             return arg1.Divide(arg2);
153         }
154
155         /// <summary>
156         /// The scale operator.
157         /// </summary>
158         /// <param name="arg1">Rotation.</param>
159         /// <param name="arg2">A value to scale by.</param>
160         /// <returns>The rotation containing the result of scaling.</returns>
161         /// <since_tizen> 3 </since_tizen>
162         public static Rotation operator /(Rotation arg1, float arg2)
163         {
164             return arg1.Divide(arg2);
165         }
166
167         /// <summary>
168         /// Returns the dot product of two rotations.
169         /// </summary>
170         /// <param name="q1">The first rotation.</param>
171         /// <param name="q2">The second rotation.</param>
172         /// <returns>The dot product of the two rotations.</returns>
173         /// <since_tizen> 3 </since_tizen>
174         public static float Dot(Rotation q1, Rotation q2)
175         {
176             float ret = Interop.Rotation.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178             return ret;
179         }
180
181         /// <summary>
182         /// The linear iterpolation (using a straight line between the two rotations).
183         /// </summary>
184         /// <param name="q1">The start rotation.</param>
185         /// <param name="q2">The end rotation.</param>
186         /// <param name="t">A progress value between 0 and 1.</param>
187         /// <returns>The interpolated rotation.</returns>
188         /// <since_tizen> 3 </since_tizen>
189         public static Rotation Lerp(Rotation q1, Rotation q2, float t)
190         {
191             Rotation ret = new Rotation(Interop.Rotation.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             return ret;
194         }
195
196         /// <summary>
197         /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
198         /// </summary>
199         /// <param name="q1">The start rotation.</param>
200         /// <param name="q2">The end rotation.</param>
201         /// <param name="progress">A progress value between 0 and 1.</param>
202         /// <returns>The interpolated rotation.</returns>
203         /// <since_tizen> 3 </since_tizen>
204         public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
205         {
206             Rotation ret = new Rotation(Interop.Rotation.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         /// <summary>
212         /// This version of slerp, used by squad, does not check for theta > 90.
213         /// </summary>
214         /// <param name="q1">The start rotation.</param>
215         /// <param name="q2">The end rotation.</param>
216         /// <param name="t">A progress value between 0 and 1.</param>
217         /// <returns>The interpolated rotation.</returns>
218         /// <since_tizen> 3 </since_tizen>
219         public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
220         {
221             Rotation ret = new Rotation(Interop.Rotation.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             return ret;
224         }
225
226         /// <summary>
227         /// The spherical cubic interpolation.
228         /// </summary>
229         /// <param name="start">The start rotation.</param>
230         /// <param name="end">The end rotation.</param>
231         /// <param name="ctrl1">The control rotation for q1.</param>
232         /// <param name="ctrl2">The control rotation for q2.</param>
233         /// <param name="t">A progress value between 0 and 1.</param>
234         /// <returns>The interpolated rotation.</returns>
235         /// <since_tizen> 3 </since_tizen>
236         public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
237         {
238             Rotation ret = new Rotation(Interop.Rotation.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
239             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240             return ret;
241         }
242
243         /// <summary>
244         /// Returns the shortest angle between two rotations in radians.
245         /// </summary>
246         /// <param name="q1">The first rotation.</param>
247         /// <param name="q2">The second rotation.</param>
248         /// <returns>The angle between the two rotation.</returns>
249         /// <since_tizen> 3 </since_tizen>
250         public static float AngleBetween(Rotation q1, Rotation q2)
251         {
252             float ret = Interop.Rotation.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             return ret;
255         }
256
257         /// <summary>
258         /// Helper to check if this is an identity quaternion.
259         /// </summary>
260         /// <returns>True if this is identity quaternion.</returns>
261         /// <since_tizen> 3 </since_tizen>
262         public bool IsIdentity()
263         {
264             bool ret = Interop.Rotation.Rotation_IsIdentity(swigCPtr);
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266             return ret;
267         }
268
269         /// <summary>
270         /// Converts the quaternion to an axis or angle pair.
271         /// </summary>
272         /// <param name="axis">The result of an an axis.</param>
273         /// <param name="angle">The result of angle in radians.</param>
274         /// <returns>True if converted correctly.</returns>
275         /// <since_tizen> 3 </since_tizen>
276         public bool GetAxisAngle(Vector3 axis, Radian angle)
277         {
278             bool ret = Interop.Rotation.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         /// <summary>
284         /// Returns the length of the rotation.
285         /// </summary>
286         /// <returns>The length of the rotation.</returns>
287         /// <since_tizen> 3 </since_tizen>
288         public float Length()
289         {
290             float ret = Interop.Rotation.Rotation_Length(swigCPtr);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         /// <summary>
296         /// Returns the squared length of the rotation.
297         /// </summary>
298         /// <returns>The squared length of the rotation.</returns>
299         /// <since_tizen> 3 </since_tizen>
300         public float LengthSquared()
301         {
302             float ret = Interop.Rotation.Rotation_LengthSquared(swigCPtr);
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304             return ret;
305         }
306
307         /// <summary>
308         /// Normalizes this to unit length.
309         /// </summary>
310         /// <since_tizen> 3 </since_tizen>
311         public void Normalize()
312         {
313             Interop.Rotation.Rotation_Normalize(swigCPtr);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315         }
316
317         /// <summary>
318         /// Normalized.
319         /// </summary>
320         /// <returns>A normalized version of this rotation.</returns>
321         /// <since_tizen> 3 </since_tizen>
322         public Rotation Normalized()
323         {
324             Rotation ret = new Rotation(Interop.Rotation.Rotation_Normalized(swigCPtr), true);
325             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326             return ret;
327         }
328
329         /// <summary>
330         /// Conjugates this rotation.
331         /// </summary>
332         /// <since_tizen> 3 </since_tizen>
333         public void Conjugate()
334         {
335             Interop.Rotation.Rotation_Conjugate(swigCPtr);
336             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337         }
338
339         /// <summary>
340         /// Inverts this rotation.
341         /// </summary>
342         /// <since_tizen> 3 </since_tizen>
343         public void Invert()
344         {
345             Interop.Rotation.Rotation_Invert(swigCPtr);
346             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347         }
348
349         /// <summary>
350         /// Performs the logarithm of a rotation.
351         /// </summary>
352         /// <returns>The rotation representing the logarithm.</returns>
353         /// <since_tizen> 3 </since_tizen>
354         public Rotation Log()
355         {
356             Rotation ret = new Rotation(Interop.Rotation.Rotation_Log(swigCPtr), true);
357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358             return ret;
359         }
360
361         /// <summary>
362         /// Performs an exponent.
363         /// </summary>
364         /// <returns>The rotation representing the exponent.</returns>
365         /// <since_tizen> 3 </since_tizen>
366         public Rotation Exp()
367         {
368             Rotation ret = new Rotation(Interop.Rotation.Rotation_Exp(swigCPtr), true);
369             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370             return ret;
371         }
372
373         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
374         {
375             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
376         }
377
378         internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
379         {
380             swigCMemOwn = cMemoryOwn;
381             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
382         }
383
384         /// <summary>
385         /// Dispose.
386         /// </summary>
387         /// <since_tizen> 3 </since_tizen>
388         protected override void Dispose(DisposeTypes type)
389         {
390             if (disposed)
391             {
392                 return;
393             }
394
395             //Release your own unmanaged resources here.
396             //You should not access any managed member here except static instance.
397             //because the execution order of Finalizes is non-deterministic.
398
399             if (swigCPtr.Handle != global::System.IntPtr.Zero)
400             {
401                 if (swigCMemOwn)
402                 {
403                     swigCMemOwn = false;
404                     Interop.Rotation.delete_Rotation(swigCPtr);
405                 }
406                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
407             }
408             base.Dispose(type);
409         }
410
411         private Rotation Add(Rotation other)
412         {
413             Rotation ret = new Rotation(Interop.Rotation.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
414             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415             return ret;
416         }
417
418         private Rotation Subtract(Rotation other)
419         {
420             Rotation ret = new Rotation(Interop.Rotation.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
421             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422             return ret;
423         }
424
425         private Rotation Multiply(Rotation other)
426         {
427             Rotation ret = new Rotation(Interop.Rotation.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
428             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429             return ret;
430         }
431
432         private Vector3 Multiply(Vector3 other)
433         {
434             Vector3 ret = new Vector3(Interop.Rotation.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
435             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436             return ret;
437         }
438
439         private Rotation Divide(Rotation other)
440         {
441             Rotation ret = new Rotation(Interop.Rotation.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443             return ret;
444         }
445
446         private Rotation Multiply(float scale)
447         {
448             Rotation ret = new Rotation(Interop.Rotation.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
449             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450             return ret;
451         }
452
453         private Rotation Divide(float scale)
454         {
455             Rotation ret = new Rotation(Interop.Rotation.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
456             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457             return ret;
458         }
459
460         private Rotation Subtract()
461         {
462             Rotation ret = new Rotation(Interop.Rotation.Rotation_Subtract__SWIG_1(swigCPtr), true);
463             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464             return ret;
465         }
466
467         private Rotation AddAssign(Rotation other)
468         {
469             Rotation ret = new Rotation(Interop.Rotation.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
470             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471             return ret;
472         }
473
474         private Rotation SubtractAssign(Rotation other)
475         {
476             Rotation ret = new Rotation(Interop.Rotation.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
477             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
478             return ret;
479         }
480
481         private Rotation MultiplyAssign(Rotation other)
482         {
483             Rotation ret = new Rotation(Interop.Rotation.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485             return ret;
486         }
487
488         private Rotation MultiplyAssign(float scale)
489         {
490             Rotation ret = new Rotation(Interop.Rotation.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
491             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492             return ret;
493         }
494
495         private Rotation DivideAssign(float scale)
496         {
497             Rotation ret = new Rotation(Interop.Rotation.Rotation_DivideAssign(swigCPtr, scale), false);
498             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
499             return ret;
500         }
501
502         private bool EqualTo(Rotation rhs)
503         {
504             bool ret = Interop.Rotation.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
505             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
506             return ret;
507         }
508
509         private bool NotEqualTo(Rotation rhs)
510         {
511             bool ret = Interop.Rotation.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
512             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513             return ret;
514         }
515     }
516 }