Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpFloatDimension.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        FGrpFloatDimension.cpp
20  * @brief       This is the implementation file for FloatDimension class.
21  *
22  * This file contains implementation of Point class.
23  *
24  */
25
26 #include <FGrpFloatDimension.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 FloatDimension::FloatDimension(void)
47         : width(0.0f)
48         , height(0.0f)
49         , __pImpl(null)
50 {
51 }
52
53 FloatDimension::FloatDimension(const FloatDimension& rhs)
54         : width(rhs.width)
55         , height(rhs.height)
56         , __pImpl(null)
57 {
58 }
59
60 FloatDimension::FloatDimension(float width_, float height_)
61         : width(width_)
62         , height(height_)
63         , __pImpl(null)
64 {
65 }
66
67 FloatDimension::~FloatDimension(void)
68 {
69 }
70
71 FloatDimension&
72 FloatDimension::operator=(const FloatDimension& rhs)
73 {
74         if (this == &rhs)
75         {
76                 return *this;
77         }
78
79         this->width = rhs.width;
80         this->height = rhs.height;
81         this->__pImpl = null;
82
83         return *this;
84 }
85
86 bool
87 FloatDimension::operator ==(const FloatDimension& rhs) const
88 {
89         return ((_IsEqual(this->width, rhs.width) && _IsEqual(this->height, rhs.height)) ? true : false);
90 }
91
92 bool
93 FloatDimension::operator !=(const FloatDimension& rhs) const
94 {
95         return (!operator ==(rhs));
96 }
97
98 bool
99 FloatDimension::Equals(const Tizen::Base::Object& rhs) const
100 {
101         if (&rhs == null)
102         {
103                 return false;
104         }
105
106         const FloatDimension* pDim = dynamic_cast <const FloatDimension*>(&rhs);
107
108         if (pDim == null)
109         {
110                 return false;
111         }
112
113         return (*this == *pDim);
114 }
115
116 int
117 FloatDimension::GetHashCode(void) const
118 {
119         const float inverseEpsilon = 1.0f / _EPSILON;
120
121         int reinterpretedX = int(this->width * inverseEpsilon);
122         int reinterpretedY = int(this->height * inverseEpsilon);
123
124         return reinterpretedX ^ (reinterpretedY * 31);
125 }
126
127 void
128 FloatDimension::SetSize(float width, float height)
129 {
130         this->width = width;
131         this->height = height;
132 }
133
134 }} // Tizen::Graphics