Repository navigation
Add getChildren, getClusterExpansionZoom, getLeaves methods - #16
Conversation
|
|
||
| if (cluster_itr != properties.end() && cluster_itr->second.get<bool>() == true) { | ||
| const auto count = static_cast<std::uint32_t>( | ||
| properties.find("point_count")->second.get<std::uint64_t>()); |
There was a problem hiding this comment.
We need to protect against missing point_count entries (and cluster_id below).
| } else { | ||
| ss << num_points; | ||
| } | ||
| properties["point_count_abbreviated"] = ss.str(); |
There was a problem hiding this comment.
Let's use properties.emplace("point_count_abbreviated", ss.str()) here to eliminate default construction
| std::uint32_t cluster_id, | ||
| std::uint32_t limit, | ||
| std::uint32_t offset, | ||
| std::uint32_t skipped) { |
There was a problem hiding this comment.
let's add const to all arguments that are not modified
| const auto &properties = child.properties; | ||
| const auto cluster_itr = properties.find("cluster"); | ||
|
|
||
| if (cluster_itr != properties.end() && cluster_itr->second.get<bool>() == true) { |
There was a problem hiding this comment.
We need to protect against the variant not being of type bool
| } else { | ||
| // enter the cluster | ||
| const auto child_id = static_cast<std::uint32_t>( | ||
| properties.find("cluster_id")->second.get<std::uint64_t>()); |
There was a problem hiding this comment.
protect against variant not being uint64_t
|
|
||
| const auto zoom_iter = zooms.find(origin_zoom); | ||
| if (zoom_iter == zooms.end()) | ||
| throw std::runtime_error("No cluster with the specified id."); |
| GeoJSONFeatures children; | ||
|
|
||
| zoom.tree.within(origin.pos.x, origin.pos.y, r, [&, this](const auto &id) { | ||
| const auto &c = zoom.clusters[id]; |
There was a problem hiding this comment.
Do we need to protect account clusters that can't be found here?
There was a problem hiding this comment.
No — this should be guaranteed by KDBush within.
There was a problem hiding this comment.
cool; can we add an assert before the operator[]?
| zoom.tree.within(origin.pos.x, origin.pos.y, r, [&, this](const auto &id) { | ||
| const auto &c = zoom.clusters[id]; | ||
| if (c.parent_id == cluster_id) { | ||
| children.push_back(c.num_points == 1 ? this->features[c.id] : c.toGeoJSON()); |
| const auto &properties = children[0].properties; | ||
| const auto it = properties.find("cluster_id"); | ||
| if (it != properties.end()) { | ||
| cluster_id = static_cast<std::uint32_t>(it->second.get<std::uint64_t>()); |
There was a problem hiding this comment.
protect against it->second not being a uint64_t
|
@kkaefer do we really need to protect against mistyped/missing properties when they're set in Supercluster and can't be different (and it's covered in tests)? I think I'd prefer this to throw a runtime error without guards than add a ton of boilerplate. |
|
Yup, because if they aren't present, the program will crash. How do we guarantee that the properties are there? If they're independent of feature properties, is there another way to pass through the properties that doesn't involve a lookup table by string? |
|
@kkaefer good point! Refactored the code to use internal classes for all traversals rather than passing around GeoJSON. Ready for another review round. |
|
Forgot I need to do a const-marking pass — hold on... |
|
@kkaefer as mentioned in Slack, the last commit triggers an internal compiler segfault in gcc 5, but I don't know how to diagnose what exactly causes it or how to proceed in this case. |
|
|
||
| Cluster(point<double> pos_, std::uint32_t num_points_, std::uint32_t id_) | ||
| Cluster(const point<double> pos_, const std::uint32_t num_points_, const std::uint32_t id_) | ||
| : pos(std::move(pos_)), num_points(num_points_), id(id_) { |
There was a problem hiding this comment.
if you make the point const, then you can't move it anymore. Given that a point only contains scalar values, move doesn't have any benefit anyway. Alternatively, you can change the signature to const point<double>& pos_, since we're creating a copy anyway.
| 360.0 * std::atan(std::exp((180.0 - pos.y * 360.0) * M_PI / 180)) / M_PI - 90.0; | ||
| point<double> p{ x, y }; | ||
| feature<double> f( | ||
| const point<double> p{ x, y }; |
| point<double> p{ x, y }; | ||
| feature<double> f( | ||
| const point<double> p{ x, y }; | ||
| const feature<double> f( |
There was a problem hiding this comment.
You can return here directly instead of storing in a variable.
| property_map properties{}; | ||
| properties["cluster"] = true; | ||
| properties["cluster_id"] = static_cast<std::uint64_t>(id); | ||
| properties["point_count"] = static_cast<std::uint64_t>(num_points); |
There was a problem hiding this comment.
Let's use emplace here, or construct the property_map directly with an initializer_list
| } else { | ||
| ss << num_points; | ||
| } | ||
| properties.emplace("point_count_abbreviated", ss.str()); |
There was a problem hiding this comment.
Why do we generate this text here? It seems like something that should happen in the stylesheet, rather than in this library.
There was a problem hiding this comment.
It was added before we implemented expressions, so I'd like to keep it for backwards compatibility.
Follows #14. Closes #7. Closes #10. Closes #8. Closes #17. Closes #18.