-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscalable_grid.h
52 lines (38 loc) · 1.69 KB
/
scalable_grid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef SCALABLE_GRID_H
#define SCALABLE_GRID_H
#include "grid.h"
#include "vector.h"
/**
This is an encapsulation of the generic grid that includes transforming floating point coordinates
to grid coordinates. The position where the item was inserted is also stored.
This scalable grid allows iteration of items within a certain floating-point distance without
concerning about the actual grid layout. It can further optimize iteration and it can do sorted
iteration of results.
*/
typedef struct {
void * item;
Vector position;
} ItemPositionPair;
typedef struct {
Grid grid;
ItemPositionPair * item_positions;
Vector scale;
Vector offset;
} ScalableGrid;
// Initializes a grid of size 0x0 with 0 capacity. Set a size, transform & capacity before using it.
void scalable_grid_initialize(ScalableGrid *);
// Set the capacity of the underlying grid & item positions.
void scalable_grid_set_capacity(ScalableGrid *, unsigned int);
// Apply grid_set_size on the grid
void scalable_grid_set_size(ScalableGrid *, GridXY);
// Set the transformation scale & offset based on a minimum & maximum position
void scalable_grid_set_transform(ScalableGrid *, Vector min, Vector max);
// Apply grid_clear on the grid
void scalable_grid_clear(ScalableGrid *);
// Store an item referenced by pointer at a given coordinate
void scalable_grid_put(ScalableGrid *, Vector, void *);
// Iterate all items that are within a given distance from a given coordinate.
void scalable_grid_iterate_items(ScalableGrid *, Vector position, float max_distance, void * param, void (*)(void * item, float distance, void * param));
// Deinitialize the scalable grid and its underlying grid.
void scalable_grid_deinitialize(ScalableGrid *);
#endif