Hi there
I am developing a grid system that would generate non-overlapping grid cells. Upon creating a grid I want to be able to check to see if the potential grid overlaps any other grid cells. If it does then clamp the new grid cell to the already existent grid.

I can input data into a linkedList and then iterate through the list and print out the data. However I am finding it difficult to be able to access a single cell of the linkedlist to compare and before moving to the next element.
Is the best tactic to write a function that will automatically compare values as it iterates through the list?

Or is it better to return some kind of object or pointer from the list to the grid so that it can then check for potential collisions.

Many thanks

Recommended Answers

All 2 Replies

Is performance your concern?
Without knowing:
- What defines a grid cell? and
- How you define "overlap"?

I can give general comment that assuming to find out overlapping cells you'll have to compare all cells with all other cells, I suggest
1. some struct with better random access (vector, array, ...) instead of linked list.
2. sort the list, it always helps the search.

Many thanks for the comments I have managed to get it working. When I go to add a gridcell it scans through all the other cells and compares its position in 3D space to other cells if the grid is potentially going to overlap another it recalculates itself from the default size to a snap into the existing grid.

If it scans through the whole list and there is no overlaps it adds the grid to the end.

Sorry about the information i'm bad at explaining problems sometimes.

thanks for the help
Glad I got it sorted

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.