diff options
| author | vvvv <[email protected]> | 2023-07-31 18:21:04 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2023-07-31 18:21:04 +0300 |
| commit | dec41c40e51aa407edef81a3c566a5a15780fc49 (patch) | |
| tree | 4f197b596b32f35eca368121f0dff913419da9af /library/cpp/geo/size.cpp | |
| parent | 3ca8b54c96e09eb2b65be7f09675623438d559c7 (diff) | |
YQL-16239 Move purecalc to public
Diffstat (limited to 'library/cpp/geo/size.cpp')
| -rw-r--r-- | library/cpp/geo/size.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/library/cpp/geo/size.cpp b/library/cpp/geo/size.cpp new file mode 100644 index 00000000000..f1bd8ab7630 --- /dev/null +++ b/library/cpp/geo/size.cpp @@ -0,0 +1,31 @@ +#include "size.h" + +#include "util.h" + +namespace NGeo { + const double TSize::BadWidth = -1.; + const double TSize::BadHeight = -1.; + + namespace { + bool IsNonNegativeSize(double width, double height) { + return width >= 0. && height >= 0.; + } + } // namespace + + TSize TSize::Parse(TStringBuf s, TStringBuf delimiter) { + const auto& [width, height] = PairFromString(s, delimiter); + Y_ENSURE_EX(IsNonNegativeSize(width, height), TBadCastException() << "Negative window size"); + return {width, height}; + } + + TMaybe<TSize> TSize::TryParse(TStringBuf s, TStringBuf delimiter) { + std::pair<double, double> lonLat; + if (!TryPairFromString(lonLat, s, delimiter)) { + return {}; + } + if (!IsNonNegativeSize(lonLat.first, lonLat.second)) { + return {}; + } + return TSize{lonLat.first, lonLat.second}; + } +} // namespace NGeo |
