Skip to content

Commit

Permalink
Update to geometry v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Nov 8, 2018
1 parent ab34b99 commit 274ec13
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .mason
Submodule .mason updated 156 files
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export MASON_DIR = $(shell pwd)/.mason
export MASON = $(MASON_DIR)/mason

VARIANT = variant 1.1.5
GEOMETRY = geometry 0.9.2
GEOMETRY = geometry 1.0.0
KDBUSH = kdbush 0.1.3
RAPIDJSON = rapidjson 1.1.0

Expand Down
8 changes: 4 additions & 4 deletions bench.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <mapbox/geometry/feature.hpp>
#include <mapbox/feature.hpp>
#include <rapidjson/document.h>
#include <rapidjson/filereadstream.h>

Expand All @@ -24,15 +24,15 @@ int main() {

const auto &json_features = d["features"];

mapbox::geometry::feature_collection<double> features;
mapbox::feature::feature_collection<double> features;
features.reserve(json_features.Size());

for (auto itr = json_features.Begin(); itr != json_features.End(); ++itr) {
const auto &json_coords = (*itr)["geometry"]["coordinates"];
const auto lng = json_coords[0].GetDouble();
const auto lat = json_coords[1].GetDouble();
mapbox::geometry::point<double> point(lng, lat);
mapbox::geometry::feature<double> feature{ point };
mapbox::feature::feature<double> feature{ point };
features.push_back(feature);
}
timer("convert to geometry.hpp");
Expand All @@ -43,7 +43,7 @@ int main() {

timer("total supercluster time");

mapbox::geometry::feature_collection<std::int16_t> tile = index.getTile(0, 0, 0);
mapbox::feature::feature_collection<std::int16_t> tile = index.getTile(0, 0, 0);
timer("query zero tile");
std::cerr << tile.size() << " features in tile 0-0-0:\n";

Expand Down
13 changes: 7 additions & 6 deletions include/supercluster.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <kdbush.hpp>
#include <mapbox/geometry/feature.hpp>
#include <mapbox/feature.hpp>
#include <mapbox/geometry/point_arithmetic.hpp>

#include <algorithm>
Expand All @@ -20,6 +20,7 @@ namespace mapbox {
namespace supercluster {

using namespace mapbox::geometry;
using namespace mapbox::feature;

struct Cluster {
const point<double> pos;
Expand All @@ -32,12 +33,12 @@ struct Cluster {
: pos(pos_), num_points(num_points_), id(id_) {
}

feature<double> toGeoJSON() const {
mapbox::feature::feature<double> toGeoJSON() const {
const double x = (pos.x - 0.5) * 360.0;
const double y =
360.0 * std::atan(std::exp((180.0 - pos.y * 360.0) * M_PI / 180)) / M_PI - 90.0;
return { point<double>{ x, y }, getProperties(),
std::experimental::make_optional(identifier(static_cast<std::uint64_t>(id))) };
identifier(static_cast<std::uint64_t>(id)) };
}

property_map getProperties() const {
Expand Down Expand Up @@ -111,11 +112,11 @@ struct Options {

class Supercluster {
using GeoJSONPoint = point<double>;
using GeoJSONFeature = feature<double>;
using GeoJSONFeature = mapbox::feature::feature<double>;
using GeoJSONFeatures = feature_collection<double>;

using TilePoint = point<std::int16_t>;
using TileFeature = feature<std::int16_t>;
using TileFeature = mapbox::feature::feature<std::int16_t>;
using TileFeatures = feature_collection<std::int16_t>;

public:
Expand Down Expand Up @@ -167,7 +168,7 @@ class Supercluster {
} else {
result.emplace_back(
point, c.getProperties(),
std::experimental::make_optional(identifier(static_cast<std::uint64_t>(c.id))));
identifier(static_cast<std::uint64_t>(c.id)));
}
};

Expand Down
8 changes: 4 additions & 4 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <mapbox/geometry/feature.hpp>
#include <mapbox/feature.hpp>
#include <rapidjson/document.h>
#include <rapidjson/filereadstream.h>

Expand All @@ -19,23 +19,23 @@ int main() {

const auto &json_features = d["features"];

mapbox::geometry::feature_collection<double> features;
mapbox::feature::feature_collection<double> features;
features.reserve(json_features.Size());

for (auto itr = json_features.Begin(); itr != json_features.End(); ++itr) {
const auto &json_coords = (*itr)["geometry"]["coordinates"];
const auto lng = json_coords[0].GetDouble();
const auto lat = json_coords[1].GetDouble();
mapbox::geometry::point<double> point(lng, lat);
mapbox::geometry::feature<double> feature{ point };
mapbox::feature::feature<double> feature{ point };
feature.properties["name"] = std::string((*itr)["properties"]["name"].GetString());
features.push_back(feature);
}

mapbox::supercluster::Options options;
mapbox::supercluster::Supercluster index(features, options);

mapbox::geometry::feature_collection<std::int16_t> tile = index.getTile(0, 0, 0);
mapbox::feature::feature_collection<std::int16_t> tile = index.getTile(0, 0, 0);
assert(tile.size() == 39);

std::uint64_t num_points = 0;
Expand Down

0 comments on commit 274ec13

Please sign in to comment.