Skip to content

Commit db3f7c7

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 db3f7c7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-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: 14 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,18 @@ TEST(GeoRectangleTest, Containment) {
8787
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(0.05, 0.15))));
8888
}
8989

90+
TEST(GeoRectangleTest, OperatorEqual) {
91+
EXPECT_EQ(GeoRectangle(GeoCoordinates(1, 2), GeoCoordinates(10, 20)),
92+
GeoRectangle(GeoCoordinates(1, 2), GeoCoordinates(10, 20)));
93+
}
94+
95+
TEST(GeoRectangleTest, OperatorNotEqual) {
96+
EXPECT_NE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)),
97+
GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 2)));
98+
EXPECT_NE(GeoRectangle(GeoCoordinates(0, 0), GeoCoordinates(1, 1)),
99+
GeoRectangle(GeoCoordinates(1, 0), GeoCoordinates(1, 1)));
100+
}
101+
90102
TEST(GeoRectangleTest, BooleanUnion) {
91103
// Non-connected
92104
{

0 commit comments

Comments
 (0)