<commit_before>#include "node.h"                       // for NODE_SET_PROTOTYPE_METHOD, etc
#include <node_buffer.h>
#include <node_version.h>

#include "utils.hpp"
#include "mapnik_map.hpp"
#include "mapnik_image.hpp"
#include "mapnik_grid.hpp"
#include "mapnik_feature.hpp"
#include "mapnik_cairo_surface.hpp"
#ifdef SVG_RENDERER
#include <mapnik/svg/output/svg_renderer.hpp>
#endif

#include "mapnik_datasource.hpp"

#include "mapnik_vector_tile.hpp"
#include "vector_tile_projection.hpp"
#include "vector_tile_datasource.hpp"
#include "vector_tile_util.hpp"
#include "vector_tile.pb.h"

#include <mapnik/map.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/geom_util.hpp>
#include <mapnik/version.hpp>
#include <mapnik/request.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/agg_renderer.hpp>      // for agg_renderer
#include <mapnik/grid/grid.hpp>         // for hit_grid, grid
#include <mapnik/grid/grid_renderer.hpp>  // for grid_renderer
#include <mapnik/box2d.hpp>
#include <mapnik/scale_denominator.hpp>

#ifdef HAVE_CAIRO
#include <mapnik/cairo_renderer.hpp>
#include <cairo.h>
#ifdef CAIRO_HAS_SVG_SURFACE
#include <cairo-svg.h>
#endif // CAIRO_HAS_SVG_SURFACE
#endif

#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>

#include <set>                          // for set, etc
#include <sstream>                      // for operator<<, basic_ostream, etc
#include <string>                       // for string, char_traits, etc
#include <exception>                    // for exception
#include <vector>                       // for vector


Persistent<FunctionTemplate> VectorTile::constructor;

void VectorTile::Initialize(Handle<Object> target) {
    HandleScope scope;
    constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(VectorTile::New));
    constructor->InstanceTemplate()->SetInternalFieldCount(1);
    constructor->SetClassName(String::NewSymbol("VectorTile"));
    NODE_SET_PROTOTYPE_METHOD(constructor, "render", render);
    NODE_SET_PROTOTYPE_METHOD(constructor, "setData", setData);
    NODE_SET_PROTOTYPE_METHOD(constructor, "setDataSync", setDataSync);
    NODE_SET_PROTOTYPE_METHOD(constructor, "getData", getData);
    NODE_SET_PROTOTYPE_METHOD(constructor, "query", query);
    NODE_SET_PROTOTYPE_METHOD(constructor, "names", names);
    NODE_SET_PROTOTYPE_METHOD(constructor, "toJSON", toJSON);
    NODE_SET_PROTOTYPE_METHOD(constructor, "toGeoJSON", toGeoJSON);
#ifdef PROTOBUF_FULL
    NODE_SET_PROTOTYPE_METHOD(constructor, "toString", toString);
#endif

    // common to mapnik.Image
    NODE_SET_PROTOTYPE_METHOD(constructor, "width", width);
    NODE_SET_PROTOTYPE_METHOD(constructor, "height", height);
    NODE_SET_PROTOTYPE_METHOD(constructor, "painted", painted);
    NODE_SET_PROTOTYPE_METHOD(constructor, "clear", clear);
    NODE_SET_PROTOTYPE_METHOD(constructor, "clearSync", clear);
    NODE_SET_PROTOTYPE_METHOD(constructor, "isSolid", isSolid);
    NODE_SET_PROTOTYPE_METHOD(constructor, "isSolidSync", isSolidSync);
    target->Set(String::NewSymbol("VectorTile"),constructor->GetFunction());
}

VectorTile::VectorTile(int z, int x, int y, unsigned w, unsigned h) :
    ObjectWrap(),
    z_(z),
    x_(x),
    y_(y),
    tiledata_(),
    width_(w),
    height_(h),
    painted_(false) {}

VectorTile::~VectorTile() { }

