906abbbff228ae194e1907742893087f8212bbd6
[platform/core/uifw/dali-csharp-binder.git] / Tizen.NUI / src / public / Position.cs
1 /*
2  * Copyright (c) 2016 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
18 namespace NUI
19 {
20   using System;
21
22   public class Position
23   {
24
25     private float x;
26     private float y;
27     private float z;
28
29     /**
30      * @brief constructor
31      *
32      * @since 1.0.0
33      */
34     public Position()
35     {
36       x = 0.0f;
37       y = 0.0f;
38       z = 0.0f;
39     }
40
41     /**
42      * @brief constructor
43      *
44      * @since 1.0.0
45      * @param [in] a The Position X.
46      * @param [in] b The Position Y.
47      * @param [in] c The Position Z.
48      */
49     public Position(float a, float b, float c)
50     {
51       x = a;
52       y = b;
53       z = c;
54     }
55
56     /**
57      * @brief constructor
58      *
59      * @since 1.0.0
60      * @param [in] o The Vector Position X, Y, Z.
61      */
62     public Position(Vector3 o)
63     {
64       x = o.X;
65       y = o.Y;
66       z = o.Z;
67     }
68
69     ///< name "X", type float (Position X value)
70     //@since 1.0.0
71     public float X
72     {
73       get { return x; }
74       set { x = value; }
75     }
76
77     ///< name "Y", type float (Position Y value)
78     //@since 1.0.0
79     public float Y
80     {
81       get { return y; }
82       set { y = value; }
83     }
84
85     ///< name "Z", type float (Position Z value)
86     //@since 1.0.0
87     public float Z
88     {
89       get { return z; }
90       set { z = value; }
91     }
92
93     /**
94      * @brief operator+
95      *
96      * @since 1.0.0
97      * @param [in] l The Position to add.
98      * @param [in] r The Position to add
99      * @return A reference to this
100      */
101     public static Position operator +(Position l, Position r)
102     {
103       return new Position(l.X + r.X, l.Y + r.Y, l.Z + r.Z);
104     }
105
106     /**
107      * @brief operator-
108      *
109      * @since 1.0.0
110      * @param [in] l The Position to substract.
111      * @param [in] r The Position to substract
112      * @return A reference to this
113      */
114     public static Position operator -(Position l, Position r)
115     {
116       return new Position(l.X - r.X, l.Y - r.Y, l.Z - r.Z);
117     }
118
119     /**
120      * @brief operator*
121      *
122      * @since 1.0.0
123      * @param [in] a The Position to multiply.
124      * @param [in] b The constant to multiply of type double.
125      * @return A reference to this
126      */
127     public static Position operator *(Position a, double b)
128     {
129       return new Position((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b));
130     }
131
132     /**
133      * @brief operator/
134      *
135      * @since 1.0.0
136      * @param [in] a The Position to divide.
137      * @param [in] b The Position to divide
138      * @return float value of division operation
139      */
140     public static float operator /(Position a, Position b)
141     {
142       return (float)System.Math.Sqrt((a.X / b.X) * (a.Y / b.Y) * (a.Z / b.Z));
143     }
144
145     /**
146      * @brief Operator ==
147      *
148      * @since 1.0.0
149      * @param [in] a The Position object to compare.
150      * @param [in] b The Position object to compare.
151      * @return bool, whether Position are equal or not
152      */
153     public static bool operator == (Position a, Position b)
154     {
155       return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
156     }
157
158     /**
159      * @brief Operator !=
160      *
161      * @since 1.0.0
162      * @param [in] a The Position object to compare.
163      * @param [in] b The Position object to compare.
164      * @return bool, whether Position are equal or not
165      */
166     public static bool operator != (Position a, Position b)
167     {
168       return a.X != b.X || a.Y != b.Y || a.Z == b.Z;
169     }
170
171     /**
172      * @brief GetHashCode
173      *
174      * @since 1.0.0
175      * @return int, hascode of position
176      */
177     public override int GetHashCode()
178     {
179       return base.GetHashCode();
180     }
181
182     /**
183      * @brief Clone
184      *
185      * @since 1.0.0
186      * @return Position object
187      */
188     public Position Clone()
189     {
190       Position copy = new Position(X, Y, Z);
191       return copy;
192     }
193
194     // User-defined conversion from Position to Vector3
195     public static implicit operator Vector3(Position pos)
196     {
197       return new Vector3(pos.x, pos.y, pos.z);
198     }
199
200     public static implicit operator Position(Vector3 vec)
201     {
202       return new Position(vec.X, vec.Y, vec.Z);
203     }
204   }
205 }