+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an ”AS IS” BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file FGrp_CoordinateSystemUtils.cpp
- * @brief This file contains implementation of _CoordinateSystemUtils class
- *
- * This file contains implementation _CoordinateSystemUtils class.
- */
-
-#include <FBaseErrors.h>
-#include "FGrp_CoordinateSystemUtils.h"
-
-using namespace Tizen::Graphics;
-
-namespace Tizen { namespace Graphics {
-
-const float _CoordinateSystemUtils::__floatIntegralEpsilon = 0.01f;
-_CoordinateSystem* _CoordinateSystemUtils::__pCoordinateSystemInstance = null;
-
-_ICoordinateSystemTransformer*
-_CoordinateSystemUtils::GetTransformer(void)
-{
- if (__pCoordinateSystemInstance == null)
- {
- __pCoordinateSystemInstance = _CoordinateSystem::GetInstance();
- SysTryReturn(NID_GRP, __pCoordinateSystemInstance, null, E_SYSTEM, "[E_SYSTEM] Coordinate system instance must not be null.");
- }
-
- _ICoordinateSystemTransformer* pTransform = __pCoordinateSystemInstance->GetTransformer();
- SysTryReturn(NID_GRP, pTransform, null, E_SYSTEM, "[E_SYSTEM] The valid coordinate transformer does not exist.");
-
- return pTransform;
-}
-
-_ICoordinateSystemTransformer*
-_CoordinateSystemUtils::GetInverseTransformer(void)
-{
- if (__pCoordinateSystemInstance == null)
- {
- __pCoordinateSystemInstance = _CoordinateSystem::GetInstance();
- SysTryReturn(NID_GRP, __pCoordinateSystemInstance, null, E_SYSTEM, "[E_SYSTEM] Coordinate system instance must not be null.");
- }
-
- _ICoordinateSystemTransformer* pInverseTransform= __pCoordinateSystemInstance->GetInverseTransformer();
- SysTryReturn(NID_GRP, pInverseTransform, null, E_SYSTEM, "[E_SYSTEM] The valid coordinate inverse transformer does not exist.");
-
- return pInverseTransform;
-}
-
-// Convert To Float
-FloatRectangle
-_CoordinateSystemUtils::ConvertToFloat(const Rectangle& rect)
-{
- return FloatRectangle(rect.x, rect.y, rect.width, rect.height);
-}
-
-FloatRectangle
-_CoordinateSystemUtils::ConvertToFloat(const Point& point, const Dimension& dim)
-{
- return FloatRectangle(point.x, point.y, dim.width, dim.height);
-}
-
-FloatDimension
-_CoordinateSystemUtils::ConvertToFloat(const Dimension& dim)
-{
- return FloatDimension(dim.width, dim.height);
-}
-
-FloatPoint
-_CoordinateSystemUtils::ConvertToFloat(const Point& point)
-{
- return FloatPoint(point.x, point.y);
-}
-
-float
-_CoordinateSystemUtils::ConvertToFloat(int scalar)
-{
- return scalar;
-}
-
-// Convert To Integer
-Rectangle
-_CoordinateSystemUtils::ConvertToInteger(const FloatRectangle& rect)
-{
- return Rectangle(floorf(rect.x + __floatIntegralEpsilon), floorf(rect.y + __floatIntegralEpsilon)
- , floorf(rect.width + __floatIntegralEpsilon), floorf(rect.height + __floatIntegralEpsilon));
-}
-
-Rectangle
-_CoordinateSystemUtils::ConvertToInteger(const FloatPoint& point, const FloatDimension& dim)
-{
- return Rectangle(floorf(point.x + __floatIntegralEpsilon), floorf(point.y + __floatIntegralEpsilon)
- , floorf(dim.width + __floatIntegralEpsilon), floorf(dim.height + __floatIntegralEpsilon));
-}
-
-Dimension
-_CoordinateSystemUtils::ConvertToInteger(const FloatDimension& dim)
-{
- return Dimension(floorf(dim.width + __floatIntegralEpsilon), floorf(dim.height + __floatIntegralEpsilon));
-}
-
-Point
-_CoordinateSystemUtils::ConvertToInteger(const FloatPoint& point)
-{
- return Point(floorf(point.x + __floatIntegralEpsilon), floorf(point.y + __floatIntegralEpsilon));
-}
-
-int
-_CoordinateSystemUtils::ConvertToInteger(float scalar)
-{
- return floorf(scalar + __floatIntegralEpsilon);
-}
-
-// Transform Utilities
-Rectangle
-_CoordinateSystemUtils::Transform(const Rectangle& rect)
-{
- return GetTransformer()->Transform(rect);
-}
-
-FloatRectangle
-_CoordinateSystemUtils::Transform(const FloatRectangle& rect)
-{
- return GetTransformer()->Transform(rect);
-}
-
-Rectangle
-_CoordinateSystemUtils::Transform(const Point& point, const Dimension& dim)
-{
- return GetTransformer()->Transform(Rectangle(point, dim));
-}
-
-FloatRectangle
-_CoordinateSystemUtils::Transform(const FloatPoint& point, const FloatDimension& dim)
-{
- return GetTransformer()->Transform(FloatRectangle(point, dim));
-}
-
-Dimension
-_CoordinateSystemUtils::Transform(const Dimension& dim)
-{
- return GetTransformer()->Transform(dim);
-}
-
-FloatDimension
-_CoordinateSystemUtils::Transform(const FloatDimension& dim)
-{
- return GetTransformer()->Transform(dim);
-}
-
-Point
-_CoordinateSystemUtils::Transform(const Point& point)
-{
- return GetTransformer()->Transform(point);
-}
-
-FloatPoint
-_CoordinateSystemUtils::Transform(const FloatPoint& point)
-{
- return GetTransformer()->Transform(point);
-}
-
-int
-_CoordinateSystemUtils::HorizontalTransform(int scalar)
-{
- return GetTransformer()->TransformHorizontal(scalar);
-}
-
-float
-_CoordinateSystemUtils::HorizontalTransform(float scalar)
-{
- return GetTransformer()->TransformHorizontal(scalar);
-}
-
-int
-_CoordinateSystemUtils::VerticalTransform(int scalar)
-{
- return GetTransformer()->TransformVertical(scalar);
-}
-
-float
-_CoordinateSystemUtils::VerticalTransform(float scalar)
-{
- return GetTransformer()->TransformVertical(scalar);
-}
-
-// InverseTransform Utilities
-Rectangle
-_CoordinateSystemUtils::InverseTransform(const Rectangle& rect)
-{
- return GetInverseTransformer()->Transform(rect);
-}
-
-FloatRectangle
-_CoordinateSystemUtils::InverseTransform(const FloatRectangle& rect)
-{
- return GetInverseTransformer()->Transform(rect);
-}
-
-Rectangle
-_CoordinateSystemUtils::InverseTransform(const Point& point, const Dimension& dim)
-{
- return GetInverseTransformer()->Transform(Rectangle(point, dim));
-}
-
-FloatRectangle
-_CoordinateSystemUtils::InverseTransform(const FloatPoint& point, const FloatDimension& dim)
-{
- return GetInverseTransformer()->Transform(FloatRectangle(point, dim));
-}
-
-Dimension
-_CoordinateSystemUtils::InverseTransform(const Dimension& dim)
-{
- return GetInverseTransformer()->Transform(dim);
-}
-
-FloatDimension
-_CoordinateSystemUtils::InverseTransform(const FloatDimension& dim)
-{
- return GetInverseTransformer()->Transform(dim);
-}
-
-Point
-_CoordinateSystemUtils::InverseTransform(const Point& point)
-{
- return GetInverseTransformer()->Transform(point);
-}
-
-FloatPoint
-_CoordinateSystemUtils::InverseTransform(const FloatPoint& point)
-{
- return GetInverseTransformer()->Transform(point);
-}
-
-int
-_CoordinateSystemUtils::InverseHorizontalTransform(int scalar)
-{
- return GetInverseTransformer()->TransformHorizontal(scalar);
-}
-
-float
-_CoordinateSystemUtils::InverseHorizontalTransform(float scalar)
-{
- return GetInverseTransformer()->TransformHorizontal(scalar);
-}
-
-int
-_CoordinateSystemUtils::InverseVerticalTransform(int scalar)
-{
- return GetInverseTransformer()->TransformVertical(scalar);
-}
-
-float
-_CoordinateSystemUtils::InverseVerticalTransform(float scalar)
-{
- return GetInverseTransformer()->TransformVertical(scalar);
-}
-}} // Tizen::Graphics
#ifndef _FGRP_INTERNAL_COORDINATE_SYSTEM_UTILS_H_
#define _FGRP_INTERNAL_COORDINATE_SYSTEM_UTILS_H_
+#include <math.h>
+#include <unique_ptr.h>
#include <FBaseSysLog.h>
+#include <FBaseErrors.h>
+#include <FBase_StringConverter.h>
#include <FGrpFloatRectangle.h>
#include <FGrpFloatPoint.h>
#include <FGrpFloatDimension.h>
+#include <FOspConfig.h>
#include <FGrp_CoordinateSystem.h>
-#include <math.h>
namespace Tizen { namespace Graphics {
{
public:
// Convert To Float
- static Tizen::Graphics::FloatRectangle ConvertToFloat(const Tizen::Graphics::Rectangle& rect);
- static Tizen::Graphics::FloatRectangle ConvertToFloat(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatDimension ConvertToFloat(const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatPoint ConvertToFloat(const Tizen::Graphics::Point& point);
- static float ConvertToFloat(int scalar);
+ static Tizen::Graphics::FloatRectangle
+ ConvertToFloat(const Tizen::Graphics::Rectangle& rect)
+ {
+ return Tizen::Graphics::FloatRectangle(rect.x, rect.y, rect.width, rect.height);
+ }
+
+ static Tizen::Graphics::FloatRectangle
+ ConvertToFloat(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim)
+ {
+ return Tizen::Graphics::FloatRectangle(point.x, point.y, dim.width, dim.height);
+ }
+
+ static Tizen::Graphics::FloatDimension
+ ConvertToFloat(const Tizen::Graphics::Dimension& dim)
+ {
+ return Tizen::Graphics::FloatDimension(dim.width, dim.height);
+ }
+
+ static Tizen::Graphics::FloatPoint
+ ConvertToFloat(const Tizen::Graphics::Point& point)
+ {
+ return Tizen::Graphics::FloatPoint(point.x, point.y);
+ }
+
+ static float
+ ConvertToFloat(const Tizen::Base::String& floatString)
+ {
+ if (floatString.IsEmpty() == true)
+ {
+ return 0.0f;
+ }
+ float integerPart = 0.0f;
+ float decimalPart = 0.0f;
+ float multiple = 1.0f;
+ float sign = 1.0f;
+ int index = 0;
+ bool isDecimal = false;
+
+ if (floatString[index] == L'-')
+ {
+ sign = -1.0f;
+ index ++;
+ }
+ else if (floatString[index] == L'+')
+ {
+ sign = 1.0f;
+ index ++;
+ }
+
+ while (index < floatString.GetLength())
+ {
+ if (floatString[index] == L'.')
+ {
+ isDecimal = true;
+ }
+ else if (floatString[index] >= L'0' && floatString[index] <= L'9')
+ {
+ if (isDecimal)
+ {
+ decimalPart = (decimalPart * 10.0f) + (floatString[index] - L'0');
+ multiple = 0.1f * multiple;
+ }
+ else
+ {
+ integerPart = (integerPart * 10.0f) + (floatString[index] - L'0');
+ }
+ }
+ index ++;
+ }
+ decimalPart = decimalPart * multiple;
+
+ return sign * (integerPart + decimalPart);
+ }
+
+ static float
+ ConvertToFloat(int scalar)
+ {
+ return scalar;
+ }
// Convert To Integer
- static Tizen::Graphics::Rectangle ConvertToInteger(const Tizen::Graphics::FloatRectangle& rect);
- static Tizen::Graphics::Rectangle ConvertToInteger(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Dimension ConvertToInteger(const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Point ConvertToInteger(const Tizen::Graphics::FloatPoint& point);
- static int ConvertToInteger(float scalar);
+ static Tizen::Graphics::Rectangle
+ ConvertToInteger(const Tizen::Graphics::FloatRectangle& rect)
+ {
+ return Tizen::Graphics::Rectangle(floorf(rect.x + __floatIntegralEpsilon), floorf(rect.y + __floatIntegralEpsilon)
+ , floorf(rect.width + __floatIntegralEpsilon), floorf(rect.height + __floatIntegralEpsilon));
+ }
+
+ static Tizen::Graphics::Rectangle
+ ConvertToInteger(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim)
+ {
+ return Tizen::Graphics::Rectangle(floorf(point.x + __floatIntegralEpsilon), floorf(point.y + __floatIntegralEpsilon)
+ , floorf(dim.width + __floatIntegralEpsilon), floorf(dim.height + __floatIntegralEpsilon));
+ }
+
+ static Tizen::Graphics::Dimension
+ ConvertToInteger(const Tizen::Graphics::FloatDimension& dim)
+ {
+ return Tizen::Graphics::Dimension(floorf(dim.width + __floatIntegralEpsilon), floorf(dim.height + __floatIntegralEpsilon));
+ }
+
+ static Tizen::Graphics::Point
+ ConvertToInteger(const Tizen::Graphics::FloatPoint& point)
+ {
+ return Tizen::Graphics::Point(floorf(point.x + __floatIntegralEpsilon), floorf(point.y + __floatIntegralEpsilon));
+ }
+
+ static int
+ ConvertToInteger(float scalar)
+ {
+ return floorf(scalar + __floatIntegralEpsilon);
+ }
// Transform Utilities
- static Tizen::Graphics::Rectangle Transform(const Tizen::Graphics::Rectangle& rect);
- static Tizen::Graphics::FloatRectangle Transform(const Tizen::Graphics::FloatRectangle& rect);
- static Tizen::Graphics::Rectangle Transform(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatRectangle Transform(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Dimension Transform(const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatDimension Transform(const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Point Transform(const Tizen::Graphics::Point& point);
- static Tizen::Graphics::FloatPoint Transform(const Tizen::Graphics::FloatPoint& point);
- static int HorizontalTransform(int scalar);
- static float HorizontalTransform(float scalar);
- static int VerticalTransform(int scalar);
- static float VerticalTransform(float scalar);
-
- // Inverse Transform Utilities
- static Tizen::Graphics::Rectangle InverseTransform(const Tizen::Graphics::Rectangle& rect);
- static Tizen::Graphics::FloatRectangle InverseTransform(const Tizen::Graphics::FloatRectangle& rect);
- static Tizen::Graphics::Rectangle InverseTransform(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatRectangle InverseTransform(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Dimension InverseTransform(const Tizen::Graphics::Dimension& dim);
- static Tizen::Graphics::FloatDimension InverseTransform(const Tizen::Graphics::FloatDimension& dim);
- static Tizen::Graphics::Point InverseTransform(const Tizen::Graphics::Point& point);
- static Tizen::Graphics::FloatPoint InverseTransform(const Tizen::Graphics::FloatPoint& point);
- static int InverseHorizontalTransform(int scalar);
- static float InverseHorizontalTransform(float scalar);
- static int InverseVerticalTransform(int scalar);
- static float InverseVerticalTransform(float scalar);
+ static Tizen::Graphics::Rectangle
+ Transform(const Tizen::Graphics::Rectangle& rect)
+ {
+ return GetTransformer()->Transform(rect);
+ }
+
+ static Tizen::Graphics::FloatRectangle
+ Transform(const Tizen::Graphics::FloatRectangle& rect)
+ {
+ return GetTransformer()->Transform(rect);
+ }
+
+ static Tizen::Graphics::Rectangle
+ Transform(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim)
+ {
+ return GetTransformer()->Transform(Tizen::Graphics::Rectangle(point, dim));
+ }
+
+ static Tizen::Graphics::FloatRectangle
+ Transform(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim)
+ {
+ return GetTransformer()->Transform(Tizen::Graphics::FloatRectangle(point, dim));
+ }
+
+ static Tizen::Graphics::Dimension
+ Transform(const Tizen::Graphics::Dimension& dim)
+ {
+ return GetTransformer()->Transform(dim);
+ }
+
+ static Tizen::Graphics::FloatDimension
+ Transform(const Tizen::Graphics::FloatDimension& dim)
+ {
+ return GetTransformer()->Transform(dim);
+ }
+
+ static Tizen::Graphics::Point
+ Transform(const Tizen::Graphics::Point& point)
+ {
+ return GetTransformer()->Transform(point);
+ }
+
+ static Tizen::Graphics::FloatPoint
+ Transform(const Tizen::Graphics::FloatPoint& point)
+ {
+ return GetTransformer()->Transform(point);
+ }
+
+ static int
+ HorizontalTransform(int scalar)
+ {
+ return GetTransformer()->TransformHorizontal(scalar);
+ }
+
+ static float
+ HorizontalTransform(float scalar)
+ {
+ return GetTransformer()->TransformHorizontal(scalar);
+ }
+
+ static int
+ VerticalTransform(int scalar)
+ {
+ return GetTransformer()->TransformVertical(scalar);
+ }
+
+ static float
+ VerticalTransform(float scalar)
+ {
+ return GetTransformer()->TransformVertical(scalar);
+ }
+
+ // InverseTransform Utilities
+ static Tizen::Graphics::Rectangle
+ InverseTransform(const Tizen::Graphics::Rectangle& rect)
+ {
+ return GetInverseTransformer()->Transform(rect);
+ }
+
+ static Tizen::Graphics::FloatRectangle
+ InverseTransform(const Tizen::Graphics::FloatRectangle& rect)
+ {
+ return GetInverseTransformer()->Transform(rect);
+ }
+
+ static Tizen::Graphics::Rectangle
+ InverseTransform(const Tizen::Graphics::Point& point, const Tizen::Graphics::Dimension& dim)
+ {
+ return GetInverseTransformer()->Transform(Tizen::Graphics::Rectangle(point, dim));
+ }
+
+ static Tizen::Graphics::FloatRectangle
+ InverseTransform(const Tizen::Graphics::FloatPoint& point, const Tizen::Graphics::FloatDimension& dim)
+ {
+ return GetInverseTransformer()->Transform(Tizen::Graphics::FloatRectangle(point, dim));
+ }
+
+ static Tizen::Graphics::Dimension
+ InverseTransform(const Tizen::Graphics::Dimension& dim)
+ {
+ return GetInverseTransformer()->Transform(dim);
+ }
+
+ static Tizen::Graphics::FloatDimension
+ InverseTransform(const Tizen::Graphics::FloatDimension& dim)
+ {
+ return GetInverseTransformer()->Transform(dim);
+ }
+
+ static Tizen::Graphics::Point
+ InverseTransform(const Tizen::Graphics::Point& point)
+ {
+ return GetInverseTransformer()->Transform(point);
+ }
+
+ static Tizen::Graphics::FloatPoint
+ InverseTransform(const Tizen::Graphics::FloatPoint& point)
+ {
+ return GetInverseTransformer()->Transform(point);
+ }
+
+ static int
+ InverseHorizontalTransform(int scalar)
+ {
+ return GetInverseTransformer()->TransformHorizontal(scalar);
+ }
+
+ static float
+ InverseHorizontalTransform(float scalar)
+ {
+ return GetInverseTransformer()->TransformHorizontal(scalar);
+ }
+
+ static int
+ InverseVerticalTransform(int scalar)
+ {
+ return GetInverseTransformer()->TransformVertical(scalar);
+ }
+
+ static float
+ InverseVerticalTransform(float scalar)
+ {
+ return GetInverseTransformer()->TransformVertical(scalar);
+ }
private:
_CoordinateSystemUtils(void);
_CoordinateSystemUtils(const _CoordinateSystemUtils&);
_CoordinateSystemUtils& operator =(const _CoordinateSystemUtils&);
- static Tizen::Graphics::_ICoordinateSystemTransformer* GetTransformer(void);
- static Tizen::Graphics::_ICoordinateSystemTransformer* GetInverseTransformer(void);
+ static Tizen::Graphics::_ICoordinateSystemTransformer*
+ GetTransformer(void)
+ {
+ Tizen::Graphics::_ICoordinateSystemTransformer* pTransform = Tizen::Graphics::_CoordinateSystem::GetInstance()->GetTransformer();
+ SysTryReturn(NID_GRP, pTransform, null, E_SYSTEM, "[E_SYSTEM] The valid coordinate transformer does not exist.");
+
+ return pTransform;
+ }
+
+ static Tizen::Graphics::_ICoordinateSystemTransformer*
+ GetInverseTransformer(void)
+ {
+ Tizen::Graphics::_ICoordinateSystemTransformer* pInverseTransform= Tizen::Graphics::_CoordinateSystem::GetInstance()->GetInverseTransformer();
+ SysTryReturn(NID_GRP, pInverseTransform, null, E_SYSTEM, "[E_SYSTEM] The valid coordinate inverse transformer does not exist.");
+
+ return pInverseTransform;
+ }
private:
// WARNING:
// Some float functions like sin and cos emit too-much float-error.
// So, the rounding const must be a bigger value than expected.
- static const float __floatIntegralEpsilon;
- static Tizen::Graphics::_CoordinateSystem* __pCoordinateSystemInstance;
-
+ static const float __floatIntegralEpsilon = 0.01f;
}; //class _CoordinateSystemUtils
}} // Tizen::Graphics