diff options
author | vvvv <vvvv@ydb.tech> | 2023-07-31 18:21:04 +0300 |
---|---|---|
committer | vvvv <vvvv@ydb.tech> | 2023-07-31 18:21:04 +0300 |
commit | dec41c40e51aa407edef81a3c566a5a15780fc49 (patch) | |
tree | 4f197b596b32f35eca368121f0dff913419da9af /library/cpp/geo/util.cpp | |
parent | 3ca8b54c96e09eb2b65be7f09675623438d559c7 (diff) | |
download | ydb-dec41c40e51aa407edef81a3c566a5a15780fc49.tar.gz |
YQL-16239 Move purecalc to public
Diffstat (limited to 'library/cpp/geo/util.cpp')
-rw-r--r-- | library/cpp/geo/util.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/library/cpp/geo/util.cpp b/library/cpp/geo/util.cpp new file mode 100644 index 0000000000..e8d0fc378e --- /dev/null +++ b/library/cpp/geo/util.cpp @@ -0,0 +1,34 @@ +#include "util.h" + +#include <math.h> +#include <util/generic/cast.h> +#include <util/generic/string.h> +#include <util/string/cast.h> +#include <utility> + +namespace NGeo { + bool TryPairFromString(std::pair<double, double>& res, TStringBuf inputStr, TStringBuf delimiter) { + TStringBuf lhsStr; + TStringBuf rhsStr; + + double lhs = NAN; + double rhs = NAN; + if ( + !inputStr.TrySplit(delimiter, lhsStr, rhsStr) || + !TryFromString<double>(lhsStr, lhs) || + !TryFromString<double>(rhsStr, rhs)) { + return false; + } + + res = {lhs, rhs}; + return true; + } + + std::pair<double, double> PairFromString(TStringBuf inputStr, TStringBuf delimiter) { + std::pair<double, double> res; + if (!TryPairFromString(res, inputStr, delimiter)) { + ythrow TBadCastException() << "Wrong point string: " << inputStr; + } + return res; + } +} // namespace NGeo |