-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * 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.
+ * 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.
+ *
+ */
// CLASS HEADER
#include <dali/public-api/math/vector3.h>
// EXTERNAL INCLUDES
#include <math.h>
+#include <ostream>
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
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