summaryrefslogtreecommitdiff
path: root/Tizen.NUI/src/public/RelativeVector4.cs
blob: 4ab36717a2d99b48b7bcbb38971fe68e2f1204e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 using System;

namespace Tizen.NUI
{

    /// <summary>
    /// RelativeVector4 is a four dimensional vector.
    /// All values(x, y, and z) should be between [0, 1].
    /// </summary>
    public class RelativeVector4 : global::System.IDisposable
    {
        private global::System.Runtime.InteropServices.HandleRef swigCPtr;
        protected bool swigCMemOwn;

        internal RelativeVector4(global::System.IntPtr cPtr, bool cMemoryOwn)
        {
            swigCMemOwn = cMemoryOwn;
            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
        }

        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector4 obj)
        {
            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
        }

        //A Flag to check who called Dispose(). (By User or DisposeQueue)
        private bool isDisposeQueued = false;
        //A Flat to check if it is already disposed.
        protected bool disposed = false;

        ~RelativeVector4()
        {
            if(!isDisposeQueued)
            {
                isDisposeQueued = true;
                DisposeQueue.Instance.Add(this);
            }
        }

        public void Dispose()
        {
            //Throw excpetion if Dispose() is called in separate thread.
            if (!Window.IsInstalled())
            {
                throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
            }

            if (isDisposeQueued)
            {
                Dispose(DisposeTypes.Implicit);
            }
            else
            {
                Dispose(DisposeTypes.Explicit);
                System.GC.SuppressFinalize(this);
            }
        }

        protected virtual void Dispose(DisposeTypes type)
        {
            if (disposed)
            {
                return;
            }

            if(type == DisposeTypes.Explicit)
            {
                //Called by User
                //Release your own managed resources here.
                //You should release all of your own disposable objects here.
            }

            //Release your own unmanaged resources here.
            //You should not access any managed member here except static instance.
            //because the execution order of Finalizes is non-deterministic.

            if (swigCPtr.Handle != global::System.IntPtr.Zero)
            {
                if (swigCMemOwn)
                {
                    swigCMemOwn = false;
                    NDalicPINVOKE.delete_Vector4(swigCPtr);
                }
                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
            }
            disposed = true;
        }


        /// <summary>
        /// Addition operator.
        /// </summary>
        /// <param name="arg1">Vector to add</param>
        /// <param name="arg2">Vector to add</param>
        /// <returns>A vector containing the result of the addition</returns>
        public static RelativeVector4 operator +(RelativeVector4 arg1, RelativeVector4 arg2)
        {
            RelativeVector4 result = arg1.Add(arg2);
            ValueCheck(result);
            return result;
        }

        /// <summary>
        /// Subtraction operator.
        /// </summary>
        /// <param name="arg1">Vector to subtract</param>
        /// <param name="arg2">Vector to subtract</param>
        /// <returns>A vector containing the result of the subtraction</returns>
        public static RelativeVector4 operator -(RelativeVector4 arg1, RelativeVector4 arg2)
        {
            RelativeVector4 result = arg1.Subtract(arg2);
            ValueCheck(result);
            return result;
        }

        /// <summary>
        /// Multiplication operator.
        /// </summary>
        /// <param name="arg1">The vector to multiply</param>
        /// <param name="arg2">The vector to multiply</param>
        /// <returns>A vector containing the result of the multiplication</returns>
        public static RelativeVector4 operator *(RelativeVector4 arg1, RelativeVector4 arg2)
        {
            RelativeVector4 result = arg1.Multiply(arg2);
            ValueCheck(result);
            return result;
        }

        /// <summary>
        /// Multiplication operator.
        /// </summary>
        /// <param name="arg1">The vector to multiply</param>
        /// <param name="arg2">The float value to scale the vector</param>
        /// <returns>A vector containing the result of the scaling</returns>
        public static RelativeVector4 operator *(RelativeVector4 arg1, float arg2)
        {
            RelativeVector4 result = arg1.Multiply(arg2);
            ValueCheck(result);
            return result;
        }

        /// <summary>
        /// Division operator.
        /// </summary>
        /// <param name="arg1">The vector to divide</param>
        /// <param name="arg2">The vector to divide</param>
        /// <returns>A vector containing the result of the division</returns>
        public static RelativeVector4 operator /(RelativeVector4 arg1, RelativeVector4 arg2)
        {
            RelativeVector4 result = arg1.Divide(arg2);
            ValueCheck(result);
            return result;
        }

        /// <summary>
        /// Division operator.
        /// </summary>
        /// <param name="arg1">The vector to divide</param>
        /// <param name="arg2">The float value to scale the vector by</param>
        /// <returns>A vector containing the result of the scaling</returns>
        public static RelativeVector4 operator /(RelativeVector4 arg1, float arg2)
        {
            RelativeVector4 result = arg1.Divide(arg2);
            ValueCheck(result);
            return result;
        }


        /// <summary>
        /// Const array subscript operator overload. Should be 0, 1 3 or 3.
        /// </summary>
        /// <param name="index">Subscript index</param>
        /// <returns>The float at the given index</returns>
        public float this[uint index]
        {
            get
            {
                return ValueOfIndex(index);
            }
        }

        /// <summary>
        /// </summary>
        internal static RelativeVector4 GetRelativeVector4FromPtr(global::System.IntPtr cPtr)
        {
            RelativeVector4 ret = new RelativeVector4(cPtr, false);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }


        /// <summary>
        /// Constructor
        /// </summary>
        public RelativeVector4() : this(NDalicPINVOKE.new_Vector4__SWIG_0(), true)
        {
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="x">x component</param>
        /// <param name="y">y component</param>
        /// <param name="z">z component</param>
        /// <param name="w">w component</param>
        public RelativeVector4(float x, float y, float z, float w) : this(NDalicPINVOKE.new_Vector4__SWIG_1(x, y, z, w), true)
        {
            ValueCheck(x);
            ValueCheck(y);
            ValueCheck(z);
            ValueCheck(W);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="relativeVector2">RelativeVector2 to create this vector from</param>
        public RelativeVector4(RelativeVector2 relativeVector2) : this(NDalicPINVOKE.new_Vector4__SWIG_3(RelativeVector2.getCPtr(relativeVector2)), true)
        {
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="relativeVector3">RelativeVector3 to create this vector from</param>
        public RelativeVector4(RelativeVector3 relativeVector3) : this(NDalicPINVOKE.new_Vector4__SWIG_4(RelativeVector3.getCPtr(relativeVector3)), true)
        {
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
        }

        private RelativeVector4 Add(RelativeVector4 rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Add(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private RelativeVector4 Subtract(RelativeVector4 rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Subtract__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private RelativeVector4 Multiply(RelativeVector4 rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private RelativeVector4 Multiply(float rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Multiply__SWIG_1(swigCPtr, rhs), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private RelativeVector4 Divide(RelativeVector4 rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_0(swigCPtr, RelativeVector4.getCPtr(rhs)), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private RelativeVector4 Divide(float rhs)
        {
            RelativeVector4 ret = new RelativeVector4(NDalicPINVOKE.Vector4_Divide__SWIG_1(swigCPtr, rhs), true);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        private float ValueOfIndex(uint index)
        {
            float ret = NDalicPINVOKE.Vector4_ValueOfIndex__SWIG_0(swigCPtr, index);
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        /// <summary>
        /// Compare if rhs is equal to
        /// </summary>
        /// <param name="rhs">The vector to compare</param>
        /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
        public bool EqualTo(RelativeVector4 rhs)
        {
            bool ret = NDalicPINVOKE.Vector4_EqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }

        /// <summary>
        /// Compare if rhs is not equal to
        /// </summary>
        /// <param name="rhs">The vector to compare</param>
        /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
        public bool NotEqualTo(RelativeVector4 rhs)
        {
            bool ret = NDalicPINVOKE.Vector4_NotEqualTo(swigCPtr, RelativeVector4.getCPtr(rhs));
            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            return ret;
        }


        /// <summary>
        /// x component
        /// </summary>
        public float X
        {
            set
            {
                ValueCheck(value);
                NDalicPINVOKE.Vector4_X_set(swigCPtr, value);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            get
            {
                float ret = NDalicPINVOKE.Vector4_X_get(swigCPtr);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                return ret;
            }
        }

        /// <summary>
        /// y component
        /// </summary>
        public float Y
        {
            set
            {
                ValueCheck(value);
                NDalicPINVOKE.Vector4_Y_set(swigCPtr, value);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            get
            {
                float ret = NDalicPINVOKE.Vector4_Y_get(swigCPtr);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                return ret;
            }
        }

        /// <summary>
        /// z component
        /// </summary>
        public float Z
        {
            set
            {
                ValueCheck(value);
                NDalicPINVOKE.Vector4_Z_set(swigCPtr, value);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            get
            {
                float ret = NDalicPINVOKE.Vector4_Z_get(swigCPtr);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                return ret;
            }
        }

        /// <summary>
        /// w component
        /// </summary>
        public float W
        {
            set
            {
                ValueCheck(value);
                NDalicPINVOKE.Vector4_W_set(swigCPtr, value);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            get
            {
                float ret = NDalicPINVOKE.Vector4_W_get(swigCPtr);
                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                return ret;
            }
        }

        /// <summary>
        /// </summary>
        public static implicit operator Vector4(RelativeVector4 relativeVector4)
        {
            return new Vector4(relativeVector4.X, relativeVector4.Y, relativeVector4.Z, relativeVector4.W);
        }

        /// <summary>
        /// </summary>
        public static implicit operator RelativeVector4(Vector4 vec)
        {
            ValueCheck(vec.X);
            ValueCheck(vec.Y);
            ValueCheck(vec.Z);
            ValueCheck(vec.W);
            return new RelativeVector4(vec.X, vec.Y, vec.Z, vec.W);
        }

        internal static void ValueCheck(RelativeVector4 relativeVector4)
        {
            if(relativeVector4.X < 0.0f)
            {
                relativeVector4.X = 0.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            else if(relativeVector4.X > 1.0f)
            {
                relativeVector4.X = 1.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            if(relativeVector4.Y < 0.0f)
            {
                relativeVector4.Y = 0.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            else if(relativeVector4.Y > 1.0f)
            {
                relativeVector4.Y = 1.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            if(relativeVector4.Z < 0.0f)
            {
                relativeVector4.Z = 0.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            else if(relativeVector4.Z > 1.0f)
            {
                relativeVector4.Z = 1.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            if(relativeVector4.W < 0.0f)
            {
                relativeVector4.W = 0.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
            else if(relativeVector4.W > 1.0f)
            {
                relativeVector4.W = 1.0f;
                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
            }
        }

        internal static void ValueCheck(float value)
        {
            if(value < 0.0f)
            {
                value = 0.0f;
                Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
            }
            else if(value > 1.0f)
            {
                value = 1.0f;
                Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
            }
        }

    }

}