2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FGrpFloatRectangle.cpp
20 * @brief This is the implementation file for FloatRectangle class.
22 * This file contains implementation of FloatRectangle class.
26 #include <FGrpFloatRectangle.h>
27 #include <FGrpFloatPoint.h>
28 #include <FGrpFloatDimension.h>
30 #include <FBaseSysLog.h>
32 #include "util/FGrp_Util.h"
38 const float _EMPTY = -1.0f;
40 // epsilon is assumed to be 0.00001f, not 1.192092896e-07f
41 const float _EPSILON = 0.00001f;
44 _IsEqual(float f1, float f2)
46 return (((f1 > f2) ? f1 - f2 : f2 - f1) < _EPSILON);
51 namespace Tizen { namespace Graphics
54 FloatRectangle::FloatRectangle()
63 FloatRectangle::FloatRectangle(const FloatRectangle& rhs)
72 FloatRectangle::FloatRectangle(float x_, float y_, float width_, float height_)
81 FloatRectangle::FloatRectangle(const FloatPoint& pt, const FloatDimension& dim)
90 FloatRectangle::~FloatRectangle()
95 FloatRectangle::operator=(const FloatRectangle& rhs)
104 this->width = rhs.width;
105 this->height = rhs.height;
106 this->__pImpl = null;
111 FloatRectangle::operator ==(const FloatRectangle& rhs) const
113 return ((_IsEqual(this->x, rhs.x) && _IsEqual(this->y, rhs.y) && _IsEqual(this->width, rhs.width) && _IsEqual(this->height, rhs.height)) ? true : false);
117 FloatRectangle::operator !=(const FloatRectangle& rhs) const
119 return (!operator ==(rhs));
123 FloatRectangle::Contains(const FloatPoint& point) const
130 if (this->x <= point.x && point.x < (this->x + this->width) &&
131 this->y <= point.y && point.y < (this->y + this->height))
140 FloatRectangle::Equals(const Tizen::Base::Object& rhs) const
147 const FloatRectangle* pRect = dynamic_cast <const FloatRectangle*>(&rhs);
154 return (*this == *pRect);
158 FloatRectangle::GetHashCode(void) const
160 int intX = int(this->x);
161 int intY = int(this->y);
162 int intWidth = int(this->width);
163 int intHeight = int(this->height);
165 return ((intX & 0xFF) << 24) | ((intY & 0xFF) << 16) | ((intWidth & 0xFF) << 8) | (intHeight & 0xFF);
169 FloatRectangle::GetIntersection(const FloatRectangle& rect) const
171 FloatRectangle rectResult(0.0f, 0.0f, _EMPTY, _EMPTY);
178 _Util::Rectangle<float> out;
179 _Util::Rectangle<float> src1;
180 _Util::Rectangle<float> src2;
184 src1.w = this->width;
185 src1.h = this->height;
190 src2.h = rect.height;
192 if (!_Util::IntersectRect(out, src1, src2))
208 rectResult.SetBounds(out.x, out.y, out.w, out.h);
214 FloatRectangle::IsIntersected(const FloatRectangle& rect) const
221 _Util::Rectangle<float> out;
222 _Util::Rectangle<float> src1;
223 _Util::Rectangle<float> src2;
227 src1.w = this->width;
228 src1.h = this->height;
233 src2.h = rect.height;
235 return _Util::IntersectRect(out, src1, src2);
239 FloatRectangle::GetUnion(const FloatRectangle& rect) const
241 FloatRectangle rectResult(0.0f, 0.0f, _EMPTY, _EMPTY);
248 rectResult.x = _Util::Min(this->x, rect.x);
249 rectResult.y = _Util::Min(this->y, rect.y);
250 rectResult.width = _Util::Max((this->x + this->width), (rect.x + rect.width));
251 rectResult.width -= rectResult.x;
252 rectResult.height = _Util::Max((this->y + this->height), (rect.y + rect.height));
253 rectResult.height -= rectResult.y;
259 FloatRectangle::GetBottomRight(void) const
261 return FloatPoint(this->x + this->width, this->y + this->height);
265 FloatRectangle::GetTopLeft(void) const
267 return FloatPoint(this->x, this->y);
271 FloatRectangle::SetBounds(float x, float y, float width, float height)
276 this->height = height;
280 FloatRectangle::SetBounds(const FloatPoint& pt, const FloatDimension& dim)
284 this->width = dim.width;
285 this->height = dim.height;
289 FloatRectangle::IsEmpty() const
291 if (this->width <= 0.0f || this->height <= 0.0f)
300 FloatRectangle::SetSize(const FloatDimension& dim)
302 this->width = dim.width;
303 this->height = dim.height;
307 FloatRectangle::SetSize(float width, float height)
310 this->height = height;
314 FloatRectangle::SetPosition(const FloatPoint& point)
321 FloatRectangle::SetPosition(float x, float y)
328 FloatRectangle::Translate(float x, float y)
334 }} // Tizen::Graphics