Core 1.0
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
HexagonArray2 Class Reference

A core hexagonal grid. More...

#include <hexagonarray.h>

Inheritance diagram for HexagonArray2:
Hexagon2 ScalarHexagonField2

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...
 

Detailed Description

A core hexagonal grid.

Constructor & Destructor Documentation

◆ HexagonArray2() [1/2]

HexagonArray2::HexagonArray2 ( const Vector2 c,
const double &  r,
int  x,
int  y 
)
explicit

Create and array of hexagons.

Parameters
cOrigin.
rSide length of equilateral triangles.
x,ySize of the array.

◆ HexagonArray2() [2/2]

HexagonArray2::HexagonArray2 ( const Box2 box,
const double &  r 
)
explicit

Create and array of hexagons embedded in a box.

Compute the largest array of hexagons centered and embedded in the argument box.

Parameters
boxThe box.
rSide length of equilateral triangles.

Member Function Documentation

◆ ArrayVertex()

Vector2 HexagonArray2::ArrayVertex ( int  i,
int  j 
) const

Compute the coordinates of a point on the grid.

Parameters
i,jPoint coordinates.

◆ CellArea()

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:

double a=array.UnitCell().Area();
double Area() const
Area of the hexagon.
Definition: hexagon2.cpp:61
A core hexagonal grid.
Definition: hexagonarray.h:10
Hexagon2 UnitCell() const
Return the geometry of a generic cell.
Definition: hexagonarray2.cpp:101

◆ CellCenter()

Vector2 HexagonArray2::CellCenter ( int  i,
int  j 
) const

Compute the center of the hexagonal cell.

Parameters
i,jCell coordinates.

◆ Draw()

void HexagonArray2::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draws the hexagon array.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ DrawCenters()

void HexagonArray2::DrawCenters ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draws the centers of the hexagon grid.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ GetBox()

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.

◆ GetHexagonBox()

Box2 HexagonArray2::GetHexagonBox ( ) const

Compute the bounding box of all the hexagons.

Note that is is smaller than the bounding box of the hexagons.

◆ Inside()

bool HexagonArray2::Inside ( const Vector2 p) const

Check if a point is in the rectangular domain.

Parameters
pPoint.

◆ InsideCellIndex()

bool HexagonArray2::InsideCellIndex ( int  i,
int  j 
) const
protected

Check if the indexes are within range.

Parameters
i,jInteger coordinates of the vertex.

◆ InsideVertexIndex()

constexpr bool HexagonArray2::InsideVertexIndex ( int  i,
int  j 
) const
inlineconstexpr

Check if the indexes are within range.

Parameters
i,jInteger coordinates of the vertex.

◆ InverseVertexIndex() [1/2]

QPoint HexagonArray2::InverseVertexIndex ( int  c) const
inlineprotected

Compute the coordinates of a given cell.

Parameters
cIndex of the cell.

◆ InverseVertexIndex() [2/2]

void HexagonArray2::InverseVertexIndex ( int  c,
int &  i,
int &  j 
) const
inlineprotected

Compute the coordinates of a given cell.

Parameters
cIndex of the cell.
i,jInteger coordinates of the cell.

◆ Next() [1/2]

QPoint HexagonArray2::Next ( const QPoint &  p,
int  k 
) const
inline

Compute the index of the neighboring hexagon.

Parameters
pCenter. point
kNeighbor, should be in [0,5].

◆ Next() [2/2]

QPoint HexagonArray2::Next ( int  i,
int  j,
int  k 
) const
inline

Compute the index of the neighboring hexagon.

Parameters
i,jCenter.
kNeighbor, should be in [0,5].

◆ Translate()

void HexagonArray2::Translate ( const Vector2 t)

Translate the array.

Parameters
tTranslation vector.

◆ TriangleInteger() [1/2]

QPoint HexagonArray2::TriangleInteger ( const Vector2 p) const

Compute the coordinates of a vertex inside a triangle of the hexagonal grid.

Parameters
pPoint.
i,jInteger coordinates of the cell.
u,vCoordinates of the point in the corresponding triangle.

◆ TriangleInteger() [2/2]

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.

Parameters
pPoint.
i,jInteger coordinates of the lower vertex.
u,vCoordinates of the point in the corresponding triangle.

◆ UnitCell()

Hexagon2 HexagonArray2::UnitCell ( ) const

Return the geometry of a generic cell.

This is a hexagon, centered at origin, with the right size.

◆ VertexIndex()

constexpr int HexagonArray2::VertexIndex ( int  i,
int  j 
) const
inlineconstexprprotected

Compute the index of a given cell.

Parameters
i,jInteger coordinates of the cell.

◆ VertexIntegerArea() [1/2]

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.

Parameters
boxBox.

◆ VertexIntegerArea() [2/2]

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.

Parameters
circleCircle.