From 4940df9c238b266135332d6d8fa92bda4b2d014d Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Wed, 18 Mar 2015 16:08:13 +0000 Subject: [PATCH] Removed spline class from dali Removed spline class as it has been replaced by Dali::Path Change-Id: Id31dbb0fd7202854b9ddcf47b159c5861c3c6075 --- automated-tests/src/dali/CMakeLists.txt | 1 - automated-tests/src/dali/utc-Dali-Spline.cpp | 634 --------------------------- dali/public-api/dali-core.h | 1 - dali/public-api/file.list | 4 +- dali/public-api/geometry/spline.cpp | 368 ---------------- dali/public-api/geometry/spline.h | 225 ---------- 6 files changed, 1 insertion(+), 1232 deletions(-) delete mode 100644 automated-tests/src/dali/utc-Dali-Spline.cpp delete mode 100644 dali/public-api/geometry/spline.cpp delete mode 100644 dali/public-api/geometry/spline.h diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index a3cd3aa..4d1fc2b 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -77,7 +77,6 @@ SET(TC_SOURCES utc-Dali-Scripting.cpp utc-Dali-SignalTemplatesFunctors.cpp utc-Dali-SignalTemplates.cpp - utc-Dali-Spline.cpp utc-Dali-Stage.cpp utc-Dali-TapGesture.cpp utc-Dali-TapGestureDetector.cpp diff --git a/automated-tests/src/dali/utc-Dali-Spline.cpp b/automated-tests/src/dali/utc-Dali-Spline.cpp deleted file mode 100644 index d9484a8..0000000 --- a/automated-tests/src/dali/utc-Dali-Spline.cpp +++ /dev/null @@ -1,634 +0,0 @@ -/* - * Copyright (c) 2014 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. - * - */ - -#include - -#include -#include -#include - -using namespace Dali; -using namespace Dali::Internal; -using Dali::Spline; -using Dali::Vector3; - -namespace -{ - -// Knots fed into Allegro, which generates control points -static Spline* SetupBezierSpline1() -{ - Spline *bezierSpline = new Spline(); - - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0)); - bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0)); - bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0)); - bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0)); - - bezierSpline->SetInTangent (0, Vector3( 0.0, 0.0, 0.0)); - bezierSpline->SetInTangent (1, Vector3(107.0, 58.0, 0.0)); - bezierSpline->SetInTangent (2, Vector3(152.0, 220.0, 0.0)); - bezierSpline->SetInTangent (3, Vector3(243.0, 263.0, 0.0)); - bezierSpline->SetInTangent (4, Vector3(317.0, 235.0, 0.0)); - bezierSpline->SetInTangent (5, Vector3(383.0, 93.0, 0.0)); - - bezierSpline->SetOutTangent(0, Vector3( 68.0, 55.0, 0.0)); - bezierSpline->SetOutTangent(1, Vector3(156.0, 102.0, 0.0)); - bezierSpline->SetOutTangent(2, Vector3(204.0, 261.0, 0.0)); - bezierSpline->SetOutTangent(3, Vector3(280.0, 256.0, 0.0)); - bezierSpline->SetOutTangent(4, Vector3(360.0, 185.0, 0.0)); - bezierSpline->SetOutTangent(5, Vector3(410.0, 40.0, 0.0)); - return bezierSpline; -} - -// Knots fed into Allegro, which generates control points -static Spline* SetupBezierSpline2() -{ - Spline *spline = new Spline(); - spline->AddKnot(Vector3( 30.0, 80.0, 0.0)); - spline->AddKnot(Vector3( 70.0, 120.0, 0.0)); - spline->AddKnot(Vector3(100.0, 100.0, 0.0)); - spline->SetInTangent (0, Vector3( 0.0, 0.0, 0.0)); - spline->SetInTangent (1, Vector3( 56.0, 119.0, 0.0)); - spline->SetInTangent (2, Vector3( 93.0, 104.0, 0.0)); - spline->SetOutTangent(0, Vector3( 39.0, 90.0, 0.0)); - spline->SetOutTangent(1, Vector3( 78.0, 120.0, 0.0)); - spline->SetOutTangent(2, Vector3(110.0, 90.0, 0.0)); - return spline; -} - - -typedef struct -{ - float x; - float y; -} tPoint; - -tPoint test[] = { - {0.0f, 0.0f}, - {50.0f, 50.0f}, - {120.0f, 70.0f}, - {190.0f, 250.0f}, - {260.0f, 260.0f}, - {330.0f, 220.0f}, - {400.0f, 50.0f}, - {106.0f, 62.5f}, - {242.0f, 261.3f}, - {320.0f, 229.3f}, - {390.0f, 78.1f}, - {399.9999f, 50.0f}, - {401.0f, 0.0f}, - {501.0f, 0.0f}, - {-100.0f, 0.0f}, -}; - -} // anonymous namespace - - - -// Positive test case for a method -int UtcDaliSplineGetYFromMonotonicX(void) -{ - TestApplication application; - - Spline *bezierSpline = SetupBezierSpline1(); - - - for(unsigned int i=0; iGetYFromMonotonicX(test[i].x), - (float)test[i].y, 0.1f, - TEST_LOCATION); - } - - delete bezierSpline; - END_TEST; -} - -int utcDaliSplineGetKnot01(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0)); - bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0)); - bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0)); - bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0)); - - DALI_TEST_EQUALS(bezierSpline->GetKnot(0), Vector3( 50.0, 50.0, 0.0), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetKnot(1), Vector3(120.0, 70.0, 0.0), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetKnot(2), Vector3(190.0, 250.0, 0.0), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetKnot(3), Vector3(260.0, 260.0, 0.0), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetKnot(4), Vector3(330.0, 220.0, 0.0), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetKnot(5), Vector3(400.0, 50.0, 0.0), TEST_LOCATION); - END_TEST; -} - -int utcDaliSplineGetKnot02(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0f)); - - try - { - bezierSpline->GetKnot(1); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - -int utcDaliSplineGetKnot03(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - - try - { - bezierSpline->GetKnot(0); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - -int utcDaliSplineGetInTangent01(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->SetInTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused - bezierSpline->SetInTangent(1, Vector3(108.0f, 57.0f, 0.0)); - - DALI_TEST_EQUALS(bezierSpline->GetInTangent(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetInTangent(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION); - END_TEST; -} - - - -int utcDaliSplineGetInTangent02(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->SetInTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused - bezierSpline->SetInTangent(1, Vector3(108.0f, 57.0f, 0.0)); - - try - { - bezierSpline->GetInTangent(5); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mInTangents.size()", TEST_LOCATION); - } - END_TEST; -} - - -int utcDaliSplineGetInTangent03(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - try - { - bezierSpline->GetInTangent(0); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mInTangents.size()", TEST_LOCATION); - } - END_TEST; -} - - -int utcDaliSplineGetOutTangent01(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->SetOutTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused - bezierSpline->SetOutTangent(1, Vector3(108.0f, 57.0f, 0.0)); - - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(0), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(1), Vector3(108.0f, 57.0f, 0.0f), TEST_LOCATION); - END_TEST; -} - - - -int utcDaliSplineGetOutTangent02(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->SetOutTangent(0, Vector3(0.0f, 0.0f, 0.0)); // Intangent for initial value is unused - bezierSpline->SetOutTangent(1, Vector3(108.0f, 57.0f, 0.0)); - - try - { - bezierSpline->GetOutTangent(5); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mOutTangents.size()", TEST_LOCATION); - } - END_TEST; -} - - -int utcDaliSplineGetOutTangent03(void) -{ - TestApplication application; - - Spline *bezierSpline= new Spline(); - try - { - bezierSpline->GetOutTangent(0); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "knotIndex < mOutTangents.size()", TEST_LOCATION); - } - END_TEST; -} - - -int utcDaliSplineGenerateControlPoints01(void) -{ - TestApplication application; - - Spline *bezierSpline = new Spline(); - - bezierSpline->AddKnot(Vector3( 50.0, 50.0, 0.0)); - bezierSpline->AddKnot(Vector3(120.0, 70.0, 0.0)); - bezierSpline->AddKnot(Vector3(190.0, 250.0, 0.0)); - bezierSpline->AddKnot(Vector3(260.0, 260.0, 0.0)); - bezierSpline->AddKnot(Vector3(330.0, 220.0, 0.0)); - bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0)); - - bezierSpline->GenerateControlPoints(0.25); - - // first in tangent is never used, ignore it. - DALI_TEST_EQUALS(bezierSpline->GetInTangent(1), Vector3(107.0, 58.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetInTangent(2), Vector3(152.0, 220.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetInTangent(3), Vector3(243.0, 263.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetInTangent(4), Vector3(317.0, 235.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetInTangent(5), Vector3(383.0, 93.0, 0.0), 1.0, TEST_LOCATION); - - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(0), Vector3( 68.0, 55.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(1), Vector3(156.0, 102.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(2), Vector3(204.0, 261.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(3), Vector3(280.0, 256.0, 0.0), 1.0, TEST_LOCATION); - DALI_TEST_EQUALS(bezierSpline->GetOutTangent(4), Vector3(360.0, 185.0, 0.0), 1.0, TEST_LOCATION); - // last out tangent is never used, ignore it. - END_TEST; -} - -int utcDaliSplineGenerateControlPoints02(void) -{ - TestApplication application; - - Spline *bezierSpline = new Spline(); - try - { - bezierSpline->GenerateControlPoints(0.25); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "numKnots > 1", TEST_LOCATION); - } - END_TEST; -} - - -int utcDaliSplineGenerateControlPoints03(void) -{ - TestApplication application; - - Spline *bezierSpline = new Spline(); - bezierSpline->AddKnot(Vector3(400.0, 50.0, 0.0f)); - try - { - bezierSpline->GenerateControlPoints(0.25); - tet_result(TET_FAIL); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "numKnots > 1", TEST_LOCATION); - } - END_TEST; -} - - -int UtcDaliSplineGetY01(void) -{ - TestApplication application; - Spline *spline = SetupBezierSpline2(); - - DALI_TEST_EQUALS(spline->GetY(0, 0.0f), 80.0f, TEST_LOCATION); // First control point - DALI_TEST_EQUALS(spline->GetY(0, 0.5f), 102.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(spline->GetY(0, 1.0f), 120.0f, TEST_LOCATION); // Second control point - DALI_TEST_EQUALS(spline->GetY(1, 0.0f), 120.0f, TEST_LOCATION); // Second control point - DALI_TEST_EQUALS(spline->GetY(1, 0.5f), 112.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(spline->GetY(1, 1.0f), 100.0f, TEST_LOCATION); // Third control point - delete spline; - END_TEST; -} - -// Test segments outside range (should assert and fail tetcase!) -int UtcDaliSplineGetY02(void) -{ - TestApplication application; - - try - { - Spline *spline = SetupBezierSpline2(); - spline->GetY(3, 0.0f); // Segment outside range - expect assertion - - // If we get here, assertion hasn't triggered. - tet_result(TET_FAIL); - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - -// Test segments outside range (should assert and fail tetcase!) -int UtcDaliSplineGetY02b(void) -{ - TestApplication application; - try - { - Spline *spline = SetupBezierSpline2(); - spline->GetY(-1, 0.0f); // Segment outside range - expect assertion - - // If we get here, assertion hasn't triggered. - tet_result(TET_FAIL); - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - - -// Test parameter ouside 0-1 - should return 0. -int UtcDaliSplineGetY03(void) -{ - TestApplication application; - Spline *spline = SetupBezierSpline2(); - DALI_TEST_EQUALS(spline->GetY(1, -1.0f), 0.0f, TEST_LOCATION); - DALI_TEST_EQUALS(spline->GetY(1, 2.0f), 0.0f, TEST_LOCATION); - delete spline; - END_TEST; -} - -// Test on empty spline - should assert -int UtcDaliSplineGetY04(void) -{ - TestApplication application; - try - { - Spline *spline = new Spline(); - spline->GetY(0, 0.0f); // Should assert - tet_result(TET_FAIL); - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - - -// Test on empty spline - should assert -int UtcDaliSplineGetY04b(void) -{ - TestApplication application; - try - { - Spline *spline = new Spline(); - spline->GetY(0, 1.0f); - tet_result(TET_FAIL); // assertion didn't trigger - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - - - -int UtcDaliSplineGetPoint01(void) -{ - TestApplication application; - Spline *spline = SetupBezierSpline2(); - - // Test control points - Vector3 pt = spline->GetPoint(0, 0.0f); - DALI_TEST_EQUALS(pt.x, 30.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 80.0f, TEST_LOCATION); - - // Test control points - pt = spline->GetPoint(0, 1.0f); - DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION); - - // Halfway point computed using Allegro engine - pt = spline->GetPoint(0, 0.5f); - DALI_TEST_EQUALS(pt.x, 47.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 102.0f, 2.0f, TEST_LOCATION); - - // Test control point - pt = spline->GetPoint(1, 0.0f); - DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION); - - // Halfway point computed using Allegro engine - pt = spline->GetPoint(1, 0.5f); - DALI_TEST_EQUALS(pt.x, 85.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 112.0f, 2.0f, TEST_LOCATION); - - // Test control points - pt = spline->GetPoint(1, 1.0f); - DALI_TEST_EQUALS(pt.x, 100.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 100.0f, TEST_LOCATION); - delete spline; - END_TEST; -} - - -int UtcDaliSplineGetPoint02(void) -{ - TestApplication application; - Spline *spline = SetupBezierSpline2(); - - // Test control points - Vector3 pt = spline->GetPoint(0.0f); - DALI_TEST_EQUALS(pt.x, 30.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 80.0f, TEST_LOCATION); - - // Halfway point computed using Allegro engine - pt = spline->GetPoint(0.25f); - DALI_TEST_EQUALS(pt.x, 47.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 102.0f, 2.0f, TEST_LOCATION); - - // Test control points - pt = spline->GetPoint(0.5f); - DALI_TEST_EQUALS(pt.x, 70.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 120.0f, TEST_LOCATION); - - // Halfway point computed using Allegro engine - pt = spline->GetPoint(0.75f); - DALI_TEST_EQUALS(pt.x, 85.0f, 2.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 112.0f, 2.0f, TEST_LOCATION); - - // Test control points - pt = spline->GetPoint(1.0f); - DALI_TEST_EQUALS(pt.x, 100.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 100.0f, TEST_LOCATION); - delete spline; - END_TEST; -} - - -// Test on segment index out of bounds - should assert and fail tet case -int UtcDaliSplineGetPoint03(void) -{ - TestApplication application; - try - { - Spline *spline = SetupBezierSpline2(); - - spline->GetPoint(-1, 0.5f); // should assert - tet_result(TET_FAIL); - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - -// Test on segment index out of bounds - should assert and fail tet case -int UtcDaliSplineGetPoint04(void) -{ - TestApplication application; - try - { - Spline *spline = SetupBezierSpline2(); - - spline->GetPoint(123, 0.5f); // should assert - tet_result(TET_FAIL); - delete spline; - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} - - -// Test on parameter out of bounds - should return 0,0 -int UtcDaliSplineGetPoint05(void) -{ - TestApplication application; - Spline *spline = SetupBezierSpline2(); - - Vector3 pt = spline->GetPoint(0, -32.0f); - DALI_TEST_EQUALS(pt.x, 0.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 0.0f, TEST_LOCATION); - - pt = spline->GetPoint(0, 23444.0f); - DALI_TEST_EQUALS(pt.x, 0.0f, TEST_LOCATION); - DALI_TEST_EQUALS(pt.y, 0.0f, TEST_LOCATION); - END_TEST; -} - -// Test on empty spline - should assert and fail tet case -int UtcDaliSplineGetPoint06(void) -{ - TestApplication application; - try - { - Spline *spline = new Spline(); - spline->GetPoint(0, 23444.0f); - tet_result(TET_FAIL); - delete(spline); - } - catch (Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_ASSERT(e, "segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size()", TEST_LOCATION); - } - END_TEST; -} diff --git a/dali/public-api/dali-core.h b/dali/public-api/dali-core.h index e1578bc..4177c7f 100644 --- a/dali/public-api/dali-core.h +++ b/dali/public-api/dali-core.h @@ -85,7 +85,6 @@ #include #include #include -#include #include #include diff --git a/dali/public-api/file.list b/dali/public-api/file.list index b31bee7..95ed9c0 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -53,7 +53,6 @@ public_api_src_files = \ $(public_api_src_dir)/geometry/mesh-data.cpp \ $(public_api_src_dir)/geometry/mesh-factory.cpp \ $(public_api_src_dir)/geometry/mesh.cpp \ - $(public_api_src_dir)/geometry/spline.cpp \ $(public_api_src_dir)/images/atlas.cpp \ $(public_api_src_dir)/images/distance-field.cpp \ $(public_api_src_dir)/images/image.cpp \ @@ -196,8 +195,7 @@ public_api_core_geometry_header_files = \ $(public_api_src_dir)/geometry/cloth.h \ $(public_api_src_dir)/geometry/mesh.h \ $(public_api_src_dir)/geometry/mesh-data.h \ - $(public_api_src_dir)/geometry/mesh-factory.h \ - $(public_api_src_dir)/geometry/spline.h + $(public_api_src_dir)/geometry/mesh-factory.h public_api_core_images_header_files = \ $(public_api_src_dir)/images/atlas.h \ diff --git a/dali/public-api/geometry/spline.cpp b/dali/public-api/geometry/spline.cpp deleted file mode 100644 index 4bb3a1e..0000000 --- a/dali/public-api/geometry/spline.cpp +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (c) 2014 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 - -// INTERNAL INCLUDES -#include -#include -#include - -namespace -{ -const int MAXIMUM_ITERATIONS=1000; -} - -namespace Dali -{ - -/** - * These basis matrices arise from the cubic polynomial equations for each - * spline type. See Collada 1.4.1 specification for more information - */ -const float Spline::BezierBasisA[] = {-1.0f, 3.0f, -3.0f, 1.0f, - 3.0f, -6.0f, 3.0f, 0.0f, - -3.0f, 3.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f }; - - -Spline::Spline() - : mBasis(BezierBasisA) -{ -} - -Spline::~Spline() -{ -} - -void Spline::AddKnot(Vector3 knot) -{ - mKnots.push_back(knot); - mInTangents.push_back(Vector3()); - mOutTangents.push_back(Vector3()); -} - - -void Spline::SetInTangent(size_t knotIndex, Vector3 inTangent) -{ - DALI_ASSERT_ALWAYS( knotIndex < mInTangents.size() && "knotIndex out of bounds" ); - mInTangents[knotIndex] = inTangent; -} - -void Spline::SetOutTangent(size_t knotIndex, Vector3 outTangent) -{ - DALI_ASSERT_ALWAYS( knotIndex < mOutTangents.size() && "knotIndex out of bounds" ); - mOutTangents[knotIndex] = outTangent; -} - -Vector3 Spline::GetKnot(size_t knotIndex) -{ - DALI_ASSERT_ALWAYS( knotIndex < mKnots.size() && "knotIndex out of bounds" ); - return mKnots[knotIndex]; -} - -Vector3 Spline::GetInTangent(size_t knotIndex) -{ - DALI_ASSERT_ALWAYS( knotIndex < mInTangents.size() && "knotIndex out of bounds" ); - return mInTangents[knotIndex]; -} - -Vector3 Spline::GetOutTangent(size_t knotIndex) -{ - DALI_ASSERT_ALWAYS( knotIndex < mOutTangents.size() && "knotIndex out of bounds" ); - return mOutTangents[knotIndex]; -} - -void Spline::GenerateControlPoints(float curvature) -{ - size_t numKnots = mKnots.size(); - DALI_ASSERT_ALWAYS( numKnots > 1 && "Need at least 1 segment to generate control points" ); // need at least 1 segment - - for(size_t knotIndex = 0; knotIndex < numKnots; knotIndex++) - { - Vector3 curPoint = mKnots[knotIndex]; - Vector3 prevPoint, nextPoint; - if(knotIndex == 0) - { - // create a dummy point - Vector3 nextPoint = mKnots[1]; - prevPoint = curPoint - (nextPoint - curPoint)/8.0f; - } - else - { - prevPoint = mKnots[knotIndex-1]; - } - - if(knotIndex == numKnots-1) - { - // create a dummy point - nextPoint = curPoint - (prevPoint - curPoint)/8.0f; - } - else - { - nextPoint = mKnots[knotIndex+1]; - } - - Vector3 a = curPoint - prevPoint; - Vector3 b = nextPoint - curPoint; - float aLength = a.Length(); - float bLength = b.Length(); - - Vector3 tangent = (a*bLength + b*aLength)/2.0f; - tangent.Normalize(); - - aLength *= curvature; - bLength *= curvature; - mInTangents[knotIndex] = curPoint - tangent*aLength; - mOutTangents[knotIndex] = curPoint + tangent*bLength; - } -} - -unsigned int Spline::GetNumberOfSegments() const -{ - return (mKnots.size()>1)?mKnots.size()-1:0; -} - - -const Vector3 Spline::GetPoint(float alpha) const -{ - Vector3 current; - unsigned int numSegs = GetNumberOfSegments(); - if(numSegs > 0) - { - unsigned int segment = alpha * numSegs; - float segLength = 1.0f / numSegs; - float segStart = (float)segment * segLength; - float progress = (alpha - segStart) * numSegs; - if(segment >= numSegs) - { - segment = numSegs-1.0f; - progress = 1.0f; - } - current = GetPoint(segment, progress); - } - return current; -} - - -// Given a parameter s, return the point on the given spline segment. -// Checks that the segment index is valid (e.g. for 10 points, there -// are only 9 segments) -const Vector3 Spline::GetPoint(unsigned int segmentIndex, float s) const -{ - DALI_ASSERT_ALWAYS( segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size() && "segmentIndex out of bounds" ); - DALI_ASSERT_ALWAYS( mOutTangents.size() == mKnots.size() && "Spline not fully initialized" ); - DALI_ASSERT_ALWAYS( mInTangents.size() == mKnots.size() && "Spline not fully initialized" ); - - Vector3 bPoint; - - if(s < 0.0f || s > 1.0f) - { - bPoint.x = 0.0f; - bPoint.y = 0.0f; - bPoint.z = 0.0f; - } - else if(s < Math::MACHINE_EPSILON_1) - { - bPoint = mKnots[segmentIndex]; - } - else if( (1.0 - s) < Math::MACHINE_EPSILON_1) - { - bPoint = mKnots[segmentIndex+1]; - } - else - { - Vector4 sVect(s*s*s, s*s, s, 1); - Vector4 cVect; - - cVect.x = mKnots[segmentIndex].x; - cVect.y = mOutTangents[segmentIndex].x; - cVect.z = mInTangents[segmentIndex+1].x; - cVect.w = mKnots[segmentIndex+1].x; - bPoint.x = sVect.Dot4(mBasis * cVect); - - cVect.x = mKnots[segmentIndex].y; - cVect.y = mOutTangents[segmentIndex].y; - cVect.z = mInTangents[segmentIndex+1].y; - cVect.w = mKnots[segmentIndex+1].y; - bPoint.y = sVect.Dot4(mBasis * cVect); - - cVect.x = mKnots[segmentIndex].z; - cVect.y = mOutTangents[segmentIndex].z; - cVect.z = mInTangents[segmentIndex+1].z; - cVect.w = mKnots[segmentIndex+1].z; - bPoint.z = sVect.Dot4(mBasis * cVect); - } - return bPoint; -} - - -// Given a parameter s (NOT x), return the Y value. Checks that the -// segment index is valid. For bezier splines, the last segment is -// only used to specify the end point, so is not valid. -float Spline::GetY(unsigned int segmentIndex, float s) const -{ - DALI_ASSERT_ALWAYS( segmentIndex+1 < mKnots.size() && segmentIndex < mKnots.size() && "segmentIndex out of bounds"); - DALI_ASSERT_ALWAYS( mOutTangents.size() == mKnots.size() && "Spline not fully initialized" ); - DALI_ASSERT_ALWAYS( mInTangents.size() == mKnots.size() && "Spline not fully initialized" ); - - float yValue=0.0f; - - if(s < 0.0f || s > 1.0f) - { - yValue = 0.0f; - } - else if(s < Math::MACHINE_EPSILON_1) - { - yValue = mKnots[segmentIndex].y; - } - else if( (1.0 - s) < Math::MACHINE_EPSILON_1) - { - yValue = mKnots[segmentIndex+1].y; - } - else - { - Vector4 sVect(s*s*s, s*s, s, 1); - Vector4 cVect; - - cVect.x = mKnots[segmentIndex].y; - cVect.y = mOutTangents[segmentIndex].y; - cVect.z = mInTangents[segmentIndex+1].y; - cVect.w = mKnots[segmentIndex+1].y; - yValue = sVect.Dot4(mBasis * cVect); - } - return yValue; -} - -float ClampToZeroOne(float v) -{ - return (v<0.0f)?(0.0f):((v>1.0f)?1.0f:v); -} - -// Use de Casteljau subdivision to approximate the parameter required to find x -// on a Bezier spline -// note, atX is already determined to be >= P0_X, 0) - { - Vector3 lastPoint = mKnots[mKnots.size()-1]; - if(fabsf(lastPoint.x - x) < GetRangedEpsilon(lastPoint.x, x)) - { - yValue = lastPoint.y; - } - } - } - return yValue; -} - -} // Dali diff --git a/dali/public-api/geometry/spline.h b/dali/public-api/geometry/spline.h deleted file mode 100644 index a03e821..0000000 --- a/dali/public-api/geometry/spline.h +++ /dev/null @@ -1,225 +0,0 @@ -#ifndef __DALI_SPLINE_H__ -#define __DALI_SPLINE_H__ - -/* - * Copyright (c) 2014 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. - * - */ - - -// INTERNAL INCLUDES -#include -#include -#include - -namespace Dali -{ - -class Matrix; -struct Vector3; - -/** - * @brief The Spline class is used to interpolate through a series of points - * (or knots) which are open (the end points do not connect). - * - * In Hermite splines, each knot has an in-tangent and an - * out-tangent associated with it. In the case of Bezier splines, - * there are equivalent control points. - * - * Once the spline is initialized with AddKnot(), SetInTangent() and - * SetOutTangent(), the client can choose to use either parametric - * interpolation (using GetPoint()), or calculate a Y value from an X - * value (using GetYFromMonotonicX()). The latter requires that the - * curve is monotonic along X (i.e. for any given X value there is - * exactly 1 Y value). Thus, the initial points and tangents have to - * be chosen carefully. (Most useful for animation curves) - * - */ -class DALI_IMPORT_API Spline -{ -public: - /** - * @brief Constructor. - */ - Spline(); - - /** - * @brief Destructor. - */ - virtual ~Spline(); - - /** - * @brief Add a knot to the spline. - * - * @param[in] knot - the point or knot to add. - */ - void AddKnot(Vector3 knot); - - /** - * @brief Get the knot at the given index. - * - * @param[in] knotIndex the index of the knot - * @return the knot vector - */ - Vector3 GetKnot(size_t knotIndex); - - /** - * @brief Get the in tangent (or in control point) at the given index. - * - * @param[in] knotIndex the index of the knot - * @return the in tangent (or in control point) - */ - Vector3 GetInTangent(size_t knotIndex); - - /** - * @brief Get the out tangent (or out control point) at the given index. - * - * @param[in] knotIndex the index of the knot - * @return the out tangent (or out control point) - */ - Vector3 GetOutTangent(size_t knotIndex); - - /** - * @brief Set an in-tangent for the given knot. - * - * @param[in] knotIndex - the index of the knot - * @param[in] inTangent - The in tangent or control point, depending on the spline type - */ - void SetInTangent(size_t knotIndex, Vector3 inTangent); - - /** - * @brief Set an out-tangent for the given knot. - * - * @param[in] knotIndex - the index of the knot - * @param[in] outTangent - The out tangent or control point, depending on the spline type - */ - void SetOutTangent(size_t knotIndex, Vector3 outTangent); - - /** - * @brief For the given set of knot points, generate control points which result in a smooth join between the splines of each segment. - * - * The generating algorithm is as follows: - * For a given knot point K[N], find the vector that bisects K[N-1],[N] and [N],[N+1]. - * Calculate the tangent vector by taking the normal of this bisector. - * The in control point is the length of the preceding segment back along this bisector multiplied by the curvature - * The out control point is the length of the succceding segment forward along this bisector multiplied by the curvature - * - * @param[in] curvature The curvature of the spline. 0 gives straight lines between the knots, - * negative values means the spline contains loops, positive values up to - * 0.5 result in a smooth curve, positive values between 0.5 and 1 result - * in looped curves where the loops are not distinct (i.e. the curve appears - * to be non-continuous), positive values higher than 1 result in looped curves. - */ - void GenerateControlPoints(float curvature=0.25f); - - /** - * @brief Get the number of segments. - * - * This is the number of points - 1, or zero if there are fewer than 2 points. - * @return the number of segments - */ - unsigned int GetNumberOfSegments() const; - - /** - * @brief Given an alpha value 0.0-1.0, return the associated point on the entire - * spline. - * - * The alpha value is split into each segment equally, so doesn't give a - * constant speed along the spline. An alpha value of 0.0 returns the first knot - * and an alpha value of 1.0 returns the last knot. - * - * @param[in] alpha - the overall parameter value. - * @return point - the interpolated point. - */ - const Vector3 GetPoint(float alpha) const; - - /** - * @brief Given a parameter 0.0 - 1.0, return the associated point - * on the spline given the relevant segment. - * - * Note, the parameter does not correspond to an axis, neither is it - * necessarily equally spaced along the curve. If the parameter is - * 0.0 or 1.0, then the first or second knot point is returned. - * - * @param[in] segmentIndex the segment of the spline to interpolation. - * @param[in] parameter the parameter to use in the parametric formula - * @return point the interpolated point. - */ - const Vector3 GetPoint(unsigned int segmentIndex, float parameter) const; - - /** - * @brief Given a value X on the spline (between the first and last knot inclusively), - * calculate the corresponding Y value. Requires that there is only 1 Y per X. - * - * @param[in] x The X - * @return the Y value - */ - float GetYFromMonotonicX(float x) const; - - /** - * @brief For a 2 dimensional curve (z=0), given a parameter 0.0 - 1.0, return the - * associated Y value on the spline given the relevant segment. - * - * Note, the parameter does not correspond to an axis, neither is it - * necessarily equally spaced along the curve. If the parameter is - * 0.0 or 1.0, then the first or second knot point's Y value is - * returned. - * - * @param[in] segmentIndex - the segment of the spline to interpolation. - * @param[in] parameter - the parameter to use in the parametric formula - * @return y value - the interpolated point's Y value - */ - float GetY(unsigned int segmentIndex, float parameter) const; - - -private: - /** - * @brief FindSegment searches through the control points to find the appropriate - * segment. - * - * @param[in] x - the X value to search for - * @param[out] segmentIndex - the returned segment index - * @return True if the segment was found. - */ - bool FindSegment(float x, int& segmentIndex) const; - - /** - * @brief Given two knots and control points, interpolate to find the - * parameter that will give the required X value. - * - * Requires that X is monotonic. - * - * @param[in] atX the X value to search for - * @param[in] P0_X the starting knot's X - * @param[in] C0_X the X of the control point for the first knot - * @param[in] C1_X the X of the control point for the second knot - * @param[in] P1_X the ending knot's X. - * @return the corresponding parameter. - */ - float ApproximateCubicBezierParameter (float atX, float P0_X, float C0_X, float C1_X, float P1_X ) const; - -private: - std::vector mKnots; ///< The set of knot points - std::vector mOutTangents; ///< The set of out tangents (matching to mKnots) - std::vector mInTangents; ///< The set of in tangents (matching to mKnots) - - Matrix mBasis; ///< The basis matrix to use - - static const float BezierBasisA[]; ///< The basis matrix for Bezier splines -}; - -} //namespace Dali - -#endif //__DALI_SPLINE_H__ -- 2.7.4