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

Commit

Permalink
[core] Remove unnecessary intermediate PolygonFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
zmiao committed Mar 4, 2020
1 parent f58cf85 commit 554a6c1
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions src/mbgl/style/expression/within.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@
namespace mbgl {
namespace {

class PolygonFeature : public GeometryTileFeature {
public:
const Feature& feature;
mutable optional<GeometryCollection> geometry;

PolygonFeature(const Feature& feature_, const CanonicalTileID& canonical) : feature(feature_) {
const auto type = apply_visitor(ToFeatureType(), feature.geometry);
if (type == FeatureType::Polygon) {
geometry = convertGeometry(feature.geometry, canonical);
assert(geometry);
geometry = fixupPolygons(*geometry);
} else {
mbgl::Log::Warning(mbgl::Event::General, "Provided feature does not contain polygon geometries.");
}
}

bool isFeatureValid() const { return geometry != nullopt; };
FeatureType getType() const override { return FeatureType::Polygon; }
const PropertyMap& getProperties() const override { return feature.properties; }
FeatureIdentifier getID() const override { return feature.id; }
optional<mbgl::Value> getValue(const std::string& /*key*/) const override { return optional<mbgl::Value>(); }
const GeometryCollection& getGeometries() const override {
assert(geometry);
return *geometry;
}
};

bool pointsWithinPolygons(const mbgl::GeometryTileFeature& feature,
const mbgl::CanonicalTileID& canonical,
const Feature::geometry_type& polygonGeoSet,
Expand Down Expand Up @@ -134,10 +107,10 @@ struct PolygonInfo {
WithinBBox bbox;
};

mbgl::optional<PolygonInfo> getPolygonInfo(const PolygonFeature& polyFeature,
mbgl::style::expression::ParsingContext& ctx) {
if (polyFeature.isFeatureValid()) {
auto refinedGeoSet = convertGeometry(polyFeature, CanonicalTileID(0, 0, 0));
mbgl::optional<PolygonInfo> getPolygonInfo(const Feature& polyFeature, mbgl::style::expression::ParsingContext& ctx) {
const auto type = apply_visitor(ToFeatureType(), polyFeature.geometry);
if (type == FeatureType::Polygon) {
auto refinedGeoSet = polyFeature.geometry;
auto bbox = calculateBBox(refinedGeoSet);
return PolygonInfo(std::move(refinedGeoSet), bbox);
}
Expand Down Expand Up @@ -192,23 +165,20 @@ ParseResult Within::parse(const Convertible& value, ParsingContext& ctx) {

return parsedValue->match(
[&parsedValue, &ctx](const mapbox::geometry::geometry<double>& geometrySet) {
PolygonFeature polyFeature(mbgl::Feature(geometrySet), CanonicalTileID(0, 0, 0));
if (auto ret = getPolygonInfo(polyFeature, ctx)) {
if (auto ret = getPolygonInfo(mbgl::Feature(geometrySet), ctx)) {
return ParseResult(std::make_unique<Within>(*parsedValue, std::move(ret->geometry), ret->bbox));
}
return ParseResult();
},
[&parsedValue, &ctx](const mapbox::feature::feature<double>& feature) {
PolygonFeature polyFeature(mbgl::Feature(feature), CanonicalTileID(0, 0, 0));
if (auto ret = getPolygonInfo(polyFeature, ctx)) {
if (auto ret = getPolygonInfo(mbgl::Feature(feature), ctx)) {
return ParseResult(std::make_unique<Within>(*parsedValue, std::move(ret->geometry), ret->bbox));
}
return ParseResult();
},
[&parsedValue, &ctx](const mapbox::feature::feature_collection<double>& features) {
for (const auto& feature : features) {
PolygonFeature polyFeature(mbgl::Feature(feature), CanonicalTileID(0, 0, 0));
if (auto ret = getPolygonInfo(polyFeature, ctx)) {
if (auto ret = getPolygonInfo(mbgl::Feature(feature), ctx)) {
return ParseResult(std::make_unique<Within>(*parsedValue, std::move(ret->geometry), ret->bbox));
}
}
Expand Down

0 comments on commit 554a6c1

Please sign in to comment.