| 38 | /// |lhs| and |rhs| are any areal boost::geometry types. |
| 39 | template <typename LGeometry, typename RGeometry> |
| 40 | double 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 |