Remove unused & unnecessary fitting functions from Vector2 & Vector3 27/42527/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 29 Jun 2015 13:56:53 +0000 (14:56 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 29 Jun 2015 13:56:53 +0000 (14:56 +0100)
Change-Id: Ia12b4da6f718f2fabca942fa5a51a987093d84df

automated-tests/src/dali/utc-Dali-Vector2.cpp
automated-tests/src/dali/utc-Dali-Vector3.cpp
dali/public-api/math/vector2.cpp
dali/public-api/math/vector2.h
dali/public-api/math/vector3.cpp
dali/public-api/math/vector3.h

index 2a9bf4c..822a6ae 100644 (file)
@@ -607,77 +607,3 @@ int UtcDaliVector2ClampP(void)
   END_TEST;
 }
 
-int UtcDaliVector2FitInsideP(void)
-{
-  TestApplication application;
-  DALI_TEST_EQUALS( Vector2(  1.0f,  2.0f ), FitInside( Vector2(   1.0f,  2.0f ), Vector2( 10.0f, 20.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  1.0f,  0.5f ), FitInside( Vector2(   1.0f,  2.0f ), Vector2( 20.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f, 20.0f ), FitInside( Vector2(  10.0f, 20.0f ), Vector2(  1.0f,  2.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f, 10.0f ), FitInside( Vector2( 100.0f, 10.0f ), Vector2( 10.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 20.0f, 10.0f ), FitInside( Vector2(  20.0f, 20.0f ), Vector2( 10.0f,  5.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f, 20.0f ), FitInside( Vector2(  20.0f, 20.0f ), Vector2(  5.0f, 10.0f ) ), TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector2FitInside01N(void)
-{
-  TestApplication application;
-  Size size = FitInside( Vector2(   1.0f,  2.0f ), Vector2( 0.0f, 0.0f ) );
-  DALI_TEST_EQUALS( false, std::isfinite(size.y), TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector2FitScaleToFillP(void)
-{
-  TestApplication application;
-  DALI_TEST_EQUALS( Vector2(  1.0f,  2.0f ), FitScaleToFill( Vector2(   1.0f,  2.0f ), Vector2( 10.0f, 20.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  1.0f,  2.0f ), FitScaleToFill( Vector2(  10.0f, 20.0f ), Vector2(  1.0f,  2.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f,  1.0f ), FitScaleToFill( Vector2( 100.0f, 10.0f ), Vector2( 10.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  5.0f,  5.0f ), FitScaleToFill( Vector2(  20.0f, 20.0f ), Vector2( 10.0f,  5.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  5.0f,  5.0f ), FitScaleToFill( Vector2(  20.0f, 20.0f ), Vector2(  5.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 20.0f, 40.0f ), FitScaleToFill( Vector2(  20.0f,  0.0f ), Vector2(  5.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f, 20.0f ), FitScaleToFill( Vector2(   0.0f, 20.0f ), Vector2(  5.0f, 10.0f ) ), TEST_LOCATION );
-  END_TEST;
-}
-
-
-int UtcDaliVector2FitScaleToFillN(void)
-{
-  TestApplication application;
-  Vector2 target(0.f, 0.f);
-  Size size = FitScaleToFill( target, Vector2( 0.0f, 0.0f ) );
-  DALI_TEST_EQUALS( size, target, TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector2ShrinkInsideP(void)
-{
-  TestApplication application;
-  DALI_TEST_EQUALS( Vector2(  1.0f,  2.0f ), ShrinkInside( Vector2(   1.0f,  2.0f ), Vector2( 10.0f, 20.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  1.0f,  2.0f ), ShrinkInside( Vector2(  10.0f, 20.0f ), Vector2(  1.0f,  2.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f, 10.0f ), ShrinkInside( Vector2( 100.0f, 10.0f ), Vector2( 10.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f,  5.0f ), ShrinkInside( Vector2(  20.0f, 20.0f ), Vector2( 10.0f,  5.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  5.0f, 10.0f ), ShrinkInside( Vector2(  20.0f, 20.0f ), Vector2(  5.0f, 10.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2(  5.0f, 10.0f ), ShrinkInside( Vector2(  10.0f, 10.0f ), Vector2( 10.0f, 20.0f ) ), TEST_LOCATION );
-  DALI_TEST_EQUALS( Vector2( 10.0f,  5.0f ), ShrinkInside( Vector2(  10.0f, 10.0f ), Vector2( 20.0f, 10.0f ) ), TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector2ShrinkInside01N(void)
-{
-  TestApplication application;
-  Vector2 target(0.f, 0.f);
-  Size size = ShrinkInside( Vector2( -1.0f,  1.0f ), Vector2( 0.0f, 1.0f ) );
-  DALI_TEST_EQUALS( false, std::isfinite(size.x), TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector2ShrinkInside02N(void)
-{
-  TestApplication application;
-  Vector2 target(0.f, 0.f);
-  Size size = ShrinkInside( Vector2( -1.0f,  -1.0f ), Vector2( 1.0f, 0.0f ) );
-  DALI_TEST_EQUALS( false, std::isfinite(size.y), TEST_LOCATION );
-  END_TEST;
-}
-
index e954277..f96a7b2 100644 (file)
@@ -637,76 +637,6 @@ int UtcDaliVector3ClampP(void)
   END_TEST;
 }
 
-int UtcDaliVector3FitKeepAspectRatioP(void)
-{
-  TestApplication application;
-  Vector3 target(10.0f, 20.0f, 30.0f);
-  Vector3 source1(1.0f, 2.0f, 3.0f);
-  Vector3 source2(1.0f, 1.0f, 1.0f);
-
-  DALI_TEST_EQUALS( FitKeepAspectRatio( target, target ), Vector3(1.0f, 1.0f, 1.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FitKeepAspectRatio( target, source1 ), Vector3(10.0f, 10.0f, 10.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FitKeepAspectRatio( target, source2 ), Vector3(10.0f, 10.0f, 10.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FitKeepAspectRatio( source2, target ), Vector3(0.0333f, 0.0333f, 0.0333f), 0.001, TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector3FillKeepAspectRatioP(void)
-{
-  TestApplication application;
-  Vector3 target(10.0f, 20.0f, 30.0f);
-  Vector3 source1(1.0f, 2.0f, 3.0f);
-  Vector3 source2(1.0f, 1.0f, 1.0f);
-
-  DALI_TEST_EQUALS( FillKeepAspectRatio( target, target ), Vector3(1.0f, 1.0f, 1.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillKeepAspectRatio( target, source1 ), Vector3(10.0f, 10.0f, 10.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillKeepAspectRatio( target, source2 ), Vector3(30.0f, 30.0f, 30.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillKeepAspectRatio( source2, target ), Vector3(0.1f, 0.1f, 0.1f), 0.001, TEST_LOCATION );
-
-  END_TEST;
-}
-
-int UtcDaliVector3FillXYKeepAspectRatioP(void)
-{
-  TestApplication application;
-  Vector3 target(10.0f, 20.0f, 30.0f);
-  Vector3 source1(1.0f, 2.0f, 3.0f);
-  Vector3 source2(1.0f, 1.0f, 1.0f);
-
-  DALI_TEST_EQUALS( FillXYKeepAspectRatio( target, target ), Vector3(1.0f, 1.0f, 1.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillXYKeepAspectRatio( target, source1 ), Vector3(10.0f, 10.0f, 10.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillXYKeepAspectRatio( target, source2 ), Vector3(20.0f, 20.0f, 20.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( FillXYKeepAspectRatio( source2, target ), Vector3(0.1f, 0.1f, 0.1f), 0.001, TEST_LOCATION );
-
-  END_TEST;
-}
-
-int UtcDaliVector3ShrinkInsideKeepAspectRatioP(void)
-{
-  TestApplication application;
-  Vector3 target(1.0f, 2.0f, 3.0f);
-  Vector3 source1(10.0f, 20.0f, 30.0f);
-  Vector3 source2(10.0f, 10.0f, 10.0f);
-
-  DALI_TEST_EQUALS( ShrinkInsideKeepAspectRatio( target, target ), Vector3(1.0f, 1.0f, 1.0f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( ShrinkInsideKeepAspectRatio( target, source1 ), Vector3(0.1f, 0.1f, 0.1f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( ShrinkInsideKeepAspectRatio( target, source2 ), Vector3(0.1f, 0.1f, 0.1f), 0.001, TEST_LOCATION );
-  DALI_TEST_EQUALS( ShrinkInsideKeepAspectRatio( source2, target ), Vector3::ONE, 0.001, TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliVector3ShrinkInsideKeepAspectRatioN(void)
-{
-  TestApplication application;
-  Vector3 target(-1.0f, -1.0f, -1.0f);
-  Vector3 source(0.0f, 0.0f, 0.0f);
-
-  Vector3 shrink = ShrinkInsideKeepAspectRatio( target, source );
-
-  DALI_TEST_EQUALS( false, std::isfinite(shrink.y), TEST_LOCATION );
-  END_TEST;
-}
-
 int UtcDaliVector3ConstantsP(void)
 {
   TestApplication application;
index 88394aa..6e4b07a 100644 (file)
@@ -123,86 +123,4 @@ Vector2 Clamp( const Vector2& v, const float& min, const float& max )
   return result;
 }
 
-Size FitInside( const Size& target, const Size& source )
-{
-  Size fitted; //zero initialized
-  float widthScale = target.width / source.width;
-  float heightScale = target.height / source.height;
-  if( widthScale < heightScale )
-  {
-    // width scale is smaller so fit according to it
-    fitted.width = source.width * widthScale;
-    fitted.height = source.height * widthScale;
-  }
-  else
-  {
-    // height scale is smaller so fit according to it
-    fitted.width = source.width * heightScale;
-    fitted.height = source.height * heightScale;
-  }
-  return fitted;
-}
-
-Size FitScaleToFill( const Size& target, const Size& source )
-{
-  Size fitted = target;
-  if( target.width > 0.0f && EqualsZero( target.height ) )
-  {
-    float scale = target.width / source.width;
-    fitted.height = scale*source.height;
-  }
-  else if( target.height > 0.0f && EqualsZero( target.width ) )
-  {
-    float scale = target.height / source.height;
-    fitted.width = scale * source.width;
-  }
-  else if( target.height > 0.0f && target.width > 0.0f ) // shouldn't be distorted
-  {
-    float widthScale = source.width / target.width;
-    float heightScale = source.height / target.height;
-    if (widthScale < heightScale && target.width > source.width)
-    {
-      //fit by width
-      fitted.height *= widthScale;
-      fitted.width  *= widthScale;
-    }
-    else if (target.height > source.height)
-    {
-      //fit by height
-      fitted.width  *= heightScale;
-      fitted.height *= heightScale;
-    }
-    // else requested dimensions don't need to be fitted
-  }
-  return fitted;
-}
-
-Size ShrinkInside( const Size& target, const Size& 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;
-  }
-  // use smaller of the scales
-  float scale = std::min( widthScale, heightScale );
-
-  // check if we need to scale
-  if( scale < 1.0f )
-  {
-    // scale natural size to fit inside
-    return source * scale;
-  }
-  // there is enough space so use source size
-  return source;
-}
-
 } // namespace Dali
index 6fb54f7..6806a4b 100644 (file)
@@ -468,44 +468,6 @@ inline Vector2 Max( const Vector2& a, const Vector2& b )
  */
 DALI_IMPORT_API Vector2 Clamp( const Vector2& v, const float& min, const float& max );
 
-/**
- * @brief Fits source size inside the target size maintaining aspect ratio.
- *
- * @pre source width and height > 0
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Size FitInside( const Size& target, const Size& source );
-
-/**
- * @brief Fits or scales to fill.
- *
- * a) If target width and height are non-zero
- *    Fits source size into target aspect ratio
- *    If source is bigger, simply returns target.
- *    Does not scale larger than source
- * b) If target width or height is zero
- *    maintains the aspect ratio of source (as target has no aspect ratio)
- *    returns target width and scaled height or target height and scaled width
- * This algorithm is usefull when you want for example a square thumbnail of a rectangular image data
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Size FitScaleToFill( const Size& target, const Size& source );
-
-/**
- * @brief Shrinks source size inside the target size maintaining aspect ratio of source.
- *
- * If source is smaller than target it returns source.
- * @pre source width and height > 0
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Size ShrinkInside( const Size& target, const Size& source );
-
 // Allow Vector2 to be treated as a POD type
 template <> struct TypeTraits< Vector2 > : public BasicTypes< Vector2 > { enum { IS_TRIVIAL_TYPE = true }; };
 
index 7d5c4c7..2b410d0 100644 (file)
@@ -179,149 +179,4 @@ Vector3 Clamp( const Vector3& v, const float& min, const float& max )
   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
index 5f744ea..7dd71a2 100644 (file)
@@ -556,53 +556,6 @@ inline Vector3 Max( const Vector3& a, const Vector3& b )
  */
 DALI_IMPORT_API Vector3 Clamp( const Vector3& v, const float& min, const float& max );
 
-/**
- * @brief Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio.
- *
- * f(target, source) = Vector3( min( target.X / source.X, min( target.Y / source.Y, target.Z / source.Z ) )
- * If any of the source dimensions is zero it will be ignored in the calculation
- *
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Vector3 FitKeepAspectRatio( const Vector3& target, const Vector3& source );
-
-/**
- * @brief Scales an Actor, such that it fill its Parent's Size Keeping the aspect ratio.
- *
- * f(target, source) = Vector3( max( target.X / source.X, max( target.Y / source.Y, target.Z / source.Z ) )
- * If any of the source dimensions is zero it will be ignored in the calculation
- *
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Vector3 FillKeepAspectRatio( const Vector3& target, const Vector3& source );
-
-/**
- * @brief Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio.
- *
- * f(target, source) = Vector3( max( target.X / sizeX, target.Y / sizeY ) )
- * If any of the source dimensions is zero it will be ignored in the calculation
- *
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Vector3 FillXYKeepAspectRatio( const Vector3& target, const Vector3& source );
-
-/**
- * @brief Shrinks source size inside the target size maintaining aspect ratio of source.
- *
- * If source is smaller than target it returns source
- * @pre source width and height > 0
- * @param [in] target size
- * @param [in] source size
- * @return target scaled inside source
- */
-DALI_IMPORT_API Vector3 ShrinkInsideKeepAspectRatio( const Vector3& target, const Vector3& source );
-
 // Allow Vector3 to be treated as a POD type
 template <> struct TypeTraits< Vector3 > : public BasicTypes< Vector3 > { enum { IS_TRIVIAL_TYPE = true }; };