Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Address review findings/nit
Browse files Browse the repository at this point in the history
  • Loading branch information
zmiao committed Feb 11, 2020
1 parent 08a64c2 commit a868c3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
15 changes: 7 additions & 8 deletions expression-test/expression_test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,13 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) {
// Parse canonicalID
optional<CanonicalTileID> canonical;
if (evaluationContext.HasMember("canonicalID")) {
assert(evaluationContext["canonicalID"].IsObject());
assert(
evaluationContext["canonicalID"].HasMember("z") && evaluationContext["canonicalID"]["z"].IsNumber() &&
evaluationContext["canonicalID"].HasMember("x") && evaluationContext["canonicalID"]["x"].IsNumber() &&
evaluationContext["canonicalID"].HasMember("y") && evaluationContext["canonicalID"]["y"].IsNumber());
canonical = CanonicalTileID(evaluationContext["canonicalID"]["z"].GetUint(),
evaluationContext["canonicalID"]["x"].GetUint(),
evaluationContext["canonicalID"]["y"].GetUint());
const auto& canonicalIDObject = evaluationContext["canonicalID"];
assert(canonicalIDObject.IsObject());
assert(canonicalIDObject.HasMember("z") && canonicalIDObject["z"].IsNumber());
assert(canonicalIDObject.HasMember("x") && canonicalIDObject["x"].IsNumber());
assert(canonicalIDObject.HasMember("y") && canonicalIDObject["y"].IsNumber());
canonical = CanonicalTileID(
canonicalIDObject["z"].GetUint(), canonicalIDObject["x"].GetUint(), canonicalIDObject["y"].GetUint());
}

// Parse availableImages
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/expression/within.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Within final : public Expression {
public:
explicit Within(GeoJSON geojson);

~Within() final;
~Within() override;

EvaluationResult evaluate(const EvaluationContext&) const override;

Expand Down
11 changes: 5 additions & 6 deletions src/mbgl/style/expression/within.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool pointWithinPolygon(const mbgl::Point<double>& point, const mapbox::geometry
for (auto ring : polygon) {
auto size = ring.size();
// loop through every edge of the ring
for (decltype(size) i = 0; i < size - 1; ++i) {
for (std::size_t i = 0; i < size - 1; ++i) {
if (rayIntersect(point, ring[i], ring[i + 1])) {
within = !within;
}
Expand All @@ -55,8 +55,7 @@ bool pointWithinPolygon(const mbgl::Point<double>& point, const mapbox::geometry

bool pointWithinPolygons(const mbgl::Point<double>& point, const mapbox::geometry::multi_polygon<double>& polygons) {
for (auto polygon : polygons) {
auto within = pointWithinPolygon(point, polygon);
if (within) return true;
if (pointWithinPolygon(point, polygon)) return true;
}
return false;
}
Expand Down Expand Up @@ -128,7 +127,7 @@ namespace expression {

Within::Within(GeoJSON geojson) : Expression(Kind::Within, type::Boolean), geoJSONSource(std::move(geojson)) {}

Within::~Within() {}
Within::~Within() = default;

using namespace mbgl::style::conversion;

Expand All @@ -140,9 +139,9 @@ EvaluationResult Within::evaluate(const EvaluationContext& params) const {
// Currently only support Point/Points in Polygon/Polygons
if (geometryType == FeatureType::Point) {
return pointsWithinPolygons(*params.feature, *params.canonical, geoJSONSource);
} else {
mbgl::Log::Warning(mbgl::Event::General, "within expression currently only support 'Point' geometry type");
}
mbgl::Log::Warning(mbgl::Event::General, "within expression currently only support 'Point' geometry type");

return false;
}

Expand Down

0 comments on commit a868c3c

Please sign in to comment.