2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/math/vector2.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/math-utils.h>
29 #include <dali/internal/render/common/performance-monitor.h>
34 const Vector2 Vector2::ONE(1.0f, 1.0f);
35 const Vector2 Vector2::XAXIS(1.0f, 0.0f);
36 const Vector2 Vector2::YAXIS(0.0f, 1.0f);
37 const Vector2 Vector2::NEGATIVE_XAXIS(-1.0f, 0.0f);
38 const Vector2 Vector2::NEGATIVE_YAXIS(0.0f, -1.0f);
39 const Vector2 Vector2::ZERO(0.0f, 0.0f);
41 Vector2::Vector2(const Vector3& vec3)
47 Vector2::Vector2(const Vector4& vec4)
53 Vector2& Vector2::operator=(const Vector3& rhs)
61 Vector2& Vector2::operator=(const Vector4& rhs)
70 bool Vector2::operator==(const Vector2& rhs) const
72 if (fabsf(x - rhs.x) > GetRangedEpsilon(x, rhs.x))
76 if (fabsf(y - rhs.y) > GetRangedEpsilon(y, rhs.y))
84 float Vector2::Length() const
86 return sqrtf(LengthSquared());
89 float Vector2::LengthSquared() const
94 void Vector2::Normalize()
96 float length = Length();
97 if( ! EqualsZero(length) )
99 MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,2);
101 const float inverseLength = 1.0f / length;
107 void Vector2::Clamp( const Vector2& min, const Vector2& max )
109 Dali::ClampInPlace<float>( x, min.x, max.x );
110 Dali::ClampInPlace<float>( y, min.y, max.y );
113 std::ostream& operator<< (std::ostream& o, const Vector2& vector)
115 return o << "[" << vector.x << ", " << vector.y << "]";
118 Vector2 Clamp( const Vector2& v, const float& min, const float& max )
121 result.Clamp( Vector2( min, min ) , Vector2( max, max ) );