Skip to content

Commit

Permalink
Merge pull request #12317 from KratosMultiphysics/mapping/close-point…
Browse files Browse the repository at this point in the history
…s-operators

[Mapping] Implementing == and != operators
  • Loading branch information
roigcarlo authored May 3, 2024
2 parents 11179af + fde830e commit f9b960a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ PointWithId::PointWithId(const PointWithId& rOther)

bool PointWithId::operator<(const PointWithId& rOther) const
{
if (Point::operator==(rOther)) return false;
return mDistance < rOther.mDistance;
return (!Point::operator==(rOther)) && (mDistance < rOther.mDistance);
}

bool PointWithId::operator==(const PointWithId& rOther) const
{
return ( Point::operator==(rOther));
}

bool PointWithId::operator!=(const PointWithId& rOther) const
{
return (!Point::operator==(rOther));
}

void PointWithId::save(Serializer &rSerializer) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class KRATOS_API(MAPPING_APPLICATION) PointWithId : public IndexedObject, public

bool operator<(const PointWithId& rOther) const;

bool operator!=(const PointWithId& rOther) const;

bool operator==(const PointWithId& rOther) const;

double GetDistance() const { return mDistance; }

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ KRATOS_TEST_CASE_IN_SUITE(PointWithIdEqualComparison, KratosMappingApplicationSe
PointWithId point_2(id, coords, dist);
PointWithId point_3(id, coords2, dist);

// only the position aka the coordinates are used for the equal comparison!
PointWithId point_4(id+1, coords, dist);
PointWithId point_5(id, coords, dist+1.0);
PointWithId point_6(id+1, coords, dist+1.0);

// Only the position (aka the coordinates) are used for the EQ and NE comparison
KRATOS_EXPECT_EQ(point_1, point_2);
KRATOS_EXPECT_NE(point_1, point_3);

Expand Down

0 comments on commit f9b960a

Please sign in to comment.