Handle<Value> VectorTile::New(const Arguments& args)
{
    HandleScope scope;
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args.Length() == 3)
    {
        if (!args[0]->IsNumber() ||
            !args[1]->IsNumber() ||
            !args[2]->IsNumber())
            return ThrowException(Exception::Error(
                                      String::New("required args (z, x, and y) must be a integers")));
        VectorTile* d = new VectorTile(args[0]->IntegerValue(),
                                   args[1]->IntegerValue(),
                                   args[2]->IntegerValue()
            );
        d->Wrap(args.This());
        return args.This();
    }
    else
    {
        return ThrowException(Exception::Error(
                                  String::New("please provide a z, x, y")));
    }
    return Undefined();
}

#ifdef PROTOBUF_FULL
Handle<Value> VectorTile::toString(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    mapnik::vector::tile const& tiledata = d->get_tile();
    return scope.Close(String::New(tiledata.DebugString().c_str()));
}
#endif

Handle<Value> VectorTile::names(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    mapnik::vector::tile const& tiledata = d->get_tile();
    Local<Array> arr = Array::New(tiledata.layers_size());
    for (int i=0; i < tiledata.layers_size(); ++i)
    {
        mapnik::vector::tile_layer const& layer = tiledata.layers(i);
        arr->Set(i, String::New(layer.name().c_str()));
    }
    return scope.Close(arr);
}

Handle<Value> VectorTile::width(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Integer::New(d->width()));
}

Handle<Value> VectorTile::height(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Integer::New(d->height()));
}

Handle<Value> VectorTile::painted(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Boolean::New(d->painted()));
}

