Dali C#: csharp dll initial upload
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size.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 Size
23   {
24     private float width;
25     private float height;
26
27     /**
28      * @brief constructor
29      *
30      * @since 1.0.0
31      * @param [in] a Width value .
32      * @param [in] b Height value.
33      */
34     public Size(float a, float b)
35     {
36       width = a;
37       height = b;
38     }
39     /**
40      * @brief default constructor
41      *
42      * @since 1.0.0
43      */
44     public Size()
45     {
46       width = 0.0f;
47       height = 0.0f;
48     }
49
50     /**
51      * @brief constructor with base class object
52      *
53      * @since 1.0.0
54      * @param [in] o The Vector2 with Width, Height values.
55      */
56     public Size(Vector2 o)
57     {
58       width = o.X;
59       height = o.Y;
60     }
61
62     /**
63      * @brief Copy constructor
64      *
65      * @since 1.0.0
66      * @param [in] o The Size having Width & Y.
67      */
68     public Size(Size a)
69     {
70       width = a.width;
71       height = a.height;
72     }
73
74     ///< name "W", type float (Size Width value)
75     //@since 1.0.0
76     public float W
77     {
78       get { return width; }
79       set { width = value; }
80     }
81
82     ///< name "H", type float (Size Height value)
83     //@since 1.0.0
84     public float H
85     {
86       get { return height; }
87       set { height = value; }
88     }
89
90     public float Width
91     {
92       get { return width; }
93       set { width = value; }
94     }
95
96     public float Height
97     {
98       get { return height; }
99       set { height = value; }
100     }
101
102     /**
103      * @brief operator+
104      *
105      * @since 1.0.0
106      * @param [in] l The Size to add.
107      * @param [in] r The Size to add
108      * @return A reference to this
109      */
110     public static Size operator +(Size l, Size r)
111     {
112       return new Size(l.W + r.W, l.H + r.H);
113     }
114
115     /**
116      * @brief operator-
117      *
118      * @since 1.0.0
119      * @param [in] l The Size to substract.
120      * @param [in] r The Size to substract
121      * @return A reference to this
122      */
123     public static Size operator -(Size l, Size r)
124     {
125       return new Size(l.W - r.W, l.H - r.H);
126     }
127
128     /**
129      * @brief operator*
130      *
131      * @since 1.0.0
132      * @param [in] a The Size to multiply
133      * @param [in] b The constant to multiply of type double.
134      * @return A reference to this
135      */
136     public static Size operator *(Size a, double b)
137     {
138       return new Size((float)(a.W * b), (float)(a.H * b));
139     }
140
141     /**
142      * @brief operator/
143      *
144      * @since 1.0.0
145      * @param [in] a The Size to divide.
146      * @param [in] b The Size to divide
147      * @return float of the size division
148      */
149     public static float operator /(Size a, Size b)
150     {
151       return (float)System.Math.Sqrt((a.W / b.W) * (a.H / b.H));
152     }
153
154     /**
155      * @brief Operator ==
156      *
157      * @since 1.0.0
158      * @param [in] a The Size object to compare.
159      * @param [in] b The Size object to compare.
160      * @return bool, whether Size are equal or not
161      */
162     public static bool operator == (Size a, Size b)
163     {
164       return a.W == b.W && a.H == b.H ;
165     }
166
167     /**
168      * @brief Operator !=
169      *
170      * @since 1.0.0
171      * @param [in] a The Size object to compare.
172      * @param [in] b The Size object to compare.
173      * @return bool, whether Size are equal or not
174      */
175     public static bool operator != (Size a, Size b)
176     {
177       return a.W != b.W || a.H != b.H;
178     }
179
180     /**
181      * @brief GetHashCode
182      *
183      * @since 1.0.0
184      * @return int, hascode of Size
185      */
186     public override int GetHashCode()
187     {
188       return (int)(W + H);
189     }
190
191     /**
192      * @brief Clone
193      *
194      * @since 1.0.0
195      * @return returns a copy of Size object
196      */
197     public Size Clone()
198     {
199       Size copy = new Size(W, H);
200       return copy;
201     }
202
203     // User-defined conversion from Position to Vector2
204     public static implicit operator Vector2(Size size)
205     {
206       return new Vector2(size.width, size.height);
207     }
208
209     public static implicit operator Size(Vector2 vec)
210     {
211       return new Size(vec.X, vec.Y);
212     }
213   }
214
215   public class Size3D
216   {
217     private float width;
218     private float height;
219     private float depth;
220
221     public Size3D(float a, float b, float c)
222     {
223       width = a;
224       height = b;
225       depth = c;
226     }
227
228     public Size3D()
229     {
230       width = 0.0f;
231       height = 0.0f;
232       depth = 0.0f;
233     }
234
235     public Size3D(Vector3 o)
236     {
237       width = o.X;
238       height = o.Y;
239       depth = o.Z;
240     }
241
242     public Size3D(Vector2 o)
243     {
244       width = o.X;
245       height = o.Y;
246       depth = 0.0f;
247     }
248
249     public Size3D(Size3D a)
250     {
251       width = a.width;
252       height = a.height;
253       depth = a.depth;
254     }
255
256     public float W
257     {
258       get { return width; }
259       set { width = value; }
260     }
261
262     public float H
263     {
264       get { return height; }
265       set { height = value; }
266     }
267
268     public float D
269     {
270       get { return depth; }
271       set { depth = value; }
272     }
273
274     public float Width
275     {
276       get { return width; }
277       set { width = value; }
278     }
279
280     public float Height
281     {
282       get { return height; }
283       set { height = value; }
284     }
285
286     public float Depth
287     {
288       get { return depth; }
289       set { depth = value; }
290     }
291
292     public float X
293     {
294       get { return width; }
295       set { width = value; }
296     }
297
298     public float Y
299     {
300       get { return height; }
301       set { height = value; }
302     }
303
304     public float Z
305     {
306       get { return depth; }
307       set { depth = value; }
308     }
309
310     // User-defined conversion from Position to Vector3
311     public static implicit operator Vector3(Size3D size)
312     {
313       return new Vector3(size.width, size.height, size.depth);
314     }
315
316     public static implicit operator Size3D(Vector3 vec)
317     {
318       return new Size3D(vec.X, vec.Y, vec.Z);
319     }
320
321   }
322
323 }