Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpFloatPoint.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrpFloatPoint.cpp
20  * @brief       This is the implementation file for FloatPoint class.
21  *
22  * This file contains implementation of FloatPoint class.
23  *
24  */
25
26 #include <FGrpFloatPoint.h>
27
28
29 namespace // unnamed
30 {
31
32 // epsilon is assumed to be 0.00001f, not 1.192092896e-07f
33 const float _EPSILON = 0.00001f;
34
35 inline bool
36 _IsEqual(float f1, float f2)
37 {
38         return (((f1 > f2) ? f1 - f2 : f2 - f1) < _EPSILON);
39 }
40
41 }
42
43 namespace Tizen { namespace Graphics
44 {
45
46 FloatPoint::FloatPoint(void)
47         : x(0.0f)
48         , y(0.0f)
49         , __pImpl(null)
50 {
51 }
52
53 FloatPoint::FloatPoint(const FloatPoint& rhs)
54         : x(rhs.x)
55         , y(rhs.y)
56         , __pImpl(null)
57 {
58 }
59
60 FloatPoint::FloatPoint(float x_, float y_)
61         : x(x_)
62         , y(y_)
63         , __pImpl(null)
64 {
65 }
66
67 FloatPoint::~FloatPoint(void)
68 {
69 }
70
71 FloatPoint&
72 FloatPoint::operator=(const FloatPoint& rhs)
73 {
74         if (this == &rhs)
75         {
76                 return *this;
77         }
78
79         this->x = rhs.x;
80         this->y = rhs.y;
81         this->__pImpl = null;
82
83         return *this;
84 }
85
86 bool
87 FloatPoint::operator ==(const FloatPoint& rhs) const
88 {
89         return ((_IsEqual(this->x, rhs.x) && _IsEqual(this->y, rhs.y)) ? true : false);
90 }
91
92 bool
93 FloatPoint::operator !=(const FloatPoint& rhs) const
94 {
95         return (!operator ==(rhs));
96 }
97
98 FloatPoint
99 FloatPoint::operator +(const FloatPoint& rhs) const
100 {
101         FloatPoint point;
102
103         point.x = this->x + rhs.x;
104         point.y = this->y + rhs.y;
105
106         return point;
107 }
108
109 FloatPoint
110 FloatPoint::operator -(const FloatPoint& rhs) const
111 {
112         FloatPoint point;
113
114         point.x = this->x - rhs.x;
115         point.y = this->y - rhs.y;
116
117         return point;
118 }
119
120 FloatPoint&
121 FloatPoint::operator +=(const FloatPoint& point)
122 {
123         this->x += point.x;
124         this->y += point.y;
125
126         return *this;
127 }
128
129 FloatPoint&
130 FloatPoint::operator -=(const FloatPoint& point)
131 {
132         this->x -= point.x;
133         this->y -= point.y;
134
135         return *this;
136 }
137
138 bool
139 FloatPoint::Equals(const Object& rhs) const
140 {
141         const FloatPoint* pPoint = dynamic_cast <const FloatPoint*>(&rhs);
142
143         if (pPoint == null)
144         {
145                 return false;
146         }
147
148         return (*this == *pPoint);
149 }
150
151 int
152 FloatPoint::GetHashCode(void) const
153 {
154         const float inverseEpsilon = 1.0f / _EPSILON;
155
156         int reinterpretedX = int(this->x * inverseEpsilon);
157         int reinterpretedY = int(this->y * inverseEpsilon);
158
159         return reinterpretedX ^ (reinterpretedY * 31);
160 }
161
162 void
163 FloatPoint::SetPosition(float x, float y)
164 {
165         this->x = x;
166         this->y = y;
167 }
168
169 void
170 FloatPoint::SetPosition(const FloatPoint& point)
171 {
172         this->x = point.x;
173         this->y = point.y;
174 }
175
176 void
177 FloatPoint::Translate(float x, float y)
178 {
179         this->x += x;
180         this->y += y;
181 }
182
183 }} // Tizen::Graphics