f89172a7ffe0eb4b91ab93f38e7e35ad4d1486f3
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / manual / csharp / Size.cs
1 namespace Dali
2 {
3   using System;
4
5   public class Size
6   {
7     private float width;
8     private float height;
9
10     /**
11      * @brief constructor
12      *
13      * @since 1.0.0
14      * @param [in] a Width value .
15      * @param [in] b Height value.
16      */
17     public Size(float a, float b)
18     {
19       width = a;
20       height = b;
21     }
22     /**
23      * @brief default constructor
24      *
25      * @since 1.0.0
26      */
27     public Size()
28     {
29       width = 0.0f;
30       height = 0.0f;
31     }
32
33     /**
34      * @brief constructor with base class object
35      *
36      * @since 1.0.0
37      * @param [in] o The Vector2 with Width, Height values.
38      */
39     public Size(Vector2 o)
40     {
41       width = o.x;
42       height = o.y;
43     }
44
45     /**
46      * @brief Copy constructor
47      *
48      * @since 1.0.0
49      * @param [in] o The Size having Width & Y.
50      */
51     public Size(Size a)
52     {
53       width = a.width;
54       height = a.height;
55     }
56
57     ///< name "W", type float (Size Width value)
58     //@since 1.0.0
59     public float W
60     {
61       get { return width; }
62       set { width = value; }
63     }
64
65     ///< name "H", type float (Size Height value)
66     //@since 1.0.0
67     public float H
68     {
69       get { return height; }
70       set { height = value; }
71     }
72
73     /**
74      * @brief operator+
75      *
76      * @since 1.0.0
77      * @param [in] l The Size to add.
78      * @param [in] r The Size to add
79      * @return A reference to this
80      */
81     public static Size operator +(Size l, Size r)
82     {
83       return new Size(l.W + r.W, l.H + r.H);
84     }
85
86     /**
87      * @brief operator-
88      *
89      * @since 1.0.0
90      * @param [in] l The Size to substract.
91      * @param [in] r The Size to substract
92      * @return A reference to this
93      */
94     public static Size operator -(Size l, Size r)
95     {
96       return new Size(l.W - r.W, l.H - r.H);
97     }
98
99     /**
100      * @brief operator*
101      *
102      * @since 1.0.0
103      * @param [in] a The Size to multiply
104      * @param [in] b The constant to multiply of type double.
105      * @return A reference to this
106      */
107     public static Size operator *(Size a, double b)
108     {
109       return new Size((float)(a.W * b), (float)(a.H * b));
110     }
111
112     /**
113      * @brief operator/
114      *
115      * @since 1.0.0
116      * @param [in] a The Size to divide.
117      * @param [in] b The Size to divide
118      * @return float of the size division
119      */
120     public static float operator /(Size a, Size b)
121     {
122       return (float)System.Math.Sqrt((a.W / b.W) * (a.H / b.H));
123     }
124
125     /**
126      * @brief Operator ==
127      *
128      * @since 1.0.0
129      * @param [in] a The Size object to compare.
130      * @param [in] b The Size object to compare.
131      * @return bool, whether Size are equal or not
132      */
133     public static bool operator == (Size a, Size b)
134     {
135       return a.W == b.W && a.H == b.H ;
136     }
137
138     /**
139      * @brief Operator !=
140      *
141      * @since 1.0.0
142      * @param [in] a The Size object to compare.
143      * @param [in] b The Size object to compare.
144      * @return bool, whether Size are equal or not
145      */
146     public static bool operator != (Size a, Size b)
147     {
148       return a.W != b.W || a.H != b.H;
149     }
150
151     /**
152      * @brief GetHashCode
153      *
154      * @since 1.0.0
155      * @return int, hascode of Size
156      */
157     public override int GetHashCode()
158     {
159       return (int)(W + H);
160     }
161
162     /**
163      * @brief Clone
164      *
165      * @since 1.0.0
166      * @return returns a copy of Size object
167      */
168     public Size Clone()
169     {
170       Size copy = new Size(W, H);
171       return copy;
172     }
173
174     // User-defined conversion from Position to Vector3
175     public static implicit operator Vector2(Size size)
176     {
177       return new Vector2(size.width, size.height);
178     }
179
180     public static implicit operator Size(Vector2 vec)
181     {
182       return new Size(vec.x, vec.y);
183     }
184   }
185 }