// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int TOO_LESS_ARGUMENTS_FOR_FUNCTION; extern const int BAD_ARGUMENTS; extern const int ILLEGAL_TYPE_OF_ARGUMENT; } // namespace ErrorCodes namespace FunctionPointInPolygonDetail { template ColumnPtr callPointInPolygonImplWithPool(const IColumn & x, const IColumn & y, Polygon & polygon) { using Pool = ObjectPoolMap; /// C++11 has thread-safe function-local statics on most modern compilers. static Pool known_polygons; auto factory = [&polygon]() { GeoUtils::normalizePolygon(polygon); auto ptr = std::make_unique(polygon); /// To allocate memory. ptr->init(); return ptr.release(); }; std::string serialized_polygon = GeoUtils::serialize(polygon); auto impl = known_polygons.get(serialized_polygon, factory); return GeoUtils::pointInPolygon(x, y, *impl); } template ColumnPtr callPointInPolygonImpl(const IColumn & x, const IColumn & y, Polygon & polygon) { PointInPolygonImpl impl(polygon); return GeoUtils::pointInPolygon(x, y, impl); } } // namespace FunctionPointInPolygonDetail template