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.
17 using System.ComponentModel;
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 [Binding.TypeConverter(typeof(RelativeVector2TypeConverter))]
28 public class RelativeVector2 : Disposable
34 /// <since_tizen> 3 </since_tizen>
35 public RelativeVector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
58 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 internal RelativeVector2(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
78 /// <since_tizen> 3 </since_tizen>
83 Interop.Vector2.Vector2_X_set(swigCPtr, ValueCheck(value));
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// <since_tizen> 3 </since_tizen>
102 Interop.Vector2.Vector2_Y_set(swigCPtr, ValueCheck(value));
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RelativeVector2 obj)
115 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
119 /// The addition operator.
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)
127 RelativeVector2 result = arg1.Add(arg2);
128 return ValueCheck(result);
132 /// The subtraction operator.
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)
140 RelativeVector2 result = arg1.Subtract(arg2);
141 return ValueCheck(result);
145 /// The multiplication operator.
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)
153 RelativeVector2 result = arg1.Multiply(arg2);
154 return ValueCheck(result);
158 /// The multiplication operator.
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)
166 RelativeVector2 result = arg1.Multiply(arg2);
167 return ValueCheck(result);
171 /// The division operator.
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)
179 RelativeVector2 result = arg1.Divide(arg2);
180 return ValueCheck(result);
184 /// The division operator.
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)
192 RelativeVector2 result = arg1.Divide(arg2);
193 return ValueCheck(result);
198 /// <since_tizen> 3 </since_tizen>
199 public static implicit operator Vector2(RelativeVector2 relativeVector2)
201 return new Vector2(relativeVector2.X, relativeVector2.Y);
206 /// <since_tizen> 3 </since_tizen>
207 public static implicit operator RelativeVector2(Vector2 vec)
209 return new RelativeVector2(ValueCheck(vec.X), ValueCheck(vec.Y));
213 /// The const array subscript operator overload. Should be 0, 1.
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]
222 return ValueOfIndex(index);
227 /// Determines whether the specified object is equal to the current object.
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)
233 RelativeVector2 relativeRector2 = obj as RelativeVector2;
235 if (X == relativeRector2?.X && Y == relativeRector2?.Y)
243 /// Gets the the hash code of this RelativeVector2.
245 /// <returns>The Hash Code.</returns>
246 /// <since_tizen> 6 </since_tizen>
247 public override int GetHashCode()
249 return swigCPtr.Handle.GetHashCode();
253 /// Compares if the rhs is equal to.
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)
260 bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Compares if the rhs is not equal to.
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)
273 bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, RelativeVector2.getCPtr(rhs));
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 internal static RelativeVector2 GetRelativeVector2FromPtr(global::System.IntPtr cPtr)
282 RelativeVector2 ret = new RelativeVector2(cPtr, false);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 internal static RelativeVector2 ValueCheck(RelativeVector2 relativeVector2)
289 if (relativeVector2.X < 0.0f)
291 relativeVector2.X = 0.0f;
292 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
294 else if (relativeVector2.X > 1.0f)
296 relativeVector2.X = 1.0f;
297 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
299 if (relativeVector2.Y < 0.0f)
301 relativeVector2.Y = 0.0f;
302 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
304 else if (relativeVector2.Y > 1.0f)
306 relativeVector2.Y = 1.0f;
307 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
309 return relativeVector2;
312 internal static float ValueCheck(float value)
317 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
319 else if (value > 1.0f)
322 NUILog.Error("The value of Parameters is invalid! Should be between [0, 1].");
327 /// This will not be public opened.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
331 Interop.Vector2.delete_Vector2(swigCPtr);
334 private RelativeVector2 Add(RelativeVector2 rhs)
336 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Add(swigCPtr, RelativeVector2.getCPtr(rhs)), true);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 private RelativeVector2 Subtract(RelativeVector2 rhs)
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();
348 private RelativeVector2 Multiply(RelativeVector2 rhs)
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();
355 private RelativeVector2 Multiply(float rhs)
357 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 private RelativeVector2 Divide(RelativeVector2 rhs)
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();
369 private RelativeVector2 Divide(float rhs)
371 RelativeVector2 ret = new RelativeVector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 private float ValueOfIndex(uint index)
378 float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();