Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-helper-functions.cpp
1 /*
2  * Copyright (c) 2014 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
18 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-helper-functions.h>
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace Internal
27 {
28
29 namespace ScrollViewHelperFunctions
30 {
31
32 bool IsStraightOnView( const Vector3& position )
33 {
34   return ( fabsf(position.x) < Math::MACHINE_EPSILON_1 ) && ( fabsf( position.y ) < Math::MACHINE_EPSILON_1 );
35 }
36
37 void WrapPositionWithinDomain( Vector3& position, const Vector3& pageSize, const Vector3& min, const Vector3& max )
38 {
39   if( fabsf( min.x - max.x ) > Math::MACHINE_EPSILON_1 )
40   {
41     // WRAP X (based on the position of the right side)
42     position.x = WrapInDomain( position.x + pageSize.width, min.x, max.x ) - pageSize.width;
43   }
44
45   if( fabsf( min.y - max.y ) > Math::MACHINE_EPSILON_1 )
46   {
47     // WRAP Y (based on the position of the bottom side)
48     position.y = WrapInDomain( position.y + pageSize.height, min.y, max.y ) - pageSize.height;
49   }
50 }
51
52 bool IsOutsideView( const Vector3& position, const Vector3& pageSize )
53 {
54   return ( fabsf( position.x ) >= pageSize.width ) || ( fabsf( position.y ) >= pageSize.height );
55 }
56
57 } // namespace ScrollViewHelperFunctions
58
59 } // namespace Internal
60
61 } // namespace Toolkit
62
63 } // namespace Dali