<commit_before>#include <mapbox/geojsonvt.hpp>
#include <mapbox/geojsonvt/clip.hpp>
#include <mapbox/geojsonvt/convert.hpp>
#include <mapbox/geojsonvt/transform.hpp>
#include <mapbox/geojsonvt/wrap.hpp>

#include <chrono>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <utility>

namespace mapbox {
namespace geojsonvt {

#pragma mark - GeoJSONVT

const Tile GeoJSONVT::emptyTile{};

namespace {

uint64_t toID(uint8_t z, uint32_t x, uint32_t y) {
    return (((1 << z) * y + x) * 32) + z;
}

ProjectedPoint intersectX(const ProjectedPoint& a, const ProjectedPoint& b, double x) {
    double y = (x - a.x) * (b.y - a.y) / (b.x - a.x) + a.y;
    return ProjectedPoint(x, y, 1.0);
}

ProjectedPoint intersectY(const ProjectedPoint& a, const ProjectedPoint& b, double y) {
    double x = (y - a.y) * (b.x - a.x) / (b.y - a.y) + a.x;
    return ProjectedPoint(x, y, 1.0);
}

// checks whether a tile is a whole-area fill after clipping; if it is, there's no sense slicing it
// further
bool isClippedSquare(Tile& tile, const uint16_t extent, const uint16_t buffer) {
    const auto& features = tile.source;
    if (features.size() != 1) {
        return false;
    }

    const auto& feature = features.front();
    if (feature.type != ProjectedFeatureType::Polygon) {
        return false;
    }
    const auto& rings = feature.geometry.get<ProjectedRings>();
    if (rings.size() > 1) {
        return false;
    }

    const auto& ring = rings.front();

    if (ring.points.size() != 5) {
        return false;
    }

    for (const auto& pt : ring.points) {
        auto p = Transform::transformPoint(pt, extent, tile.z2, tile.tx, tile.ty);
        if ((p.x != -static_cast<int>(buffer) && p.x != extent + buffer) ||
            (p.y != -static_cast<int>(buffer) && p.y != extent + buffer)) {
            return false;
        }
    }

    return true;
}

class Timer {
    using Clock = std::chrono::steady_clock;

    Clock::time_point start = Clock::now();

public:
    void report(const std::string& name) {
        Clock::duration duration = Clock::now() - start;
        auto ms = std::chrono::duration_cast<std::chrono::microseconds>(duration);
        printf("%s: %.2fms\n", name.c_str(), double(ms.count()) / 1000);
        start += duration;
    }
};

struct FeatureStackItem {
    std::vector<ProjectedFeature> features;
    uint32_t z;
    uint32_t x;
    uint32_t y;

    template <typename T>
    FeatureStackItem(T && features_, uint32_t z_, uint32_t x_, uint32_t y_)
        : features(std::forward<T>(features_)), z(z_), x(x_), y(y_) {
    }
};
} // namespace

GeoJSONVT::GeoJSONVT(std::vector<ProjectedFeature> const& features_, Options options_)
    : options(std::move(options_)) {

#ifdef DEBUG
    printf("index: maxZoom: %d, maxPoints: %d\n", options.indexMaxZoom, options.indexMaxPoints);
    Timer timer;
#endif

    auto features = Wrap::wrap(features_, double(options.buffer) / options.extent, intersectX);

    // start slicing from the top tile down
    if (!features.empty()) {<commit_msg>consistently use uint8_t for zoom to avoid -Wconversion warning<commit_after>#include <mapbox/geojsonvt.hpp>
#include <mapbox/geojsonvt/clip.hpp>
#include <mapbox/geojsonvt/convert.hpp>
#include <mapbox/geojsonvt/transform.hpp>
#include <mapbox/geojsonvt/wrap.hpp>

#include <chrono>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <utility>

namespace mapbox {
namespace geojsonvt {

#pragma mark - GeoJSONVT

const Tile GeoJSONVT::emptyTile{};

namespace {

uint64_t toID(uint8_t z, uint32_t x, uint32_t y) {
    return (((1 << z) * y + x) * 32) + z;
}

ProjectedPoint intersectX(const ProjectedPoint& a, const ProjectedPoint& b, double x) {
    double y = (x - a.x) * (b.y - a.y) / (b.x - a.x) + a.y;
    return ProjectedPoint(x, y, 1.0);
}

ProjectedPoint intersectY(const ProjectedPoint& a, const ProjectedPoint& b, double y) {
    double x = (y - a.y) * (b.x - a.x) / (b.y - a.y) + a.x;
    return ProjectedPoint(x, y, 1.0);
}

// checks whether a tile is a whole-area fill after clipping; if it is, there's no sense slicing it
// further
bool isClippedSquare(Tile& tile, const uint16_t extent, const uint16_t buffer) {
    const auto& features = tile.source;
    if (features.size() != 1) {
        return false;
    }

    const auto& feature = features.front();
    if (feature.type != ProjectedFeatureType::Polygon) {
        return false;
    }
    const auto& rings = feature.geometry.get<ProjectedRings>();
    if (rings.size() > 1) {
        return false;
    }

    const auto& ring = rings.front();

    if (ring.points.size() != 5) {
        return false;
    }

    for (const auto& pt : ring.points) {
        auto p = Transform::transformPoint(pt, extent, tile.z2, tile.tx, tile.ty);
        if ((p.x != -static_cast<int>(buffer) && p.x != extent + buffer) ||
            (p.y != -static_cast<int>(buffer) && p.y != extent + buffer)) {
            return false;
        }
    }

    return true;
}

class Timer {
    using Clock = std::chrono::steady_clock;

    Clock::time_point start = Clock::now();

public:
    void report(const std::string& name) {
        Clock::duration duration = Clock::now() - start;
        auto ms = std::chrono::duration_cast<std::chrono::microseconds>(duration);
        printf("%s: %.2fms\n", name.c_str(), double(ms.count()) / 1000);
        start += duration;
    }
};

struct FeatureStackItem {
    std::vector<ProjectedFeature> features;
    uint8_t z;
    uint32_t x;
    uint32_t y;

    template <typename T>
    FeatureStackItem(T && features_, uint8_t z_, uint32_t x_, uint32_t y_)
        : features(std::forward<T>(features_)), z(z_), x(x_), y(y_) {
    }
};
} // namespace

GeoJSONVT::GeoJSONVT(std::vector<ProjectedFeature> const& features_, Options options_)
    : options(std::move(options_)) {

#ifdef DEBUG
    printf("index: maxZoom: %d, maxPoints: %d\n", options.indexMaxZoom, options.indexMaxPoints);
    Timer timer;
#endif

    auto features = Wrap::wrap(features_, double(options.buffer) / options.extent, intersectX);

    // start slicing from the top tile down
    if (!features.empty()) {
{'fraction_non_alphanumeric': 0.14974210186976145, 'fraction_numerical': 0.012411347517730497, 'mean_word_length': 3.232605729877217, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, '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': '2530473', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2134, 'n_words': 548}