degate  0.1.2
Public Member Functions | Private Attributes
degate::IrregularGrid Class Reference

This class represents a grid type with non equidistant spacing between grid lines. More...

#include <IrregularGrid.h>

Inheritance diagram for degate::IrregularGrid:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 IrregularGrid (Grid::ORIENTATION orientation)
 The ctor to construct a new irregular grid.
virtual ~IrregularGrid ()
 The destructor.
virtual grid_iter begin () const
 Get an iterator to iterate over the offsets where the grid lines are.
virtual grid_iter end () const
 Get an end marker for the iteration over grid line offsets.
virtual void clear ()
 Remove all grid lines.
virtual void add_offset (int offset)
 Add a new grid line starting at an given offset.
virtual void remove_offset (int offset)
 Remove a grid line that is placed at an offset.
virtual int snap_to_grid (int pos) const
 Get the nearest offset where a grid line starts.

Private Attributes

grid_set grid_offsets

Detailed Description

This class represents a grid type with non equidistant spacing between grid lines.

Definition at line 35 of file IrregularGrid.h.


Constructor & Destructor Documentation

The ctor to construct a new irregular grid.

Definition at line 44 of file IrregularGrid.h.

virtual degate::IrregularGrid::~IrregularGrid ( ) [inline, virtual]

The destructor.

Definition at line 49 of file IrregularGrid.h.

{}

Member Function Documentation

virtual void degate::IrregularGrid::add_offset ( int  offset) [inline, virtual]

Add a new grid line starting at an given offset.

Definition at line 69 of file IrregularGrid.h.

References grid_offsets.

                                        {
      grid_offsets.push_back(offset);
      grid_offsets.sort();
    }
virtual grid_iter degate::IrregularGrid::begin ( ) const [inline, virtual]

Get an iterator to iterate over the offsets where the grid lines are.

Implements degate::Grid.

Definition at line 54 of file IrregularGrid.h.

References grid_offsets.

{ return grid_offsets.begin(); }
virtual void degate::IrregularGrid::clear ( ) [inline, virtual]

Remove all grid lines.

Implements degate::Grid.

Definition at line 64 of file IrregularGrid.h.

References grid_offsets.

{ grid_offsets.clear(); }
virtual grid_iter degate::IrregularGrid::end ( ) const [inline, virtual]

Get an end marker for the iteration over grid line offsets.

Implements degate::Grid.

Definition at line 59 of file IrregularGrid.h.

References grid_offsets.

{ return grid_offsets.end(); }
virtual void degate::IrregularGrid::remove_offset ( int  offset) [inline, virtual]

Remove a grid line that is placed at an offset.

Definition at line 77 of file IrregularGrid.h.

References grid_offsets.

                                           {
      grid_offsets.remove(offset);
    }
int IrregularGrid::snap_to_grid ( int  pos) const [virtual]

Get the nearest offset where a grid line starts.

Implements degate::Grid.

Definition at line 29 of file IrregularGrid.cc.

References grid_offsets.

                                             {

        if(pos <= grid_offsets.front()) return grid_offsets.front();
        else if(pos >= grid_offsets.back()) return grid_offsets.back();
    else {

                int last = grid_offsets.front();
                for(grid_iter it = grid_offsets.begin(); it != grid_offsets.end(); ++it) {
                        int current = *it;
                        if(current < pos) last = current;
                        else if(current >= pos) {
                                int d1 = abs(pos - last);
                                int d2 = abs(current - pos);
                                return d1 < d2 ? last : current;
                        }
                }

                // should not reach this line
                assert(1 == 0);
    }

}

Member Data Documentation

Definition at line 37 of file IrregularGrid.h.

Referenced by add_offset(), begin(), clear(), end(), remove_offset(), and snap_to_grid().


The documentation for this class was generated from the following files: