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

Function ForEachRect

libs/geometry/calipers_box.cpp:35–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33// containing the hull and with one side collinear to the facet.
34template <typename Fn>
35void ForEachRect(ConvexHull const & hull, Fn && fn)
36{
37 ASSERT_GREATER(hull.Size(), 2, ());
38
39 size_t j = 0, k = 0, l = 0;
40 for (size_t i = 0; i < hull.Size(); ++i)
41 {
42 auto const ab = hull.SegmentAt(i).Dir();
43
44 j = std::max(j, i + 1);
45 while (DotProduct(ab, hull.SegmentAt(j).Dir()) > CalipersBox::kEps)
46 ++j;
47
48 k = std::max(k, j);
49 while (CrossProduct(ab, hull.SegmentAt(k).Dir()) > CalipersBox::kEps)
50 ++k;
51
52 l = std::max(l, k);
53 while (DotProduct(ab, hull.SegmentAt(l).Dir()) < -CalipersBox::kEps)
54 ++l;
55
56 auto const oab = Ort(ab);
57 std::array<Line2D, 4> const lines = {Line2D(hull.PointAt(i), ab), Line2D(hull.PointAt(j), oab),
58 Line2D(hull.PointAt(k), ab), Line2D(hull.PointAt(l), oab)};
59 std::vector<PointD> corners;
60 for (size_t i = 0; i < lines.size(); ++i)
61 {
62 auto const j = (i + 1) % lines.size();
63 auto result = Intersect(lines[i], lines[j], CalipersBox::kEps);
64 if (result.m_type == IntersectionResult::Type::One)
65 corners.push_back(result.m_point);
66 }
67
68 if (corners.size() != 4)
69 continue;
70
71 auto const it = std::min_element(corners.begin(), corners.end());
72 std::rotate(corners.begin(), it, corners.end());
73
74 fn(std::move(corners));
75 }
76}
77} // namespace
78
79CalipersBox::CalipersBox(std::vector<PointD> const & points) : m_points({})

Callers 1

CalipersBoxMethod · 0.85

Calls 12

OrtFunction · 0.85
Line2DClass · 0.85
DirMethod · 0.80
SegmentAtMethod · 0.80
DotProductFunction · 0.70
CrossProductFunction · 0.70
IntersectFunction · 0.70
SizeMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected