2 * Copyright (c) 2017 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.
22 /// Position2D is a two-dimensional vector.
24 public class Position2D : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27 protected bool swigCMemOwn;
29 internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
31 swigCMemOwn = cMemoryOwn;
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 //A Flag to check who called Dispose(). (By User or DisposeQueue)
41 private bool isDisposeQueued = false;
42 //A Flat to check if it is already disposed.
43 protected bool disposed = false;
49 isDisposeQueued = true;
50 DisposeQueue.Instance.Add(this);
56 //Throw excpetion if Dispose() is called in separate thread.
57 if (!Window.IsInstalled())
59 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
64 Dispose(DisposeTypes.Implicit);
68 Dispose(DisposeTypes.Explicit);
69 System.GC.SuppressFinalize(this);
73 protected virtual void Dispose(DisposeTypes type)
80 if (type == DisposeTypes.Explicit)
83 //Release your own managed resources here.
84 //You should release all of your own disposable objects here.
87 //Release your own unmanaged resources here.
88 //You should not access any managed member here except static instance.
89 //because the execution order of Finalizes is non-deterministic.
91 if (swigCPtr.Handle != global::System.IntPtr.Zero)
96 NDalicPINVOKE.delete_Vector2(swigCPtr);
98 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
104 /// The addition operator.
106 /// <param name="arg1">The vector to add.</param>
107 /// <param name="arg2">The vector to add.</param>
108 /// <returns>The vector containing the result of the addition.</returns>
109 public static Position2D operator +(Position2D arg1, Position2D arg2)
111 return arg1.Add(arg2);
115 /// The subtraction operator.
117 /// <param name="arg1">The vector to subtract.</param>
118 /// <param name="arg2">The vector to subtract.</param>
119 /// <returns>The vector containing the result of the subtraction.</returns>
120 public static Position2D operator -(Position2D arg1, Position2D arg2)
122 return arg1.Subtract(arg2);
126 /// The unary negation operator.
128 /// <param name="arg1">The vector to negate.</param>
129 /// <returns>The vector containing the negation.</returns>
130 public static Position2D operator -(Position2D arg1)
132 return arg1.Subtract();
136 /// The multiplication operator.
138 /// <param name="arg1">The vector to multiply.</param>
139 /// <param name="arg2">The vector to multiply.</param>
140 /// <returns>The vector containing the result of the multiplication.</returns>
141 public static Position2D operator *(Position2D arg1, Position2D arg2)
143 return arg1.Multiply(arg2);
147 /// The multiplication operator.
149 /// <param name="arg1">The vector to multiply.</param>
150 /// <param name="arg2">The integer value to scale the vector.</param>
151 /// <returns>The vector containing the result of the multiplication.</returns>
152 public static Position2D operator *(Position2D arg1, int arg2)
154 return arg1.Multiply(arg2);
158 /// The division operator.
160 /// <param name="arg1">The vector to divide.</param>
161 /// <param name="arg2">The vector to divide.</param>
162 /// <returns>The vector containing the result of the division.</returns>
163 public static Position2D operator /(Position2D arg1, Position2D arg2)
165 return arg1.Divide(arg2);
169 /// The division operator.
171 /// <param name="arg1">The vector to divide.</param>
172 /// <param name="arg2">The integer value to scale the vector by.</param>
173 /// <returns>The vector containing the result of the division.</returns>
174 public static Position2D operator /(Position2D arg1, int arg2)
176 return arg1.Divide(arg2);
180 /// The const array subscript operator overload. Should be 0, or 1.
182 /// <param name="index">The subscript index.</param>
183 /// <returns>The float at the given index.</returns>
184 public float this[uint index]
188 return ValueOfIndex(index);
192 internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
194 Position2D ret = new Position2D(cPtr, false);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210 /// <param name="x">x component</param>
211 /// <param name="y">y component</param>
212 public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 /// <param name="position">Position to create this vector from</param>
221 public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 private Position2D Add(Position2D rhs)
228 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 private Position2D Subtract(Position2D rhs)
235 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 private Position2D Multiply(Position2D rhs)
243 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 private Position2D Multiply(int rhs)
250 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 private Position2D Divide(Position2D rhs)
258 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 private Position2D Divide(int rhs)
265 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 private Position2D Subtract()
272 Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 /// Compares if the rhs is equal to.
280 /// <param name="rhs">The vector to compare</param>
281 /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
282 public bool EqualTo(Position2D rhs)
284 bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 /// Compares if the rhs is not equal to.
292 /// <param name="rhs">The vector to compare.</param>
293 /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
294 public bool NotEqualTo(Position2D rhs)
296 bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 private int ValueOfIndex(uint index)
303 int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 /// Converts a Position2D instance to a Vector2 instance.
347 public static implicit operator Vector2(Position2D position2d)
349 return new Vector2((float)position2d.X, (float)position2d.Y);
353 /// Converts a Vector2 instance to a Position2D instance.
355 public static implicit operator Position2D(Vector2 vec)
357 return new Position2D((int)vec.X, (int)vec.Y);
361 /// Converts a Position2D instance to a Uint16Pair instance.
363 public static implicit operator Uint16Pair(Position2D position2d)
365 return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
369 /// Converts a Uint16Pair instance to a Position2D instance.
371 public static implicit operator Position2D(Uint16Pair pair)
373 return new Position2D((int)pair.GetX(), (int)pair.GetY());