|
Core 1.0
|
A core hexagonal grid. More...
#include <hexagonarray.h>
Public Member Functions | |
| HexagonArray2 (const Vector2 &, const double &, int, int) | |
| Create and array of hexagons. | |
| HexagonArray2 (const Box2 &, const double &) | |
| Create and array of hexagons embedded in a box. | |
| bool | IsEmpty () const |
| Detect if the array is empty, i.e., any dimension equal to zero. | |
| int | GetSizeX () const |
| Get the vertex size of the array for x axis. | |
| int | GetSizeY () const |
| Get the vertex size of the array for y axis. | |
| int | VertexSize () const |
| Return the size of the vertex array. | |
| Box2 | GetBox () const |
| Compute the bounding box of the centroids of the hexagons. | |
| Box2 | GetHexagonBox () const |
| Compute the bounding box of all the hexagons. | |
| Vector2 | CellCenter (int, int) const |
| Compute the center of the hexagonal cell. | |
| void | Translate (const Vector2 &) |
| Translate the array. | |
| Vector2 | ArrayVertex (int, int) const |
| Compute the coordinates of a point on the grid. | |
| constexpr bool | InsideVertexIndex (int, int) const |
| Check if the indexes are within range. | |
| bool | Inside (const Vector2 &) const |
| Check if a point is in the rectangular domain. | |
| Hexagon2 | UnitCell () const |
| Return the geometry of a generic cell. | |
| double | CellArea () const |
| Return the area of a cell. | |
| QPoint | Next (int, int, int) const |
| Compute the index of the neighboring hexagon. | |
| QPoint | Next (const QPoint &, int) const |
| Compute the index of the neighboring hexagon. | |
| void | TriangleInteger (const Vector2 &, int &, int &, double &, double &) const |
| Compute the coordinates of a vertex inside a triangle of the hexagonal grid. | |
| QPoint | TriangleInteger (const Vector2 &) const |
| Compute the coordinates of a vertex inside a triangle of the hexagonal grid. | |
| QRect | VertexIntegerArea (const Box2 &) const |
| Compute the integer coordinates of the vertices embedding a box. | |
| QRect | VertexIntegerArea (const Circle2 &) const |
| Compute the integer coordinates of the vertices embedding a circle. | |
| void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draws the hexagon array. | |
| void | DrawCenters (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draws the centers of the hexagon grid. | |
Protected Member Functions | |
| constexpr int | VertexIndex (int, int) const |
| Compute the index of a given cell. | |
| void | InverseVertexIndex (int, int &, int &) const |
| Compute the coordinates of a given cell. | |
| QPoint | InverseVertexIndex (int) const |
| Compute the coordinates of a given cell. | |
| bool | InsideCellIndex (int, int) const |
| Check if the indexes are within range. | |
Protected Member Functions inherited from Hexagon2 | |
| Hexagon2 () | |
| Empty. | |
| Hexagon2 (const Vector2 &, const double &) | |
| Create an hexagon. | |
| Hexagon2 (const double &) | |
| Create an hexagon. | |
| void | Translate (const Vector2 &) |
| Translate a hexagon. | |
| void | Scale (const double &) |
| Scale a hexagon. | |
| double | Width () const |
| Width of the hexagon. | |
| double | Height () const |
| Height of the hexagon. | |
| bool | Inside (const Vector2 &) const |
| Test if a point is inside. | |
| bool | Intersect (const Hexagon2 &) const |
| Check if two hexagons intersect. | |
| double | R (const Vector2 &) const |
| Compute the squared Euclidean distance to the hexagon. | |
| double | Signed (const Vector2 &) const |
| Compute the signed Euclidean distance to the hexagon. | |
| Vector2 | Normal (const Vector2 &) const |
| Computes the distance vector between a hexagon and a point. | |
| Vector2 | Center () const |
| Return the center of the hexagonal cell. | |
| double | Radius () const |
| Return the radius of the hexagonal cell. | |
| Vector2 | Radial (int) const |
| Return the radial vector of the k-th vertex. | |
| Vector2 | Edge (int) const |
| Return the edge vector connecting vertexes k and k+1. | |
| Vector2 | Vertex (int) const |
| Return the coordinates of the k-th vertex. | |
| Box2 | GetBox () const |
| Compute the bounding box of a hexagon. | |
| double | Area () const |
| Area of the hexagon. | |
| double | Perimeter () const |
| Perimeter of the hexagon. | |
| Vector2 | RandomInside (Random &=Random::R239) const |
| Generate a random vector inside the hexagon. | |
| QVector< Vector2 > | Poisson (const double &, int, Random &=Random::R239) const |
| Compute a Poisson disc distribution inside the hexagon. | |
| bool | Intersect (const Circle2 &) const |
| Check the intersection with a circle. | |
| void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
| Draws an hexagon. | |
Protected Attributes | |
| int | ny = 0 |
| Number of hexagons. | |
Protected Attributes inherited from Hexagon2 | |
| Vector2 | c = Vector2::Null |
| Center. | |
| double | r = 1.0 |
| Radius. | |
Static Protected Attributes | |
| static int | next [6][2] = { {1,0}, {0,1}, {-1,0 }, {-1,-1}, {0,-1}, {1,-1 } } |
| Array of offsets for computing neighbor indexes. | |
Static Protected Attributes inherited from Hexagon2 | |
| static const Vector2 | vertex [6] |
| Array of vertices. | |
| static const Vector2 | normal [6] |
| Array of normal vectors to the edges. | |
| static const Vector2 | edge [6] |
| Unit edge vectors. | |
| static const double | Alpha = sqrt(3.0) / 2.0 |
| Constant sin(π/6)=√3/2. | |
Additional Inherited Members | |
Static Protected Member Functions inherited from Hexagon2 | |
| static int | Sector (const Vector2 &) |
| Compute the sector given an input direction. | |
A core hexagonal grid.
|
explicit |
Create and array of hexagons.
| c | Origin. |
| r | Side length of equilateral triangles. |
| x,y | Size of the array. |
|
explicit |
Create and array of hexagons embedded in a box.
Compute the largest array of hexagons centered and embedded in the argument box.
| box | The box. |
| r | Side length of equilateral triangles. |
| Vector2 HexagonArray2::ArrayVertex | ( | int | i, |
| int | j ) const |
Compute the coordinates of a point on the grid.
| i,j | Point coordinates. |
| double HexagonArray2::CellArea | ( | ) | const |
Return the area of a cell.
This is convenience function, which is the same as the following code, but more efficient:
| Vector2 HexagonArray2::CellCenter | ( | int | i, |
| int | j ) const |
Compute the center of the hexagonal cell.
| i,j | Cell coordinates. |
| void HexagonArray2::Draw | ( | QGraphicsScene & | scene, |
| const QPen & | pen = QPen(), | ||
| const QBrush & | brush = QBrush() ) const |
Draws the hexagon array.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush. |
| void HexagonArray2::DrawCenters | ( | QGraphicsScene & | scene, |
| const QPen & | pen = QPen(), | ||
| const QBrush & | brush = QBrush() ) const |
Draws the centers of the hexagon grid.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush. |
| Box2 HexagonArray2::GetBox | ( | ) | const |
Compute the bounding box of the centroids of the hexagons.
Note that is is smaller than the bounding box of the hexagons.
| Box2 HexagonArray2::GetHexagonBox | ( | ) | const |
Compute the bounding box of all the hexagons.
Note that is is smaller than the bounding box of the hexagons.
| bool HexagonArray2::Inside | ( | const Vector2 & | p | ) | const |
Check if a point is in the rectangular domain.
| p | Point. |
|
protected |
Check if the indexes are within range.
| i,j | Integer coordinates of the vertex. |
|
inlineconstexpr |
Check if the indexes are within range.
| i,j | Integer coordinates of the vertex. |
|
inlineprotected |
Compute the coordinates of a given cell.
| c | Index of the cell. |
|
inlineprotected |
Compute the coordinates of a given cell.
| c | Index of the cell. |
| i,j | Integer coordinates of the cell. |
|
inline |
Compute the index of the neighboring hexagon.
| p | Center. point |
| k | Neighbor, should be in [0,5]. |
|
inline |
Compute the index of the neighboring hexagon.
| i,j | Center. |
| k | Neighbor, should be in [0,5]. |
| void HexagonArray2::Translate | ( | const Vector2 & | t | ) |
Translate the array.
| t | Translation vector. |
| QPoint HexagonArray2::TriangleInteger | ( | const Vector2 & | p | ) | const |
Compute the coordinates of a vertex inside a triangle of the hexagonal grid.
| p | Point. |
| void HexagonArray2::TriangleInteger | ( | const Vector2 & | p, |
| int & | i, | ||
| int & | j, | ||
| double & | u, | ||
| double & | v ) const |
Compute the coordinates of a vertex inside a triangle of the hexagonal grid.
| p | Point. |
| i,j | Integer coordinates of the lower vertex. |
| u,v | Coordinates of the point in the corresponding triangle. |
| Hexagon2 HexagonArray2::UnitCell | ( | ) | const |
Return the geometry of a generic cell.
This is a hexagon, centered at origin, with the right size.
|
inlineconstexprprotected |
Compute the index of a given cell.
| i,j | Integer coordinates of the cell. |
| QRect HexagonArray2::VertexIntegerArea | ( | const Box2 & | box | ) | const |
Compute the integer coordinates of the vertices embedding a box.
The coordinates are clamped to the size of the array.
| box | Box. |
| QRect HexagonArray2::VertexIntegerArea | ( | const Circle2 & | circle | ) | const |
Compute the integer coordinates of the vertices embedding a circle.
The coordinates are clamped to the size of the array.
| circle | Circle. |