Skip to content

Commit 90a618c

Browse files
committed
Add GeoRectangle operators ==, != implementation
These operators were declared, but not implemented Relates-To: MINOR Signed-off-by: Mykola Malik <[email protected]>
1 parent 65757ff commit 90a618c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

olp-cpp-sdk-core/src/geo/coordinates/GeoRectangle.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ bool GeoRectangle::Overlaps(const GeoRectangle& rectangle) const {
120120
return !(west >= rectangle_east || rectangle_west >= east);
121121
}
122122

123+
bool GeoRectangle::operator==(const GeoRectangle& other) const {
124+
return south_west_ == other.south_west_ && north_east_ == other.north_east_;
125+
}
126+
127+
bool GeoRectangle::operator!=(const GeoRectangle& other) const {
128+
return !(*this == other);
129+
}
130+
123131
GeoRectangle GeoRectangle::BooleanUnion(const GeoRectangle& other) const {
124132
if (IsEmpty()) {
125133
return other;

olp-cpp-sdk-core/tests/geo/coordinates/GeoRectangleTest.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
#include <gtest/gtest.h>
2121

22-
#include "../testutil/CompareGeoCoordinates.h"
23-
#include "../testutil/CompareGeoRectangle.h"
2422
#include <olp/core/geo/coordinates/GeoRectangle.h>
2523
#include <olp/core/math/Math.h>
24+
#include "../testutil/CompareGeoCoordinates.h"
25+
#include "../testutil/CompareGeoRectangle.h"
2626

2727
namespace olp {
2828
namespace geo {
@@ -87,6 +87,24 @@ TEST(GeoRectangleTest, Containment) {
8787
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(0.05, 0.15))));
8888
}
8989

90+
TEST(GeoRectangleTest, OperatorEqual) {
91+
EXPECT_TRUE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) ==
92+
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)));
93+
EXPECT_FALSE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) ==
94+
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 2)));
95+
EXPECT_FALSE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) ==
96+
GeoRectangle(GeoCoordinates(1, 0), GeoCoordinates(1, 1)));
97+
}
98+
99+
TEST(GeoRectangleTest, OperatorNotEqual) {
100+
EXPECT_FALSE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) !=
101+
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)));
102+
EXPECT_TRUE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) !=
103+
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 2)));
104+
EXPECT_TRUE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)) !=
105+
GeoRectangle(GeoCoordinates(1, 0), GeoCoordinates(1, 1)));
106+
}
107+
90108
TEST(GeoRectangleTest, BooleanUnion) {
91109
// Non-connected
92110
{

0 commit comments

Comments
 (0)