[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / algorithm / path-finder.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // CLASS HEADER
18 #include <dali-scene3d/public-api/algorithm/path-finder.h>
19
20 // INTERNAL INCLUDES
21 // default algorithm
22 #include <dali-scene3d/internal/algorithm/path-finder-dijkstra.h>
23 #include <dali-scene3d/internal/algorithm/path-finder-spfa-double-way.h>
24 #include <dali-scene3d/internal/algorithm/path-finder-spfa.h>
25
26 namespace Dali::Scene3D::Algorithm
27 {
28 std::unique_ptr<PathFinder> PathFinder::New(NavigationMesh& navigationMesh, PathFinderAlgorithm algorithm)
29 {
30   PathFinderBase* impl = nullptr;
31
32   switch(algorithm)
33   {
34     case PathFinderAlgorithm::DIJKSTRA_SHORTEST_PATH:
35     {
36       impl = new Dali::Scene3D::Internal::Algorithm::PathFinderAlgorithmDijkstra(navigationMesh);
37       break;
38     }
39     case PathFinderAlgorithm::SPFA:
40     {
41       impl = new Dali::Scene3D::Internal::Algorithm::PathFinderAlgorithmSPFA(navigationMesh);
42       break;
43     }
44     case PathFinderAlgorithm::SPFA_DOUBLE_WAY:
45     {
46       impl = new Dali::Scene3D::Internal::Algorithm::PathFinderAlgorithmSPFADoubleWay(navigationMesh);
47       break;
48     }
49   }
50
51   if(!impl)
52   {
53     return {};
54   }
55
56   auto retval = std::unique_ptr<PathFinderBase>();
57   retval.reset(impl);
58   return std::unique_ptr<Algorithm::PathFinder>(new Algorithm::PathFinder(std::move(retval)));
59 }
60
61 WayPointList PathFinder::FindPath(const Dali::Vector3& positionFrom, const Dali::Vector3& positionTo)
62 {
63   return mImpl->FindPath(positionFrom, positionTo);
64 }
65
66 WayPointList PathFinder::FindPath(FaceIndex polyIndexFrom, FaceIndex polyIndexTo)
67 {
68   return mImpl->FindPath(polyIndexFrom, polyIndexTo);
69 }
70
71 PathFinder::PathFinder(std::unique_ptr<PathFinderBase>&& baseImpl)
72 {
73   mImpl = std::move(baseImpl);
74 }
75
76 } // namespace Dali::Scene3D::Algorithm