Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Coordinate: Add std::pair constructor

# This is the commit message #2:

Fix std::pair member types
  • Loading branch information
ferdnyc committed Dec 4, 2020
1 parent d6892dd commit de9fb41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Coordinate.cpp
Expand Up @@ -40,7 +40,7 @@ Coordinate::Coordinate() : Coordinate::Coordinate(0, 0) {};
Coordinate::Coordinate(double x, double y) : X(x), Y(y) {};

// Constructor which accepts a std::pair for (X, Y)
Coordinate::Coordinate(const std::pair<int, int>& co)
Coordinate::Coordinate(const std::pair<double, double>& co)
: X(co.first), Y(co.second) {};

// Generate JSON string of this object
Expand Down
4 changes: 2 additions & 2 deletions src/Coordinate.h
Expand Up @@ -64,8 +64,8 @@ namespace openshot {
Coordinate(double x, double y);

/// @brief Constructor which accepts a std::pair tuple for {X, Y}
/// @param co A std::pair<int, int> tuple containing (X, Y)
Coordinate(const std::pair<int, int>& co);
/// @param co A std::pair<double, double> tuple containing (X, Y)
Coordinate(const std::pair<double, double>& co);

/// Get and Set JSON methods
std::string Json() const; ///< Generate JSON string of this object
Expand Down
7 changes: 7 additions & 0 deletions tests/Coordinate_Tests.cpp
Expand Up @@ -57,6 +57,13 @@ TEST(X_Y_Constructor)
CHECK_CLOSE(8.0f, c1.Y, 0.00001);
}

TEST(Pair_Constructor)
{
Coordinate c1(std::pair<double,double>(12, 10));
CHECK_CLOSE(12.0f, c1.X, 0.00001);
CHECK_CLOSE(10.0f, c1.Y, 0.00001);
}

TEST(Json)
{
openshot::Coordinate c(100, 200);
Expand Down

0 comments on commit de9fb41

Please sign in to comment.