33 #ifdef OGDF_INCLUDE_CGAL
47 template<
typename Kernel>
48 Point_t<Kernel> largest_circle_in_polygon(
const Polygon_t<Kernel>& polygon,
double precision = 1) {
49 using FT =
typename Kernel::FT;
55 Cell(Bbox& bb_, FT distance) : bb(bb_), m_distance(distance) {
59 FT cell_size()
const {
60 return std::min(bb.height(), bb.width());
63 FT potential()
const {
return m_distance + bb.width() * bb.height() / 4; }
65 bool operator<(
const Cell& c)
const {
return potential() > c.potential(); }
68 Bbox bb_p(polygon.bbox());
70 PriorityQueue<Cell> pq;
72 Cell opt(bb_p, squared_distance(polygon, bb_p.template center<Kernel>()));
76 const Cell top = pq.top();
79 if (top.potential() < 0) {
83 if (top.m_distance > opt.m_distance) {
87 if (top.potential() - opt.m_distance < precision) {
91 auto h = top.bb.height() / 2;
92 auto w = top.bb.width() / 2;
94 Bbox b1(top.bb.xmin(), top.bb.ymin(), top.bb.xmin() + w, top.bb.ymin() + h);
95 Bbox b2(top.bb.xmin() + w, top.bb.ymin(), top.bb.xmax(), top.bb.ymin() + h);
96 Bbox b3(top.bb.xmin() + w, top.bb.ymin() + h, top.bb.xmax(), top.bb.ymax());
97 Bbox b4(top.bb.xmin(), top.bb.ymin() + h, top.bb.xmin() + w, top.bb.ymax());
99 pq.push(Cell(b1, squared_distance(polygon, b1.template center<Kernel>())));
100 pq.push(Cell(b2, squared_distance(polygon, b2.template center<Kernel>())));
101 pq.push(Cell(b3, squared_distance(polygon, b3.template center<Kernel>())));
102 pq.push(Cell(b4, squared_distance(polygon, b4.template center<Kernel>())));
106 OGDF_ASSERT(contains(polygon, opt.bb.template center<Kernel>()));
108 return opt.bb.template center<Kernel>();