aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/geo/util.cpp
diff options
context:
space:
mode:
authorvvvv <vvvv@ydb.tech>2023-07-31 18:21:04 +0300
committervvvv <vvvv@ydb.tech>2023-07-31 18:21:04 +0300
commitdec41c40e51aa407edef81a3c566a5a15780fc49 (patch)
tree4f197b596b32f35eca368121f0dff913419da9af /library/cpp/geo/util.cpp
parent3ca8b54c96e09eb2b65be7f09675623438d559c7 (diff)
downloadydb-dec41c40e51aa407edef81a3c566a5a15780fc49.tar.gz
YQL-16239 Move purecalc to public
Diffstat (limited to 'library/cpp/geo/util.cpp')
-rw-r--r--library/cpp/geo/util.cpp34
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