Skip to content

Commit

Permalink
Add Min() function and test.
Browse files Browse the repository at this point in the history
Signed-off-by: pxalcantara <[email protected]>
  • Loading branch information
pxalcantara committed Jul 14, 2020
1 parent 9d5fd9c commit 877bca9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/ignition/math/Vector2.hh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ namespace ignition
return std::max(this->data[0], this->data[1]);
}

/// \brief Get the minimum value in the vector
/// \return the minimum element
public: T Min() const
{
return std::min(this->data[0], this->data[1]);
}

/// \brief Assignment operator
/// \param[in] _v a value for x and y element
/// \return this
Expand Down
5 changes: 4 additions & 1 deletion src/Vector2_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ TEST(Vector2Test, Min)
math::Vector2d vec1(0.3, 0.5);
math::Vector2d vec2(0.1, 0.2);
math::Vector2d vec3(0.05, 0.1);


EXPECT_DOUBLE_EQ(vec1.Min(), 0.3);
EXPECT_DOUBLE_EQ(vec3.Min(), 0.05);

vec1.Min(vec2);
EXPECT_EQ(vec1, math::Vector2d(0.1, 0.2));

Expand Down

0 comments on commit 877bca9

Please sign in to comment.