YARP
Yet Another Robot Platform
Vec2D.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MATH_VEC2D_H
10 #define YARP_MATH_VEC2D_H
11 
12 #include <yarp/math/api.h>
13 
14 #include <yarp/os/Portable.h>
15 
16 #include <yarp/sig/Matrix.h>
17 #include <yarp/sig/Vector.h>
18 
19 #include <type_traits>
20 
21 namespace yarp {
22 namespace math {
23 
24 template <typename T>
26 {
27  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");
28 
29 public:
30  T x;
31  T y;
32 
33 public:
34  Vec2D<T>();
35  Vec2D<T>(const T& x_value, const T& y_value);
36  Vec2D<T>(const yarp::sig::Vector& v);
37  explicit operator yarp::sig::Vector() const
38  {
39  yarp::sig::Vector v(2);
40  v[0] = double(x);
41  v[1] = double(y);
42  return v;
43  }
44 
49  T norm() const;
50 
55  std::string toString(int precision = -1, int width = -1) const;
56 
58  /*
59  * Read vector from a connection.
60  * return true if a Vec2D was read correctly
61  */
62  bool read(yarp::os::ConnectionReader& connection) override;
63 
68  bool write(yarp::os::ConnectionWriter& connection) const override;
69 
70  yarp::os::Type getType() const override
71  {
72  return yarp::os::Type::byName("yarp/vec2D");
73  }
74 
75  //operators
78  bool operator==(const yarp::math::Vec2D<T>& rhs) const;
79  bool operator!=(const yarp::math::Vec2D<T>& rhs) const;
80 };
81 
82 } // namespace math
83 } // namespace yarp
84 
85 //operators
86 template <typename T>
88 
89 template <typename T>
91 
92 template <typename T>
94 
95 #endif // YARP_MATH_VEC2D_H
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
Vector.h
contains the definition of a Vector type
yarp::math::Vec2D::x
T x
Definition: Vec2D.h:27
yarp::os::Type
Definition: Type.h:24
yarp::math::Vec2D::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
operator+
yarp::math::Vec2D< T > operator+(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition: Vec2D.cpp:213
Portable.h
Matrix.h
contains the definition of a Matrix type
yarp::math::Vec2D::getType
yarp::os::Type getType() const override
Definition: Vec2D.h:70
operator+=
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition: math.cpp:41
yarp::math::norm
double norm(const yarp::sig::Vector &v)
Returns the Euclidean norm of the vector (defined in Math.h).
Definition: math.cpp:520
yarp::math::Vec2D
Definition: Vec2D.h:26
yarp::sig::VectorOf< double >
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::sig::Vector
VectorOf< double > Vector
Definition: Vector.h:33
yarp::math::Vec2D::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
toString
std::string toString(const T &value)
convert an arbitrary type to string.
Definition: fakeMotionControl.cpp:121
operator-=
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:96
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
operator*
yarp::math::Vec2D< T > operator*(const yarp::sig::Matrix &lhs, yarp::math::Vec2D< T > rhs)
Definition: Vec2D.cpp:203
YARP_math_API
#define YARP_math_API
Definition: api.h:18
api.h
yarp::math::Vec2D::y
T y
Definition: Vec2D.h:31
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46
operator-
yarp::math::Vec2D< T > operator-(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition: Vec2D.cpp:220