/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
return result;
}
-Vector3 FitKeepAspectRatio( const Vector3& target, const Vector3& source )
-{
- float scale = 0.0f;
-
- if ( fabsf(source.x) > 0.0f )
- {
- scale = target.x / source.x;
- }
-
- if ( fabsf(source.y) > 0.0f )
- {
- if ( scale > Math::MACHINE_EPSILON_1 )
- {
- scale = std::min( scale, target.y / source.y );
- }
- else
- {
- scale = target.y / source.y;
- }
- }
-
- if ( fabsf(source.z) > 0.0f )
- {
- if ( scale > Math::MACHINE_EPSILON_1 )
- {
- scale = std::min( scale, target.z / source.z );
- }
- else
- {
- scale = target.z / source.z;
- }
- }
-
- if ( scale < Math::MACHINE_EPSILON_1 )
- {
- scale = 1.0f;
- }
-
- return Vector3( scale, scale, scale );
-}
-
-Vector3 FillKeepAspectRatio( const Vector3& target, const Vector3& source )
-{
- float scale = 0.0f;
-
- if ( fabsf(source.x) > 0.0f )
- {
- scale = target.x / source.x;
- }
-
- if ( fabsf(source.y) > 0.0f )
- {
- if ( scale > Math::MACHINE_EPSILON_1 )
- {
- scale = std::max( scale, target.y / source.y );
- }
- else
- {
- scale = target.y / source.y;
- }
- }
-
- if ( fabsf(source.z) > 0.0f )
- {
- if ( scale > Math::MACHINE_EPSILON_1 )
- {
- scale = std::max( scale, target.z / source.z );
- }
- else
- {
- scale = target.z / source.z;
- }
- }
-
- if ( scale < Math::MACHINE_EPSILON_1 )
- {
- scale = 1.0f;
- }
-
- return Vector3( scale, scale, scale );
-}
-
-Vector3 FillXYKeepAspectRatio( const Vector3& target, const Vector3& source )
-{
- float scale = 0.0f;
-
- if ( fabsf(source.x) > 0.0f )
- {
- scale = target.x / source.x;
- }
-
- if ( fabsf(source.y) > 0.0f )
- {
- if ( scale > Math::MACHINE_EPSILON_1 )
- {
- scale = std::max( scale, target.y / source.y );
- }
- else
- {
- scale = target.y / source.y;
- }
- }
-
- if ( scale < Math::MACHINE_EPSILON_1 )
- {
- scale = 1.0f;
- }
-
- return Vector3( scale, scale, scale );
-}
-
-Vector3 ShrinkInsideKeepAspectRatio( const Vector3& target, const Vector3& source )
-{
- // calculate source size vs target size to see if we need to shrink
- float widthScale = 1.0f;
- if( target.width < source.width )
- {
- // not enough width, width needs to shrink
- widthScale = target.width / source.width;
- }
- float heightScale = 1.0f;
- if( target.height < source.height )
- {
- // not enough height, height needs to shrink
- heightScale = target.height / source.height;
- }
- float depthScale = 1.0f;
- if( target.depth < source.depth )
- {
- // not enough depth, depth needs to shrink
- depthScale = target.depth / source.depth;
- }
- // use smaller of the scales
- float scale = std::min( std::min( widthScale, heightScale ), depthScale );
-
- // check if we need to scale
- if( scale < 1.0f )
- {
- // scale natural size to fit inside
- return Vector3( scale, scale, scale );
- }
- // there is enough space so use source size
- return Vector3::ONE;
-}
-
} // namespace Dali