Skip to content

Commit

Permalink
toString() with precision for vector2d and 3d
Browse files Browse the repository at this point in the history
  • Loading branch information
Labauke committed Dec 19, 2023
1 parent 39fa801 commit bb1a9d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions externals/IBKMK/src/IBKMK_Vector2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ std::string Vector2D::toString() const {
return strm.str();
}

std::string Vector2D::toString(int precision) const {
std::stringstream strm;
strm << std::setprecision(precision) << m_x << " " << m_y;
return strm.str();
}

/*! Converts a vector from a string in format "x y z". Throws an exception if parsing of numbers fails. */
Vector2D Vector2D::fromString(const std::string & vecString) {
FUNCID(Vector2D::fromString);
Expand Down
2 changes: 2 additions & 0 deletions externals/IBKMK/src/IBKMK_Vector2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class Vector2D : public IBK::point2D<double> {

/*! Converts a vector to a string in format "x y z". */
std::string toString() const;
/*! Converts a vector to a string in format "x y z" with given numerical precision */
std::string toString(int precision) const;
/*! Converts a vector from a string in format "x y z". Throws an exception if parsing of numbers fails. */
static Vector2D fromString(const std::string & vecString);

Expand Down
6 changes: 6 additions & 0 deletions externals/IBKMK/src/IBKMK_Vector3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ std::string Vector3D::toString() const {
return strm.str();
}

std::string IBKMK::Vector3D::toString(int precision) const {
std::stringstream strm;
strm << std::setprecision(precision) << m_x << " " << m_y << " " << m_z;
return strm.str();
}


Vector3D Vector3D::fromString(const std::string & vecString) {
FUNCID(Vector3D::fromString);
Expand Down
3 changes: 3 additions & 0 deletions externals/IBKMK/src/IBKMK_Vector3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class Vector3D : public IBK::point3D<double> {
/*! Converts a vector to a string in format "x y z". */
std::string toString() const;

/*! Converts a vector to a string in format "x y z". */
std::string toString(int precision) const;

/*! Converts a vector from a string in format "x y z". Throws an exception if parsing of numbers fails. */
static Vector3D fromString(const std::string & vecString);
};
Expand Down

0 comments on commit bb1a9d7

Please sign in to comment.