| 1923 | } |
| 1924 | |
| 1925 | contour_line_type contour_line(const vector_2d &X, const vector_2d &Y, |
| 1926 | const vector_2d &Z, double level) { |
| 1927 | // create_contour is an external algorithm that seems to be generating |
| 1928 | // incoherent contour lines sometimes. So we regenerate the contour |
| 1929 | // until we get sometime that makes sense (something at least not out of |
| 1930 | // range). We then make sure this contour line matches the next contour |
| 1931 | // line. |
| 1932 | double x_min = min(X); |
| 1933 | double x_max = max(X); |
| 1934 | double y_min = min(X); |
| 1935 | double y_max = max(X); |
| 1936 | |
| 1937 | auto contour_is_in_bounds = [&](const contour_line_type &c) { |
| 1938 | double cx_min = min(c.first); |
| 1939 | double cx_max = max(c.first); |
| 1940 | double cy_min = min(c.second); |
| 1941 | double cy_max = max(c.second); |
| 1942 | const bool xminok = cx_min >= x_min; |
| 1943 | const bool xmaxok = cx_max <= x_max; |
| 1944 | const bool yminok = cy_min >= y_min; |
| 1945 | const bool ymaxok = cy_max <= y_max; |
| 1946 | return (xminok && xmaxok && yminok && ymaxok); |
| 1947 | }; |
| 1948 | |
| 1949 | auto contour_line_in_bounds = [&]() { |
| 1950 | QuadContourGenerator contour_generator(X, Y, Z, false, 0); |
| 1951 | auto c = contour_generator.create_contour(level); |
| 1952 | size_t attempts = 0; |
| 1953 | while (!contour_is_in_bounds(c) && attempts < 10) { |
| 1954 | std::cerr << "Contour out of bounds" << std::endl; |
| 1955 | QuadContourGenerator contour_generator2(X, Y, Z, false, 0); |
| 1956 | c = contour_generator2.create_contour(level); |
| 1957 | ++attempts; |
| 1958 | } |
| 1959 | return c; |
| 1960 | }; |
| 1961 | |
| 1962 | auto c = contour_line_in_bounds(); |
| 1963 | |
| 1964 | return c; |
| 1965 | } |
| 1966 | |
| 1967 | std::vector<contour_line_type> contourc(const vector_2d &x, |
| 1968 | const vector_2d &y, |
no test coverage detected