util/checks.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/util/checks.h" | ||
| 2 | |||
| 3 | #include <stdexcept> | ||
| 4 | #include <string> | ||
| 5 | |||
| 6 | namespace terraingen { | ||
| 7 | |||
| 8 | namespace { | ||
| 9 | |||
| 10 | 164 | [[noreturn]] void Fail(std::string_view what, std::string_view requirement) { | |
| 11 | 820 | throw std::invalid_argument(std::string(what) + " must be " + std::string(requirement)); | |
| 12 | } | ||
| 13 | |||
| 14 | } // namespace | ||
| 15 | |||
| 16 | 55888935 | void RequirePositive(double value, std::string_view what) { | |
| 17 | 55888935 | if (!IsPositive(value)) { | |
| 18 | 122 | Fail(what, "positive and finite"); | |
| 19 | } | ||
| 20 | 55888813 | } | |
| 21 | |||
| 22 | 7363069 | void RequireNonNegative(double value, std::string_view what) { | |
| 23 | 7363069 | if (!IsNonNegative(value)) { | |
| 24 | 28 | Fail(what, "finite and not negative"); | |
| 25 | } | ||
| 26 | 7363041 | } | |
| 27 | |||
| 28 | 103414 | void RequireFinite(double value, std::string_view what) { | |
| 29 | 103414 | if (!std::isfinite(value)) { | |
| 30 | 3 | Fail(what, "finite"); | |
| 31 | } | ||
| 32 | 103411 | } | |
| 33 | |||
| 34 | 1010903 | void RequireUnitInterval(double value, std::string_view what) { | |
| 35 | 1010903 | if (!IsInUnitInterval(value)) { | |
| 36 | 11 | Fail(what, "in [0, 1]"); | |
| 37 | } | ||
| 38 | 1010892 | } | |
| 39 | |||
| 40 | } // namespace terraingen | ||
| 41 |