<commit_before>#include "MBVectorTileDecoder.h"
#include "core/MapBounds.h"
#include "core/BinaryData.h"
#include "core/Variant.h"
#include "components/Exceptions.h"
#include "geometry/Feature.h"
#include "geometry/Geometry.h"
#include "geometry/PointGeometry.h"
#include "geometry/MultiPointGeometry.h"
#include "graphics/Bitmap.h"
#include "styles/CompiledStyleSet.h"
#include "styles/CartoCSSStyleSet.h"
#include "vectortiles/utils/MapnikVTLogger.h"
#include "vectortiles/utils/VTBitmapLoader.h"
#include "vectortiles/utils/CartoCSSAssetLoader.h"
#include "utils/AssetPackage.h"
#include "utils/FileUtils.h"
#include "utils/Const.h"
#include "utils/Log.h"

#include <vt/Tile.h>
#include <mapnikvt/Value.h>
#include <mapnikvt/SymbolizerParser.h>
#include <mapnikvt/SymbolizerContext.h>
#include <mapnikvt/MBVTFeatureDecoder.h>
#include <mapnikvt/MBVTTileReader.h>
#include <mapnikvt/MapParser.h>
#include <cartocss/CartoCSSMapLoader.h>

#include <functional>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>

namespace {

    struct ValueConverter : boost::static_visitor<carto::Variant> {
        carto::Variant operator() (boost::blank) const { return carto::Variant(); }
        template <typename T> carto::Variant operator() (T val) const { return carto::Variant(val); }
    };

    typedef std::function<carto::MapPos(const cglib::vec2<float>& pos)> PointConversionFunction;

    std::vector<carto::MapPos> convertPoints(const PointConversionFunction& convertFn, const std::vector<cglib::vec2<float> >& poses) {
        std::vector<carto::MapPos> points;
        points.reserve(poses.size());
        std::transform(poses.begin(), poses.end(), std::back_inserter(points), convertFn);
        return points;
    }

    std::vector<std::vector<carto::MapPos> > convertPointsList(const PointConversionFunction& convertFn, const std::vector<std::vector<cglib::vec2<float> > >& posesList) {
        std::vector<std::vector<carto::MapPos> > pointsList;
        pointsList.reserve(posesList.size());
        std::transform(posesList.begin(), posesList.end(), std::back_inserter(pointsList), [&](const std::vector<cglib::vec2<float> >& poses) {
            return convertPoints(convertFn, poses);
        });
        return pointsList;
    }

    std::shared_ptr<carto::Geometry> convertGeometry(const PointConversionFunction& convertFn, const std::shared_ptr<const carto::mvt::Geometry>& mvtGeometry) {
        if (auto mvtPoint = std::dynamic_pointer_cast<const carto::mvt::PointGeometry>(mvtGeometry)) {
            std::vector<carto::MapPos> poses = convertPoints(convertFn, mvtPoint->getVertices());
            std::vector<std::shared_ptr<carto::PointGeometry> > points;
            points.reserve(poses.size());
            std::transform(poses.begin(), poses.end(), std::back_inserter(points), [](const carto::MapPos& pos) { return std::make_shared<carto::PointGeometry>(pos); });
            if (points.size() == 1) {
                return points.front();
            }
            else {
                return std::make_shared<carto::MultiPointGeometry>(points);
            }
        }
        return std::shared_ptr<carto::Geometry>();
    }

}

namespace carto {
    
    MBVectorTileDecoder::MBVectorTileDecoder(const std::shared_ptr<CompiledStyleSet>& compiledStyleSet) :
        _buffer(0),
        _cartoCSSLayerNamesIgnored(false),
        _layerNameOverride(),
        _logger(std::make_shared<MapnikVTLogger>("MBVectorTileDecoder")),
        _map(),
        _parameterValueMap(),
        _backgroundPattern(),
        _symbolizerContext(),<commit_msg>Support for line/polygon geometry in tiledecoder<commit_after>#include "MBVectorTileDecoder.h"
#include "core/MapBounds.h"
#include "core/BinaryData.h"
#include "core/Variant.h"
#include "components/Exceptions.h"
#include "geometry/Feature.h"
#include "geometry/Geometry.h"
#include "geometry/PointGeometry.h"
#include "geometry/LineGeometry.h"
#include "geometry/PolygonGeometry.h"
#include "geometry/MultiPointGeometry.h"
#include "geometry/MultiLineGeometry.h"
#include "geometry/MultiPolygonGeometry.h"
#include "graphics/Bitmap.h"
#include "styles/CompiledStyleSet.h"
#include "styles/CartoCSSStyleSet.h"
#include "vectortiles/utils/MapnikVTLogger.h"
#include "vectortiles/utils/VTBitmapLoader.h"
#include "vectortiles/utils/CartoCSSAssetLoader.h"
#include "utils/AssetPackage.h"
#include "utils/FileUtils.h"
#include "utils/Const.h"
#include "utils/Log.h"

#include <vt/Tile.h>
#include <mapnikvt/Value.h>
#include <mapnikvt/SymbolizerParser.h>
#include <mapnikvt/SymbolizerContext.h>
#include <mapnikvt/MBVTFeatureDecoder.h>
#include <mapnikvt/MBVTTileReader.h>
#include <mapnikvt/MapParser.h>
#include <cartocss/CartoCSSMapLoader.h>

#include <functional>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>

namespace {

