Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ version of PackedRtree violates rule of three #327

Open
district10 opened this issue Oct 22, 2023 · 1 comment
Open

C++ version of PackedRtree violates rule of three #327

district10 opened this issue Oct 22, 2023 · 1 comment

Comments

@district10
Copy link

I'm using PackedRTree as spatial index, demo code:

struct GeojsonWithAutoSpatialIndex {
	std::vector<int> query_by_bbox(double xmin, double ymin, double ymin, double ymax) const {
		auto &tree = this->tree(); // rebuild spatial index if needed
		auto hits = tree.search(...); // not working, always empty hits
		...
	}

	void add_feature(...) {
		// ...
		tree_.reset(); // reset spatial index
	}
	void remove_feature(...);

private:
	FeatureCollection features;
	// auto spatial index
	mutable std::optional<PackedRtree> tree_;
	PackedRtree &tree() const {
		if (!tree_) {
			// code to build rtree from features here
			// ...
			tree_ = PackedRTree(nodes, extent); // BAD CODE HERE
		}
		return *tree_;
	}
};

I've already tested PackedRTree in other projects and it works well. But in this case, it's not working.

Strugged for a while, I find that PackedRTree violates rule of three.

PackedRTree should disable copy (like boost:noncopyable), or implement proper deepcopy (handle NodeItem *_nodeItems).

Or make it value semantic (cubao/headers#17).

@bjornharrtell
Copy link
Member

Thanks for noticing @district10, I think prefer the value semantic fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants