Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Add getChildren, getClusterExpansionZoom, getLeaves methods - #16

Merged
mourner merged 15 commits into
masterfrom
get-children
Jul 10, 2018
Merged

mourner merged 15 commits into
masterfrom
get-children

Conversation

@mourner

@mourner mourner commented Jul 5, 2018 •

Copy link
Copy Markdown
Member

Follows #14. Closes #7. Closes #10. Closes #8. Closes #17. Closes #18.

@mourner mourner changed the title Add getChildren method for cluster lookup Add getChildren and getClusterExpansionZoom methods Jul 6, 2018
@mourner
mourner requested a review from kkaefer July 6, 2018 10:17
@mourner mourner changed the title Add getChildren and getClusterExpansionZoom methods Add getChildren, getClusterExpansionZoom, getLeaves methods Jul 6, 2018
Comment thread include/supercluster.hpp Outdated

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>());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to protect against missing point_count entries (and cluster_id below).

Comment thread include/supercluster.hpp Outdated
} else {
ss << num_points;
}
properties["point_count_abbreviated"] = ss.str();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use properties.emplace("point_count_abbreviated", ss.str()) here to eliminate default construction

Comment thread include/supercluster.hpp Outdated
std::uint32_t cluster_id,
std::uint32_t limit,
std::uint32_t offset,
std::uint32_t skipped) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add const to all arguments that are not modified

Comment thread include/supercluster.hpp Outdated
const auto &properties = child.properties;
const auto cluster_itr = properties.find("cluster");

if (cluster_itr != properties.end() && cluster_itr->second.get<bool>() == true) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to protect against the variant not being of type bool

Comment thread include/supercluster.hpp Outdated
} else {
// enter the cluster
const auto child_id = static_cast<std::uint32_t>(
properties.find("cluster_id")->second.get<std::uint64_t>());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protect against variant not being uint64_t

Comment thread include/supercluster.hpp Outdated

const auto zoom_iter = zooms.find(origin_zoom);
if (zoom_iter == zooms.end())
throw std::runtime_error("No cluster with the specified id.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add braces

Comment thread include/supercluster.hpp Outdated
GeoJSONFeatures children;

zoom.tree.within(origin.pos.x, origin.pos.y, r, [&, this](const auto &id) {
const auto &c = zoom.clusters[id];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to protect account clusters that can't be found here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No — this should be guaranteed by KDBush within.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool; can we add an assert before the operator[]?

Comment thread include/supercluster.hpp Outdated
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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and features here?

Comment thread include/supercluster.hpp Outdated
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>());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protect against it->second not being a uint64_t

@mourner

mourner commented Jul 6, 2018

Copy link
Copy Markdown
Member Author

@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.

@kkaefer

kkaefer commented Jul 9, 2018

Copy link
Copy Markdown
Member

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?

@mourner

mourner commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

@kkaefer good point! Refactored the code to use internal classes for all traversals rather than passing around GeoJSON. Ready for another review round.

@mourner

mourner commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

Forgot I need to do a const-marking pass — hold on...

@mourner
mourner requested a review from kkaefer July 9, 2018 17:53
@mourner

mourner commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

@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.

Comment thread include/supercluster.hpp Outdated

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_) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread include/supercluster.hpp Outdated
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 };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider inlining this

Comment thread include/supercluster.hpp Outdated
point<double> p{ x, y };
feature<double> f(
const point<double> p{ x, y };
const feature<double> f(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can return here directly instead of storing in a variable.

@mourner mourner mentioned this pull request Jul 10, 2018
Comment thread include/supercluster.hpp Outdated
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use emplace here, or construct the property_map directly with an initializer_list

Comment thread include/supercluster.hpp
} else {
ss << num_points;
}
properties.emplace("point_count_abbreviated", ss.str());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we generate this text here? It seems like something that should happen in the stylesheet, rather than in this library.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added before we implemented expressions, so I'd like to keep it for backwards compatibility.

@mourner
mourner merged commit c3702f5 into master Jul 10, 2018
@mourner
mourner deleted the get-children branch July 10, 2018 11:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants