| 2267 | } |
| 2268 | |
| 2269 | void clean_noisy_paths(DebugWriter& debug_output, Arrangement_2& arr, SegmentLookup& segment_lookup, double& threshold) { |
| 2270 | using SK = CGAL::Simple_cartesian<double>; |
| 2271 | CGAL::Cartesian_converter<K, SK> C{}; |
| 2272 | |
| 2273 | auto other = [](const Segment_2& e, const Point_2& v) { |
| 2274 | return (e.source() == v) ? e.target() : e.source(); |
| 2275 | }; |
| 2276 | |
| 2277 | std::set<Segment_2, Segment_2_less> edges; |
| 2278 | for (auto he = arr.edges_begin(); he != arr.edges_end(); ++he) { |
| 2279 | auto a = he->source()->point(); |
| 2280 | auto b = he->target()->point(); |
| 2281 | if (a < b) { |
| 2282 | edges.insert({a, b}); |
| 2283 | } else { |
| 2284 | edges.insert({b, a}); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | auto edge_badness = [&](const Segment_2& e) -> double { |
| 2289 | auto closest = segment_lookup.n_closest_input_segments(e, 2); |
| 2290 | if (closest.size() != 2) { |
| 2291 | throw std::runtime_error("Unable to locate two nearby edges"); |
| 2292 | } |
| 2293 | |
| 2294 | auto get_dir = [&](const Segment_2& s) { |
| 2295 | auto a = C(s.source()); |
| 2296 | auto b = C(s.target()); |
| 2297 | SK::Vector_2 v = b - a; |
| 2298 | double l = std::sqrt(v.squared_length()); |
| 2299 | if (l <= 1e-12) { |
| 2300 | return std::make_pair(SK::Vector_2(0, 0), 0.); |
| 2301 | } |
| 2302 | return std::make_pair(v / l, l); |
| 2303 | }; |
| 2304 | |
| 2305 | auto [own_dir, own_length] = get_dir(e); |
| 2306 | |
| 2307 | auto angle = [&](const SK::Vector_2& ov) { |
| 2308 | double d = std::abs(own_dir * ov); |
| 2309 | if (d > 1.0) { |
| 2310 | d = 1.0; |
| 2311 | } |
| 2312 | return std::acos(d); |
| 2313 | }; |
| 2314 | |
| 2315 | double best = std::numeric_limits<double>::infinity(); |
| 2316 | for (auto& s : closest) { |
| 2317 | auto [dv, dl] = get_dir(s); |
| 2318 | best = std::min(best, angle(dv)); |
| 2319 | } |
| 2320 | return (best + 0.01) / own_length; |
| 2321 | }; |
| 2322 | |
| 2323 | std::map<Segment_2, double, Segment_2_less> badnesses; |
| 2324 | for (auto& e : edges) { |
| 2325 | badnesses[e] = edge_badness(e); |
| 2326 | } |
no test coverage detected