2015-05-19 04:16:51 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 04:16:51 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 04:16:51 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 04:16:51 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 04:17:45 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 04:16:51 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 04:17:45 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 04:16:51 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 04:17:45 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 04:16:51 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file vector2.inl
|
|
|
|
* @brief Inline implementation of aiVector2t<TReal> operators
|
|
|
|
*/
|
2016-07-11 18:56:38 +00:00
|
|
|
#pragma once
|
2015-05-19 04:16:51 +00:00
|
|
|
#ifndef AI_VECTOR2D_INL_INC
|
|
|
|
#define AI_VECTOR2D_INL_INC
|
|
|
|
|
2019-10-11 11:27:36 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC system_header
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 04:16:51 +00:00
|
|
|
#ifdef __cplusplus
|
2019-10-11 11:27:36 +00:00
|
|
|
#include <assimp/vector2.h>
|
2015-05-19 04:16:51 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
|
|
|
template <typename TOther>
|
|
|
|
aiVector2t<TReal>::operator aiVector2t<TOther> () const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y));
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:17:45 +00:00
|
|
|
void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
|
2015-05-19 04:18:29 +00:00
|
|
|
x = pX; y = pY;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
TReal aiVector2t<TReal>::SquareLength() const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x*x + y*y;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
TReal aiVector2t<TReal>::Length() const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return std::sqrt( SquareLength());
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:17:45 +00:00
|
|
|
aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
|
2015-05-19 04:18:29 +00:00
|
|
|
*this /= Length();
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
|
2015-05-19 04:18:29 +00:00
|
|
|
x += o.x; y += o.y;
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
|
2015-05-19 04:18:29 +00:00
|
|
|
x -= o.x; y -= o.y;
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:17:45 +00:00
|
|
|
const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
x *= f; y *= f;
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
x /= f; y /= f;
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
TReal aiVector2t<TReal>::operator[](unsigned int i) const {
|
2017-12-14 16:21:17 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return x;
|
|
|
|
case 1:
|
|
|
|
return y;
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-19 04:16:51 +00:00
|
|
|
|
2017-12-14 16:21:17 +00:00
|
|
|
}
|
|
|
|
return x;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x == other.x && y == other.y;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return x != other.x || y != other.y;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
template<typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
bool aiVector2t<TReal>::Equal(const aiVector2t& other, TReal epsilon) const {
|
2015-05-19 04:18:29 +00:00
|
|
|
return
|
|
|
|
std::abs(x - other.x) <= epsilon &&
|
|
|
|
std::abs(y - other.y) <= epsilon;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:18:29 +00:00
|
|
|
aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
|
|
|
|
x = y = f;
|
|
|
|
return *this;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2015-05-19 04:16:51 +00:00
|
|
|
const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t(x*o.x,y*o.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// symmetric addition
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
2017-12-14 16:52:47 +00:00
|
|
|
aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// symmetric subtraction
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar product
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return v1.x*v2.x + v1.y*v2.y;
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar multiplication
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>( f*v.x, f*v.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// and the other way around
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>( f*v.x, f*v.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// scalar division
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return v * (1/f);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// vector division
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// vector negation
|
|
|
|
template <typename TReal>
|
2017-12-14 16:42:59 +00:00
|
|
|
inline
|
|
|
|
aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v) {
|
2015-05-19 04:18:29 +00:00
|
|
|
return aiVector2t<TReal>( -v.x, -v.y);
|
2015-05-19 04:16:51 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 04:17:45 +00:00
|
|
|
#endif
|
2016-07-11 18:56:38 +00:00
|
|
|
|
|
|
|
#endif // AI_VECTOR2D_INL_INC
|