MCPcopy Create free account
hub / github.com/comaps/comaps / GetIntersectionScore

Function GetIntersectionScore

libs/geometry/intersection_score.hpp:40–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38/// |lhs| and |rhs| are any areal boost::geometry types.
39template <typename LGeometry, typename RGeometry>
40double GetIntersectionScore(LGeometry const & lhs, RGeometry const & rhs)
41{
42 if (!boost::geometry::is_valid(lhs) || !boost::geometry::is_valid(rhs) || boost::geometry::is_empty(lhs) ||
43 boost::geometry::is_empty(rhs))
44 {
45 return kPenaltyScore;
46 }
47
48 auto const lhsArea = boost::geometry::area(lhs);
49 auto const rhsArea = boost::geometry::area(rhs);
50 impl::MultiPolygon result;
51 boost::geometry::intersection(lhs, rhs, result);
52 auto const intersectionArea = boost::geometry::area(result);
53 auto const unionArea = lhsArea + rhsArea - intersectionArea;
54
55 auto const score = intersectionArea / unionArea;
56
57 return score;
58}
59
60/// Throws NotAPolygonException exception.
61/// For detailed info see comment for

Callers 1

ScoreGeometryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected