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. More... | |
HexagonArray2 (const Box2 &, const double &) | |
Create and array of hexagons embedded in a box. More... | |
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. More... | |
Box2 | GetHexagonBox () const |
Compute the bounding box of all the hexagons. More... | |
Vector2 | CellCenter (int, int) const |
Compute the center of the hexagonal cell. More... | |
void | Translate (const Vector2 &) |
Translate the array. More... | |
Vector2 | ArrayVertex (int, int) const |
Compute the coordinates of a point on the grid. More... | |
constexpr bool | InsideVertexIndex (int, int) const |
Check if the indexes are within range. More... | |
bool | Inside (const Vector2 &) const |
Check if a point is in the rectangular domain. More... | |
Hexagon2 | UnitCell () const |
Return the geometry of a generic cell. More... | |
double | CellArea () const |
Return the area of a cell. More... | |
QPoint | Next (int, int, int) const |
Compute the index of the neighboring hexagon. More... | |
QPoint | Next (const QPoint &, int) const |
Compute the index of the neighboring hexagon. More... | |
void | TriangleInteger (const Vector2 &, int &, int &, double &, double &) const |
Compute the coordinates of a vertex inside a triangle of the hexagonal grid. More... | |
QPoint | TriangleInteger (const Vector2 &) const |
Compute the coordinates of a vertex inside a triangle of the hexagonal grid. More... | |
QRect | VertexIntegerArea (const Box2 &) const |
Compute the integer coordinates of the vertices embedding a box. More... | |
QRect | VertexIntegerArea (const Circle2 &) const |
Compute the integer coordinates of the vertices embedding a circle. More... | |
void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
Draws the hexagon array. More... | |
void | DrawCenters (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
Draws the centers of the hexagon grid. More... | |
Protected Member Functions | |
constexpr int | VertexIndex (int, int) const |
Compute the index of a given cell. More... | |
void | InverseVertexIndex (int, int &, int &) const |
Compute the coordinates of a given cell. More... | |
QPoint | InverseVertexIndex (int) const |
Compute the coordinates of a given cell. More... | |
bool | InsideCellIndex (int, int) const |
Check if the indexes are within range. More... | |
Protected Member Functions inherited from Hexagon2 | |
Hexagon2 () | |
Empty. | |
Hexagon2 (const Vector2 &, const double &) | |
Create an hexagon. More... | |
Hexagon2 (const double &) | |
Create an hexagon. More... | |
void | Translate (const Vector2 &) |
Translate a hexagon. More... | |
void | Scale (const double &) |
Scale a hexagon. More... | |
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. More... | |
bool | Intersect (const Hexagon2 &) const |
Check if two hexagons intersect. More... | |
double | R (const Vector2 &) const |
Compute the squared Euclidean distance to the hexagon. More... | |
double | Signed (const Vector2 &) const |
Compute the signed Euclidean distance to the hexagon. More... | |
Vector2 | Normal (const Vector2 &) const |
Computes the distance vector between a hexagon and a point. More... | |
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. More... | |
Vector2 | Edge (int) const |
Return the edge vector connecting vertexes k and k+1. More... | |
Vector2 | Vertex (int) const |
Return the coordinates of the k-th vertex. More... | |
Box2 | GetBox () const |
Compute the bounding box of a hexagon. | |
double | Area () const |
Area of the hexagon. | |
double | Perimeter () const |
Perimeter of the hexagon. | |
bool | Intersect (const Circle2 &) const |
Check the intersection with a circle. More... | |
void | Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const |
Draws an hexagon. More... | |
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. More... | |
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. |
i,j | Integer coordinates of the cell. |
u,v | Coordinates of the point in the corresponding triangle. |
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. |