2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.Binding;
23 /// RelativeVector2 is a two-dimensional vector.
24 /// Both values (x and y) should be between [0, 1].
26 /// <since_tizen> 3 </since_tizen>
27 [TypeConverter(typeof(RelativeVector2TypeConverter))]
28 public class RelativeVector2 : Disposable
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
36 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
41 /// <since_tizen> 3 </since_tizen>
42 public RelativeVector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50 /// <param name="x">The x component.</param>
51 /// <param name="y">The y component.</param>
52 /// <since_tizen> 3 </since_tizen>
53 public RelativeVector2(float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(ValueCheck(x), ValueCheck(y)), true)
55 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61 /// <param name="relativeVector3">The RelativeVector3 to create this vector from.</param>
62 /// <since_tizen> 3 </since_tizen>
63 public RelativeVector2(RelativeVector3 relativeVector3) : this(Interop.Vector2.new_Vector2__SWIG_3(RelativeVector3.getCPtr(relativeVector3)), true)
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 /// <param name="relativeVector4">The RelativeVector4 to create this vector from.</param>
72 /// <since_tizen> 3 </since_tizen>
73 public RelativeVector2(RelativeVector4 relativeVector4) : this(Interop.Vector2.new_Vector2__SWIG_4(RelativeVector4.getCPtr(relativeVector4)), true)
75 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn)
80 swigCMemOwn = cMemoryOwn;
81 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
87 /// <since_tizen> 3 </since_tizen>
92 Interop.Vector2.Vector2_X_set(swigCPtr, ValueCheck(value));
93 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106 /// <since_tizen> 3 </since_tizen>
111 Interop.Vector2.Vector2_Y_set(swigCPtr, ValueCheck(value));
112 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
124 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
128 /// The addition operator.
130 /// <param name="arg1">The vector to add.</param>
131 /// <param name="arg2">The vector to add.</param>
132 /// <returns>The vector containing the result of the addition.</returns>
133 /// <since_tizen> 3 </since_tizen>
134 public static RelativeVector2 operator +(RelativeVector2 arg1, RelativeVector2 arg2)
136 RelativeVector2 result = arg1.Add(arg2);
137 return ValueCheck(result);
141 /// The subtraction operator.
143 /// <param name="arg1">The vector to subtract.</param>
144 /// <param name="arg2">The vector to subtract.</param>
145 /// <returns>The vector containing the result of the subtraction.</returns>
146 /// <since_tizen> 3 </since_tizen>
147 public static RelativeVector2 operator -(RelativeVector2 arg1, RelativeVector2 arg2)
149 RelativeVector2 result = arg1.Subtract(arg2);
150 return ValueCheck(result);
154 /// The multiplication operator.
156 /// <param name="arg1">The vector to multiply.</param>
157 /// <param name="arg2">The vector to multiply.</param>
158 /// <returns>The vector containing the result of the multiplication.</returns>
159 /// <since_tizen> 3 </since_tizen>
160 public static RelativeVector2 operator *(RelativeVector2 arg1, RelativeVector2 arg2)
162 RelativeVector2 result = arg1.Multiply(arg2);
163 return ValueCheck(result);
167 /// The multiplication operator.
169 /// <param name="arg1">The vector to multiply.</param>
170 /// <param name="arg2">The float value to scale the vector.</param>
171 /// <returns>The vector containing the result of the scaling.</returns>
172 /// <since_tizen> 3 </since_tizen>
173 public static RelativeVector2 operator *(RelativeVector2 arg1, float arg2)
175 RelativeVector2 result = arg1.Multiply(arg2);
176 return ValueCheck(result);
180 /// The division operator.
182 /// <param name="arg1">The vector to divide.</param>
183 /// <param name="arg2">The vector to divide.</param>
184 /// <returns>The vector containing the result of the division.</returns>
185 /// <since_tizen> 3 </since_tizen>
186 public static RelativeVector2 operator /(RelativeVector2 arg1, RelativeVector2 arg2)
188 RelativeVector2 result = arg1.Divide(arg2);
189 return ValueCheck(result);
193 /// The division operator.
195 /// <param name="arg1">The vector to divide.</param>
196 /// <param name="arg2">The float value to scale the vector by.</param>
197 /// <returns>The vector containing the result of the scaling.</returns>
198 /// <since_tizen> 3 </since_tizen>
199 public static RelativeVector2 operator /(RelativeVector2 arg1, float arg2)
201 RelativeVector2 result = arg1.Divide(arg2);
202 return ValueCheck(result);
207 /// <since_tizen> 3 </since_tizen>
208 public static implicit operator Vector2(RelativeVector2 relativeVector2)
210 return new Vector2(relativeVector2.X, relativeVector2.Y);
215 /// <since_tizen> 3 </since_tizen>
216 public static implicit operator RelativeVector2(Vector2 vec)
218 return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
222 /// The const array subscript operator overload. Should be 0, 1.
224 /// <param name="index">The subscript index.</param>
225 /// <returns>The float at the given index.</returns>
226 /// <since_tizen> 3 </since_tizen>
227 public float this[uint index]
231 return ValueOfIndex(index);
236 /// Determines whether the specified object is equal to the current object.
238 /// <param name="obj">The object to compare with the current object.</param>
239 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
240 public override bool Equals(System.Object obj)
242 RelativeVector2 relativeRector2 = obj as RelativeVector2;
244 if (X == relativeRector2?.X && Y == relativeRector2?.Y)
252 /// Gets the the hash code of this RelativeVector2.
254 /// <returns>The Hash Code.</returns>
255 /// <since_tizen> 6 </since_tizen>
256 public override int GetHashCode()
258 return swigCPtr.Handle.GetHashCode();
262 /// Compares if the rhs is equal to.
264 /// <param name="rhs">The vector to compare.</param>
265 /// <returns>Returns true if the two vectors are equal, otherwise false.</returns>
266 /// <since_tizen> 3 </since_tizen>
267 public bool EqualTo(RelativeVector2 rhs)
269 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 /// Compares if the rhs is not equal to.
277 /// <param name="rhs">The vector to compare.</param>
278 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
279 /// <since_tizen> 3 </since_tizen>
280 public bool NotEqualTo(RelativeVector2 rhs)
282 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
291 RelativeVector2 ret = new RelativeVector2(cPtr, false);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
298 if (relativeVector2.X < 0.0f)
300 relativeVector2.X = 0.0f;
301 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
303 else if (relativeVector2.X > 1.0f)
305 relativeVector2.X = 1.0f;
306 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
308 if (relativeVector2.Y < 0.0f)
310 relativeVector2.Y = 0.0f;
311 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
313 else if (relativeVector2.Y > 1.0f)
315 relativeVector2.Y = 1.0f;
316 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
318 return relativeVector2;
321 internal static float ValueCheck(float value)
326 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
328 else if (value > 1.0f)
331 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
339 /// <since_tizen> 3 </since_tizen>
340 protected override void Dispose(DisposeTypes type)
347 //Release your own unmanaged resources here.
348 //You should not access any managed member here except static instance.
349 //because the execution order of Finalizes is non-deterministic.
351 if (swigCPtr.Handle != global::System.IntPtr.Zero)
356 Interop.Vector2.delete_Vector2(swigCPtr);
358 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
363 private RelativeVector2 Add(RelativeVector2 rhs)
365 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 private RelativeVector2 Subtract(RelativeVector2 rhs)
372 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 private RelativeVector2 Multiply(RelativeVector2 rhs)
379 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 private RelativeVector2 Multiply(float rhs)
386 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 private RelativeVector2 Divide(RelativeVector2 rhs)
393 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 private RelativeVector2 Divide(float rhs)
400 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 private float ValueOfIndex(uint index)
407 float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();