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

Method CalipersBox

libs/geometry/calipers_box.cpp:79–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77} // namespace
78
79CalipersBox::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
111void CalipersBox::Deserialize(std::vector<PointD> && points)
112{

Callers

nothing calls this directly

Calls 9

ForEachRectFunction · 0.85
GetPolygonAreaFunction · 0.85
PointsMethod · 0.80
BoundingBoxFunction · 0.70
SizeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected