Partition std::vector of 2D points

Suppose I have a std::vector<Point> where Point is struct Point { double x; double y;} I'd like to partition such a vector into groups (buckets), where all Points in same bucket have same Euclidean norm between each other (e.g dist(PointA,PointB) == X, where X is constant). I've decided to use std::map for such task with custom sorting operator:

struct ClosePoints {     bool operator()(Point const& A, Point const& B) const     {         bool same = dist(A,B) < x;         //If not close enough use lexical sort         return same ? false : std::tie(A.x, A.y) < std::tie(B.x,);      } } 

Partitioning code:

std::map<Point, std::list<Point>, ClosePoints> map; for(const auto& p : pointsVector)     map[p].push_back(p); 

After some testing and printing the buckets I've noticed that some points that do obey given Euclidean norm limit X ended in different buckets. I can't figure out why is it so ?

Replay

Category: c# Time: 2016-07-28 Views: 0

Related post

  • Use of raw pointer of std::vector 2015-01-06

    I am currently maintaining a code that makes liberal use of raw pointers where std::vector would be a better option. Worse, these pointers are not always properly handled (when run using Intel Inspector, I get the warning message "Warning: Only the f

  • passing pointer argument to std::vector function 2016-01-19

    I have a C++ application (let's call it "client") that does extensive use of double pointers to store and pass arrays among its functions and across several dlls. I need to integrate that with a C++ library that instead exposes function argument

  • What memory is occupied by std::vector if I only give it a pointer to my object? 2016-01-22

    There is something I don't understand and I would highly appreciate some clarification. I know there is a lot around about std::containers and memory not freed, but I still don't understand one particular fact. Below is a minimal program that represe

  • Delete all items from a c++ std::vector 2009-10-06

    I'm trying to delete everything from a std::vector by using the following code vector.erase( vector.begin(), vector.end() ); but it doesn't work. Update: Doesn't clear destruct the elements held by the vector? I don't want that, as I'm still using th

  • std::vector::size with glDrawElements crashes? 2012-04-15

    ( win32 / OpenGL 3.3 / GLSL 330 ) I decided after a long time of trying to do a graphical user interface using just opengl graphics to go back to a gui toolkit and so in the process have had to port alot of my code to win32. But I have a problem with

  • std::vector performance for pixel buffers 2012-05-01

    Doing software 2d pixel buffers, blitting, etc. Someone was telling me there's absolutely no overhead involved in using an std::vector to represent objects, I was wondering if std::vector is indeed a good container for pixel buffers or if I should in

  • How can I store spell & items using a std::vector implementation? 2012-11-05

    I'm following along with a book from GameInstitute right now, and it's asking me to: Allow the player to buy and carry healing potions and potions of fireball. You can add an Item array (after you define the item class) to the Player class for storin

  • How to remove an object from a std::vector 2013-01-01

    So I have a vector of bullets that show up on the screen and I do not want these bullets to live forever. I want them to "die as soon as they go off screen or collide with an enemy. How can I make sure they are removed from the array and no longer ta

  • std::vector memory manipulation with serialization and deserialization 2013-01-13

    This is my code and I would like to get it code reviewed. It is functional and behaves as expected. I pass some basic types to the Serialize() function and then deserialize the output to get back the original value. size_t returnSize(const char* s) {

  • Henry Hatsworth kind of blocks minigame, std::vector sorting or alternative? 2014-08-02

    I'm not sure if this is the right place to post this, or if I'm doing it right. But I believe I've kept to the rules. If not, please let me know and I'll remove my post or edit it accordingly. I'm building a mini game that's inspired by Henry Hatswor

  • Deleting values from std::vector of different types 2014-10-20

    I need to make a vector of different types and be able to delete the values (please ignore anything else but deleting the values for now). Is the next code safe to delete the values? #include <memory> #include <vector> #include <string>

  • std::vector of pointers with the rule of three 2014-11-11

    I have a class that has a std::vector of pointers, I'm NOT going to give any of those pointers to objects outside of it, I mean, I'm not going to share the pointers. - I was reading that isn't everywhere that we will use smart pointers and that raw p

  • Mergesort with std::vector 2014-12-21

    I made a mergesort implementation based on this code. Please review my C++ version. using size = std::size_t; template<typename T> void merge(std::vector<T>& v, size low, size mid, size high) { size i = low, j = mid+1; std::vector<T>

  • Queue with std::vector 2014-12-29

    How can I improve this code? template<class T> class Queue { public: Queue(const std::initializer_list<T>& i) :elem{i} {} int size() const { return elem.size(); } bool empty() const { return elem.empty(); } void enqueue(T&&); void

  • Defining std::vector::push_back(new Object) 2015-02-03

    Is this the best way to construct a vector of 2D points for return? I don't entirely understand new and delete so I'm concerned about any memory leaks that I might be incurring. std::vector<Point2D> results; results.reserve(max_results); ... inside

  • Using std::vectors to store textures 2015-04-23

    I need to write a TextureManager class which stores Texture objects; the problem is I'm using an std::map<Texture *, const char*> map to store Texture objects using a key. Searching elements through a map is not ideal because of performance issues (

  • How to properly pass sprites to a std::vector without destroying the sprite's texture in SFML? 2015-05-08

    From the official SFML tutorials, The White Box Problem:- "When you set the texture of a sprite, all it does internally is store a pointer to the texture instance. Therefore, if the texture is destroyed or moves elsewhere in memory, the sprite ends u

  • `std::vector` 'substring concatenator' 2015-05-29

    The point of this is to concatenate a vector of std::strings into one string starting at an index of the vector. std::string vectorSubstr(std::vector<std::string> vec, int startPos, char seperator) { std::stringstream ss; for (int i = startPos; i &l

  • std::vector Non-Array Implementation? 2015-05-31

    I've seen some posts on the StackExchange family of sites talking about std::vector implementations. They all seem to indicate that std::vector is implemented strictly as an array (in practice), and that C++ 2003 dictates contiguity of elements - pre

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.432 (s). 13 q(s)