    struct ValueConverter : boost::static_visitor<carto::Variant> {
        carto::Variant operator() (boost::blank) const { return carto::Variant(); }
        template <typename T> carto::Variant operator() (T val) const { return carto::Variant(val); }
    };

    typedef std::function<carto::MapPos(const cglib::vec2<float>& pos)> PointConversionFunction;

    std::vector<carto::MapPos> convertPoints(const PointConversionFunction& convertFn, const std::vector<cglib::vec2<float> >& poses) {
        std::vector<carto::MapPos> points;
        points.reserve(poses.size());
        std::transform(poses.begin(), poses.end(), std::back_inserter(points), convertFn);
        return points;
    }

    std::vector<std::vector<carto::MapPos> > convertPointsList(const PointConversionFunction& convertFn, const std::vector<std::vector<cglib::vec2<float> > >& posesList) {
        std::vector<std::vector<carto::MapPos> > pointsList;
        pointsList.reserve(posesList.size());
        std::transform(posesList.begin(), posesList.end(), std::back_inserter(pointsList), [&](const std::vector<cglib::vec2<float> >& poses) {
            return convertPoints(convertFn, poses);
        });
        return pointsList;
    }

    std::vector<std::vector<std::vector<carto::MapPos> > > convertPointsLists(const PointConversionFunction& convertFn, const std::vector<std::vector<std::vector<cglib::vec2<float> > > >& posesLists) {
        std::vector<std::vector<std::vector<carto::MapPos> > > pointsLists;
        pointsLists.reserve(posesLists.size());
        std::transform(posesLists.begin(), posesLists.end(), std::back_inserter(pointsLists), [&](const std::vector<std::vector<cglib::vec2<float> > >& posesList) {
            return convertPointsList(convertFn, posesList);
        });
        return pointsLists;
    }

    std::shared_ptr<carto::Geometry> convertGeometry(const PointConversionFunction& convertFn, const std::shared_ptr<const carto::mvt::Geometry>& mvtGeometry) {
        if (auto mvtPoint = std::dynamic_pointer_cast<const carto::mvt::PointGeometry>(mvtGeometry)) {
            std::vector<carto::MapPos> poses = convertPoints(convertFn, mvtPoint->getVertices());
            std::vector<std::shared_ptr<carto::PointGeometry> > points;
            points.reserve(poses.size());
            std::transform(poses.begin(), poses.end(), std::back_inserter(points), [](const carto::MapPos& pos) { return std::make_shared<carto::PointGeometry>(pos); });
            if (points.size() == 1) {
                return points.front();
            }
            else {
                return std::make_shared<carto::MultiPointGeometry>(points);
            }
        }
        else if (auto mvtLine = std::dynamic_pointer_cast<const carto::mvt::LineGeometry>(mvtGeometry)) {
            std::vector<std::vector<carto::MapPos>> posesList = convertPointsList(convertFn, mvtLine->getVerticesList());
            std::vector<std::shared_ptr<carto::LineGeometry> > lines;
            lines.reserve(posesList.size());
            std::transform(posesList.begin(), posesList.end(), std::back_inserter(lines), [](const std::vector<carto::MapPos>& poses) { return std::make_shared<carto::LineGeometry>(poses); });
            if (lines.size() == 1) {
                return lines.front();
            }
            else {
                return std::make_shared<carto::MultiLineGeometry>(lines);
            }
        }
        else if (auto mvtPolygon = std::dynamic_pointer_cast<const carto::mvt::PolygonGeometry>(mvtGeometry)) {
            std::vector<std::vector<std::vector<carto::MapPos> > > posesLists = convertPointsLists(convertFn, mvtPolygon->getPolygonList());
            std::vector<std::shared_ptr<carto::PolygonGeometry> > polygons;
            polygons.reserve(posesLists.size());
            std::transform(posesLists.begin(), posesLists.end(), std::back_inserter(polygons), [](const std::vector<std::vector<carto::MapPos> >& posesList) { return std::make_shared<carto::PolygonGeometry>(posesList); });
            if (polygons.size() == 1) {
                return polygons.front();
            }
            else {
                return std::make_shared<carto::MultiPolygonGeometry>(polygons);
            }
        }
        return std::shared_ptr<carto::Geometry>();
    }

}

namespace carto {
    
    MBVectorTileDecoder::MBVectorTileDecoder(const std::shared_ptr<CompiledStyleSet>& compiledStyleSet) :
        _buffer(0),
        _cartoCSSLayerNamesIgnored(false),
        _layerNameOverride(),
        _logger(std::make_shared<MapnikVTLogger>("MBVectorTileDecoder")),
        _map(),
        _parameterValueMap(),
        _backgroundPattern(),
        _symbolizerContext(),
{'fraction_non_alphanumeric': 0.14920535340861565, 'fraction_numerical': 0.001672940192388122, 'mean_word_length': 4.241095890410959, 'pattern_counts': {'":': 0, '<': 112, '<?xml version=': 0, '>': 116, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '666381', 'n_tokens_mistral': 3004, 'n_tokens_neox': 2940, 'n_words': 437}