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/polygon.cpp | |
parent | 3ca8b54c96e09eb2b65be7f09675623438d559c7 (diff) | |
download | ydb-dec41c40e51aa407edef81a3c566a5a15780fc49.tar.gz |
YQL-16239 Move purecalc to public
Diffstat (limited to 'library/cpp/geo/polygon.cpp')
-rw-r--r-- | library/cpp/geo/polygon.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/library/cpp/geo/polygon.cpp b/library/cpp/geo/polygon.cpp new file mode 100644 index 00000000000..44e5c38b5f6 --- /dev/null +++ b/library/cpp/geo/polygon.cpp @@ -0,0 +1,28 @@ +#include "polygon.h" +namespace NGeo { + TMaybe<TGeoPolygon> TGeoPolygon::TryParse(TStringBuf s, TStringBuf llDelimiter, TStringBuf pointsDelimiter) { + TVector<TGeoPoint> points; + + for (const auto& pointString : StringSplitter(s).SplitByString(pointsDelimiter).SkipEmpty()) { + auto curPoint = TGeoPoint::TryParse(pointString.Token(), llDelimiter); + if (!curPoint) { + return {}; + } + points.push_back(*curPoint); + } + + if (points.size() < 3) { + return {}; + } + + return TGeoPolygon(points); + } + + TGeoPolygon TGeoPolygon::Parse(TStringBuf s, TStringBuf llDelimiter, TStringBuf pointsDelimiter) { + auto res = TGeoPolygon::TryParse(s, llDelimiter, pointsDelimiter); + if (!res) { + ythrow yexception() << "Can't parse polygon from input string: " << s; + } + return *res; + } +} // namespace NGeo |