| 77 | } // namespace |
| 78 | |
| 79 | CalipersBox::CalipersBox(std::vector<PointD> const & points) : m_points({}) |
| 80 | { |
| 81 | ConvexHull hull(points, kEps); |
| 82 | |
| 83 | if (hull.Size() < 3) |
| 84 | { |
| 85 | m_points = hull.Points(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | double bestArea = std::numeric_limits<double>::max(); |
| 90 | std::vector<PointD> bestPoints; |
| 91 | ForEachRect(hull, [&](std::vector<PointD> && points) |
| 92 | { |
| 93 | ASSERT_EQUAL(points.size(), 4, ()); |
| 94 | double const area = GetPolygonArea(points.begin(), points.end()); |
| 95 | if (area < bestArea) |
| 96 | { |
| 97 | bestArea = area; |
| 98 | bestPoints = std::move(points); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | if (!bestPoints.empty()) |
| 103 | { |
| 104 | ASSERT_EQUAL(bestPoints.size(), 4, ()); |
| 105 | m_points = std::move(bestPoints); |
| 106 | } |
| 107 | else |
| 108 | m_points = BoundingBox(points).Points(); |
| 109 | } |
| 110 | |
| 111 | void CalipersBox::Deserialize(std::vector<PointD> && points) |
| 112 | { |
nothing calls this directly
no test coverage detected