YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Vec2D.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_MATH_VEC2D_H
7#define YARP_MATH_VEC2D_H
8
9#include <yarp/math/api.h>
10
11#include <yarp/os/Portable.h>
12
13#include <yarp/sig/Matrix.h>
14#include <yarp/sig/Vector.h>
15
16#include <type_traits>
17
18namespace yarp::math {
19
20template <typename T>
23{
24 static_assert(std::is_same<size_t, T>::value || std::is_same<int, T>::value || std::is_same<double, T>::value, "Vec2D can be specialized only as size_t, int, double");
25
26public:
27 T x;
28 T y;
29
30 Vec2D();
31 Vec2D(const T& x_value, const T& y_value);
32 Vec2D(const yarp::sig::Vector& v);
33 explicit operator yarp::sig::Vector() const
34 {
36 v[0] = double(x);
37 v[1] = double(y);
38 return v;
39 }
40
45 T norm() const;
46
51 std::string toString(int precision = -1, int width = -1) const;
52
54 /*
55 * Read vector from a connection.
56 * return true if a Vec2D was read correctly
57 */
58 bool read(yarp::os::ConnectionReader& connection) override;
59
64 bool write(yarp::os::ConnectionWriter& connection) const override;
65
66 yarp::os::Type getType() const override
67 {
68 return yarp::os::Type::byName("yarp/vec2D");
69 }
70
71 //operators
74 bool operator==(const yarp::math::Vec2D<T>& rhs) const;
75 bool operator!=(const yarp::math::Vec2D<T>& rhs) const;
76};
77
78} // namespace yarp::math
79
80// Forward declarations of specialized methods
87
88// Forward declaration of explicit instantiated template classes
89YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<double>;
90YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<int>;
91YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<size_t>;
92
93
94
95//operators
96template <typename T>
98
99template <typename T>
101
102template <typename T>
104
105// Forward declaration of explicit instantiated template functions
112
113
114#endif // YARP_MATH_VEC2D_H
bool operator==(const struct v4l2_control &left, const struct v4l2_control &right)
Definition CApiMock.h:65
std::string toString(const T &value)
convert an arbitrary type to string.
contains the definition of a Matrix type
yarp::math::Vec2D< T > operator*(const yarp::sig::Matrix &lhs, yarp::math::Vec2D< T > rhs)
Definition Vec2D.cpp:204
yarp::math::Vec2D< T > operator-(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition Vec2D.cpp:221
yarp::math::Vec2D< T > operator+(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition Vec2D.cpp:214
contains the definition of a Vector type
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
yarp::os::Type getType() const override
Definition Vec2D.h:66
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
static Type byName(const char *name)
Definition Type.cpp:171
A class for a Matrix.
Definition Matrix.h:39
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition math.cpp:98
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition math.cpp:38
double norm(const yarp::sig::Vector &v)
Returns the Euclidean norm of the vector (defined in Math.h).
Definition math.cpp:538
VectorOf< double > Vector
Definition Vector.h:36
#define YARP_math_API
Definition api.h:17
#define YARP_math_EXTERN
Definition api.h:18