Handle<Value> VectorTile::query(const Arguments& args)
{
    HandleScope scope;
    if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
    {
        return ThrowException(Exception::Error(
                                  String::New("expects lon,lat args")));
    }
    double tolerance = 10.0; // meters
    if (args.Length() > 2)
    {
        Local<Object> options = Object::New();
        if (!args[2]->IsObject())
        {
            return ThrowException(Exception::TypeError(String::New("optional third argument must be an options object")));<commit_msg>vtile.query tolerance default should be 0.0<commit_after>#include "node.h"                       // for NODE_SET_PROTOTYPE_METHOD, etc
#include <node_buffer.h>
#include <node_version.h>

#include "utils.hpp"
#include "mapnik_map.hpp"
#include "mapnik_image.hpp"
#include "mapnik_grid.hpp"
#include "mapnik_feature.hpp"
#include "mapnik_cairo_surface.hpp"
#ifdef SVG_RENDERER
#include <mapnik/svg/output/svg_renderer.hpp>
#endif

#include "mapnik_datasource.hpp"

#include "mapnik_vector_tile.hpp"
#include "vector_tile_projection.hpp"
#include "vector_tile_datasource.hpp"
#include "vector_tile_util.hpp"
#include "vector_tile.pb.h"

#include <mapnik/map.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/geom_util.hpp>
#include <mapnik/version.hpp>
#include <mapnik/request.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/agg_renderer.hpp>      // for agg_renderer
#include <mapnik/grid/grid.hpp>         // for hit_grid, grid
#include <mapnik/grid/grid_renderer.hpp>  // for grid_renderer
#include <mapnik/box2d.hpp>
#include <mapnik/scale_denominator.hpp>

#ifdef HAVE_CAIRO
#include <mapnik/cairo_renderer.hpp>
#include <cairo.h>
#ifdef CAIRO_HAS_SVG_SURFACE
#include <cairo-svg.h>
#endif // CAIRO_HAS_SVG_SURFACE
#endif

#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>

#include <set>                          // for set, etc
#include <sstream>                      // for operator<<, basic_ostream, etc
#include <string>                       // for string, char_traits, etc
#include <exception>                    // for exception
#include <vector>                       // for vector


Persistent<FunctionTemplate> VectorTile::constructor;

void VectorTile::Initialize(Handle<Object> target) {
    HandleScope scope;
    constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(VectorTile::New));
    constructor->InstanceTemplate()->SetInternalFieldCount(1);
    constructor->SetClassName(String::NewSymbol("VectorTile"));
    NODE_SET_PROTOTYPE_METHOD(constructor, "render", render);
    NODE_SET_PROTOTYPE_METHOD(constructor, "setData", setData);
    NODE_SET_PROTOTYPE_METHOD(constructor, "setDataSync", setDataSync);
    NODE_SET_PROTOTYPE_METHOD(constructor, "getData", getData);
    NODE_SET_PROTOTYPE_METHOD(constructor, "query", query);
    NODE_SET_PROTOTYPE_METHOD(constructor, "names", names);
    NODE_SET_PROTOTYPE_METHOD(constructor, "toJSON", toJSON);
    NODE_SET_PROTOTYPE_METHOD(constructor, "toGeoJSON", toGeoJSON);
#ifdef PROTOBUF_FULL
    NODE_SET_PROTOTYPE_METHOD(constructor, "toString", toString);
#endif

    // common to mapnik.Image
    NODE_SET_PROTOTYPE_METHOD(constructor, "width", width);
    NODE_SET_PROTOTYPE_METHOD(constructor, "height", height);
    NODE_SET_PROTOTYPE_METHOD(constructor, "painted", painted);
    NODE_SET_PROTOTYPE_METHOD(constructor, "clear", clear);
    NODE_SET_PROTOTYPE_METHOD(constructor, "clearSync", clear);
    NODE_SET_PROTOTYPE_METHOD(constructor, "isSolid", isSolid);
    NODE_SET_PROTOTYPE_METHOD(constructor, "isSolidSync", isSolidSync);
    target->Set(String::NewSymbol("VectorTile"),constructor->GetFunction());
}

VectorTile::VectorTile(int z, int x, int y, unsigned w, unsigned h) :
    ObjectWrap(),
    z_(z),
    x_(x),
    y_(y),
    tiledata_(),
    width_(w),
    height_(h),
    painted_(false) {}

VectorTile::~VectorTile() { }

Handle<Value> VectorTile::New(const Arguments& args)
{
    HandleScope scope;
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args.Length() == 3)
    {
        if (!args[0]->IsNumber() ||
            !args[1]->IsNumber() ||
            !args[2]->IsNumber())
            return ThrowException(Exception::Error(
                                      String::New("required args (z, x, and y) must be a integers")));
        VectorTile* d = new VectorTile(args[0]->IntegerValue(),
                                   args[1]->IntegerValue(),
                                   args[2]->IntegerValue()
            );
        d->Wrap(args.This());
        return args.This();
    }
    else
    {
        return ThrowException(Exception::Error(
                                  String::New("please provide a z, x, y")));
    }
    return Undefined();
}

#ifdef PROTOBUF_FULL
Handle<Value> VectorTile::toString(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    mapnik::vector::tile const& tiledata = d->get_tile();
    return scope.Close(String::New(tiledata.DebugString().c_str()));
}
#endif

Handle<Value> VectorTile::names(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    mapnik::vector::tile const& tiledata = d->get_tile();
    Local<Array> arr = Array::New(tiledata.layers_size());
    for (int i=0; i < tiledata.layers_size(); ++i)
    {
        mapnik::vector::tile_layer const& layer = tiledata.layers(i);
        arr->Set(i, String::New(layer.name().c_str()));
    }
    return scope.Close(arr);
}

Handle<Value> VectorTile::width(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Integer::New(d->width()));
}

Handle<Value> VectorTile::height(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Integer::New(d->height()));
}

Handle<Value> VectorTile::painted(const Arguments& args)
{
    HandleScope scope;
    VectorTile* d = node::ObjectWrap::Unwrap<VectorTile>(args.This());
    return scope.Close(Boolean::New(d->painted()));
}

Handle<Value> VectorTile::query(const Arguments& args)
{
    HandleScope scope;
    if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
    {
        return ThrowException(Exception::Error(
                                  String::New("expects lon,lat args")));
    }
    double tolerance = 0.0; // meters
    if (args.Length() > 2)
    {
        Local<Object> options = Object::New();
        if (!args[2]->IsObject())
        {
            return ThrowException(Exception::TypeError(String::New("optional third argument must be an options object")));
{'fraction_non_alphanumeric': 0.14381349925179177, 'fraction_numerical': 0.0029140741907537214, 'mean_word_length': 3.7593703148425788, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '487565', 'n_tokens_mistral': 4087, 'n_tokens_neox': 3992, 'n_words': 754}