/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "stdafx.h" #include "editor/editorClickHeights.hpp" #include #include namespace click_heights { std::size_t settle(std::vector &Points, std::vector &Sources, std::function const &Ground) { std::size_t changed{0}; auto const count{std::min(Points.size(), Sources.size())}; for (std::size_t i = 0; i < count; ++i) { auto &point{Points[i]}; switch (Sources[i]) { case source::none: { auto const height{Ground(i)}; if (false == std::isfinite(height)) break; if (point.y != height) { point.y = height; ++changed; } Sources[i] = source::ground; break; } case source::level: if (i > 0 && point.y != Points[i - 1].y) { point.y = Points[i - 1].y; ++changed; } break; default: break; } } return changed; } bool guessed(std::vector const &Sources) { return std::find(Sources.begin(), Sources.end(), source::none) != Sources.end(); } std::size_t guessed_count(std::vector const &Sources) { return static_cast(std::count(Sources.begin(), Sources.end(), source::none)); } bool waiting(std::vector const &Sources, std::function const &Coming) { for (std::size_t i = 0; i < Sources.size(); ++i) if (Sources[i] == source::none && Coming(i)) return true; return false; } bool wait_on(std::vector const &Sources, std::function const &Coming, double const Waited) { return Waited < wait_longest && waiting(Sources, Coming); } } // namespace click_heights