21template <
typename Derived,
typename Scalar>
22bool Vec2DCommon<Derived, Scalar>::operator==(
const Derived& other)
const
24 const auto& v =
static_cast<const Derived&
>(*this);
26 return v.x == other.x &&
30template <
typename Derived,
typename Scalar>
31bool Vec2DCommon<Derived, Scalar>::operator!=(
const Derived& other)
const
33 const auto& v =
static_cast<const Derived&
>(*this);
35 return v.x != other.x ||
39template <
typename Derived,
typename Scalar>
40Derived Vec2DCommon<Derived, Scalar>::operator+(
const Derived& other)
const
42 const auto& v =
static_cast<const Derived&
>(*this);
45 result.x = v.x + other.x;
46 result.y = v.y + other.y;
51template <
typename Derived,
typename Scalar>
52Derived Vec2DCommon<Derived, Scalar>::operator-(
const Derived& other)
const
54 const auto& v =
static_cast<const Derived&
>(*this);
57 result.x = v.x - other.x;
58 result.y = v.y - other.y;
63template <
typename Derived,
typename Scalar>
64Derived Vec2DCommon<Derived, Scalar>::operator*(
const Derived& other)
const
66 const auto& v =
static_cast<const Derived&
>(*this);
69 result.x = v.x * other.x;
70 result.y = v.y * other.y;
75template <
typename Derived,
typename Scalar>
76Derived Vec2DCommon<Derived, Scalar>::operator+=(
const Derived& other)
78 auto& v =
static_cast<Derived&
>(*this);
80 result.x = v.x += other.x;
81 result.y = v.y += other.y;
85template <
typename Derived,
typename Scalar>
86Derived Vec2DCommon<Derived, Scalar>::operator-=(
const Derived& other)
88 auto& v =
static_cast<Derived&
>(*this);
90 result.x = v.x -= other.x;
91 result.y = v.y -= other.y;
95template <
typename Derived,
typename Scalar>
100 auto& ccv =
static_cast<Derived&
>(*this);
101 ccv.x =
decltype(ccv.x)(v[0]);
102 ccv.y =
decltype(ccv.y)(v[1]);
108 template <
typename Derived>
113 result.x =
static_cast<decltype(result.x)
>(lhs[0][0] * rhs.x + lhs[0][1] * rhs.y);
114 result.y =
static_cast<decltype(result.y)
>(lhs[1][0] * rhs.x + lhs[1][1] * rhs.y);
126template <
typename Derived,
typename Scalar>
127std::string yarp::math::Vec2DCommon<Derived, Scalar>::PrintToString(
int precision,
int width)
const
129 const auto& ccv =
static_cast<const Derived&
>(*this);
131 std::ostringstream stringStream;
132 stringStream.precision(precision);
133 stringStream.width(width);
134 stringStream << std::string(
"x:") << ccv.x << std::string(
" y:") << ccv.y;
135 return stringStream.str();
139template <
typename Derived,
typename Scalar>
140Scalar yarp::math::Vec2DCommon<Derived, Scalar>::norm()
const
142 const auto& v =
static_cast<const Derived&
>(*this);
143 return static_cast<Scalar
>(std::sqrt(
static_cast<double>(v.x * v.x + v.y * v.y)));
146template <
typename Derived,
typename Scalar>
149 const auto& ccv =
static_cast<const Derived&
>(*this);
152 v[0] = double(ccv.x);
153 v[1] = double(ccv.y);
158template class YARP_math_API yarp::math::Vec2DCommon<Vec2DOfInt, int>;
159template class YARP_math_API yarp::math::Vec2DCommon<Vec2DOfDouble, double>;
160template class YARP_math_API yarp::math::Vec2DCommon<Vec2DOfSizet, size_t>;
size_t cols() const
Return number of columns.
size_t rows() const
Return number of rows.
size_t size() const
Returns the number of elements in the vector.
#define yCAssert(component, x)
#define YARP_LOG_COMPONENT(name,...)
Derived operator*(const yarp::sig::Matrix &lhs, const Derived &rhs)