# Holding Vectors

When I run my game it creates 40401 vectors to hold the places of game objects. I need to store 4 vectors, were 2 of the vector’s x values are 20 units apart and the other 2 vector’s y values are 50 units apart. All my vectors have this relationship in common, so I will need to create groups of vectors until they’re all in groups. I will then remove 1 vector from each group that has the same x/y value as another vector in a different group.

How would you recommend that I go about this? I don’t need step by step help, just someone to point me in a general direction; like how to store my groups of vectors.

Any help would be greatly appreciated.

Let me restate what I think is the task that results from what you’ve described, and correct me if my understanding is incorrect.

There is a List<> of objects (a class) where the class contains 4 Vector2 objects, thus creating a list of vector groups. The objective is to remove any Vector2 from a group which happens to coincide with a Vector2 of any other group.

The class which contains the Vector2 groups could be implemented with a small array in the class, and some unique identifier (maybe a serial number) for the group. In this way, removing a Vector2 from a group is a matter of removing an entry from a small array (sometimes making a list with 4 Vector2, or 3, or maybe even just 2.

These classes, vector groups, may be stored in a List<> of some 10,000 vector groups.

To find the coincident vectors, I would fashion a list of some struct or class which holds a vector2 and the ID of the group it belongs to. I would sort the source list (of the groups) by group ID, so they’re fast to look up using binary search. I would then fashion this proposed list by looping through all the groups, and adding every vector in each group to this proposed list (containing a single vector2 and the group ID it came from). I would then sort this result list by Vector2/group ID (custom sort order of a List<>). This would cause all coincident Vector2’s to appear together. After sorting, I would then loop through this result list, and each time the loop notices the current Vector2 is the same (or very close) to the previous Vector2, that becomes a candidate for removal (process the removal by lookup of the group, then remove within that group). When finished, all coincident Vector2’s should have been found and removed.