|
degate 0.1.1
|
Represents a grid with equidistant spacing between grid lines. More...
#include <RegularGrid.h>

Public Member Functions | |
| RegularGrid (Grid::ORIENTATION orientation) | |
| virtual | ~RegularGrid () |
| virtual grid_iter | begin () const |
| Get an iterator to iterate over grid offsets. | |
| virtual grid_iter | end () const |
| Get an end marker for ther iteration. | |
| virtual void | clear () |
| Clear the grid. | |
| virtual int | get_min () const |
| virtual int | get_max () const |
| virtual void | set_range (int min, int max) |
| virtual void | set_distance (double distance) |
| virtual double | get_distance () const |
| virtual int | snap_to_grid (int pos) const |
| Get the nearest offset, that is on grid. | |
Private Member Functions | |
| void | precalc_steps () |
Private Attributes | |
| double | distance |
| int | min |
| int | max |
| grid_set | grid_offsets |
Represents a grid with equidistant spacing between grid lines.
Definition at line 36 of file RegularGrid.h.
| degate::RegularGrid::RegularGrid | ( | Grid::ORIENTATION | orientation | ) | [inline] |
Definition at line 44 of file RegularGrid.h.
References distance, max, and min.
: Grid(orientation) { min = 0; max = 0; distance = 0; }
| virtual degate::RegularGrid::~RegularGrid | ( | ) | [inline, virtual] |
Definition at line 50 of file RegularGrid.h.
{}
| virtual grid_iter degate::RegularGrid::begin | ( | ) | const [inline, virtual] |
Get an iterator to iterate over grid offsets.
Implements degate::Grid.
Definition at line 52 of file RegularGrid.h.
References grid_offsets.
{ return grid_offsets.begin(); }
| virtual void degate::RegularGrid::clear | ( | ) | [inline, virtual] |
Clear the grid.
Implements degate::Grid.
Definition at line 54 of file RegularGrid.h.
References distance, grid_offsets, max, and min.
{
distance = 0;
min = max = 0;
grid_offsets.clear();
}
| virtual grid_iter degate::RegularGrid::end | ( | ) | const [inline, virtual] |
Get an end marker for ther iteration.
Implements degate::Grid.
Definition at line 53 of file RegularGrid.h.
References grid_offsets.
{ return grid_offsets.end(); }
| virtual double degate::RegularGrid::get_distance | ( | ) | const [inline, virtual] |
| virtual int degate::RegularGrid::get_max | ( | ) | const [inline, virtual] |
| virtual int degate::RegularGrid::get_min | ( | ) | const [inline, virtual] |
| void RegularGrid::precalc_steps | ( | ) | [private] |
Definition at line 27 of file RegularGrid.cc.
References distance, grid_offsets, max, and min.
Referenced by set_distance(), and set_range().
{
grid_offsets.clear();
if(distance > 0) {
for(double i = min; i < max; i += distance) {
grid_offsets.push_back(lround(i));
}
grid_offsets.sort();
}
}

| virtual void degate::RegularGrid::set_distance | ( | double | distance | ) | [inline, virtual] |
Definition at line 68 of file RegularGrid.h.
References precalc_steps().
{
assert(distance >= 0);
this->distance = abs(static_cast<long>(distance));
precalc_steps();
}

| virtual void degate::RegularGrid::set_range | ( | int | min, |
| int | max | ||
| ) | [inline, virtual] |
Definition at line 62 of file RegularGrid.h.
References max, min, and precalc_steps().

| int RegularGrid::snap_to_grid | ( | int | pos | ) | const [virtual] |
Get the nearest offset, that is on grid.
Implements degate::Grid.
Definition at line 37 of file RegularGrid.cc.
References distance, max, and min.
{
if(pos <= min) return min;
else if(pos >= max) return max;
else {
if(distance == 0) return pos;
unsigned int grid_coord_x_lo = (unsigned int)((pos - min) / distance);
unsigned int grid_coord_x_hi = grid_coord_x_lo + 1;
if( (grid_coord_x_hi * distance + min - pos) < (pos - (grid_coord_x_lo * distance + min)))
return (int)(grid_coord_x_hi * distance + min);
else return (int)(grid_coord_x_lo * distance + min);
}
}
double degate::RegularGrid::distance [private] |
Definition at line 38 of file RegularGrid.h.
Referenced by clear(), get_distance(), precalc_steps(), RegularGrid(), and snap_to_grid().
grid_set degate::RegularGrid::grid_offsets [private] |
Definition at line 40 of file RegularGrid.h.
Referenced by begin(), clear(), end(), and precalc_steps().
int degate::RegularGrid::max [private] |
Definition at line 39 of file RegularGrid.h.
Referenced by clear(), get_max(), precalc_steps(), RegularGrid(), set_range(), and snap_to_grid().
int degate::RegularGrid::min [private] |
Definition at line 39 of file RegularGrid.h.
Referenced by clear(), get_min(), precalc_steps(), RegularGrid(), set_range(), and snap_to_grid().
1.7.4