From 554a6c14db102f751c392ea65120f71c6bc0f36e Mon Sep 17 00:00:00 2001 From: zmiao Date: Wed, 4 Mar 2020 23:15:53 +0200 Subject: [PATCH] [core] Remove unnecessary intermediate PolygonFeature --- src/mbgl/style/expression/within.cpp | 44 +++++----------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/src/mbgl/style/expression/within.cpp b/src/mbgl/style/expression/within.cpp index d81d30ae940..b9418e5665f 100644 --- a/src/mbgl/style/expression/within.cpp +++ b/src/mbgl/style/expression/within.cpp @@ -13,33 +13,6 @@ namespace mbgl { namespace { -class PolygonFeature : public GeometryTileFeature { -public: - const Feature& feature; - mutable optional 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 getValue(const std::string& /*key*/) const override { return optional(); } - const GeometryCollection& getGeometries() const override { - assert(geometry); - return *geometry; - } -}; - bool pointsWithinPolygons(const mbgl::GeometryTileFeature& feature, const mbgl::CanonicalTileID& canonical, const Feature::geometry_type& polygonGeoSet, @@ -134,10 +107,10 @@ struct PolygonInfo { WithinBBox bbox; }; -mbgl::optional getPolygonInfo(const PolygonFeature& polyFeature, - mbgl::style::expression::ParsingContext& ctx) { - if (polyFeature.isFeatureValid()) { - auto refinedGeoSet = convertGeometry(polyFeature, CanonicalTileID(0, 0, 0)); +mbgl::optional 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); } @@ -192,23 +165,20 @@ ParseResult Within::parse(const Convertible& value, ParsingContext& ctx) { return parsedValue->match( [&parsedValue, &ctx](const mapbox::geometry::geometry& 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(*parsedValue, std::move(ret->geometry), ret->bbox)); } return ParseResult(); }, [&parsedValue, &ctx](const mapbox::feature::feature& 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(*parsedValue, std::move(ret->geometry), ret->bbox)); } return ParseResult(); }, [&parsedValue, &ctx](const mapbox::feature::feature_collection& 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(*parsedValue, std::move(ret->geometry), ret->bbox)); } }