75 int32_t x = target.
x-curpos.
x;
76 int32_t y = target.
y-curpos.
y;
78 if (
ABS(x) <= 1 &&
ABS(y) <= 1) {
80 if (y == 0 || x == 0 || x == -y)
85 }
else if (curpos.
y & 1) {
86 if (x >= 0)
return true;
87 }
else if (x <= 0)
return true;
94 if (curpos == target) {
101 return static_cast<double>(
ABS(target.
x - curpos.
x) +
ABS(target.
y - curpos.
y));
106 static std::string type(
"hexagonal_axial");
109 static std::string type(
"hexagonal");
116 static std::string hexGrid(
"Hex Grid (Axial)");
119 static std::string hexGrid(
"Hex Grid");
126 return HEX_TO_EDGE * y;
131 int32_t i_layer_y =
static_cast<int32_t
>(ay);
132 double offset = ay -
static_cast<double>(i_layer_y);
133 if ((i_layer_y % 2) == 1) {
136 return HEX_TO_EDGE * offset;
145 FL_DBG(
_log,
LMsg(
"layercoords ") << layer_coords <<
" converted to map: " << result);
153 FL_DBG(
_log,
LMsg(
"mapcoords ") << map_coord <<
" converted to layer: " << layer_coords);
158 FL_DBG(
_log,
LMsg(
"==============\nConverting map coords ") << map_coord <<
" to int32_t layer coords...");
176 if( static_cast<int32_t>(round(elc.
y)) & 1 )
180 int32_t x =
static_cast<int32_t
>(lc.
x);
181 int32_t y =
static_cast<int32_t
>(lc.
y);
182 int32_t z =
static_cast<int32_t
>(lc.
z);
196 if (
ABS(dy) > ((HEX_TO_CORNER - HEX_EDGE_GRADIENT *
ABS(dx)) * VERTICAL_MULTIP_INV)) {
224 FL_DBG(
_log,
LMsg(
"===============\ngetting vertices for ") << cell);
226 double x =
static_cast<double>(cell.
x);
227 double y =
static_cast<double>(cell.
y);
230 horiz_shift = HEX_TO_EDGE * cell.
y;
233 if (cell.
y % 2 != 0) {
240 #define ADD_PT(_x, _y) vtx.push_back(ExactModelCoordinate(_x, _y)); 268 std::vector<ModelCoordinate> coords;
269 std::vector<ModelCoordinate>::const_iterator it = orig.begin();
271 for (; it != orig.end(); ++it) {
283 coords.push_back(mc);
286 for (; it != orig.end(); ++it) {
298 coords.push_back(mc);
305 std::vector<ModelCoordinate> coords;
306 int32_t doubleDeltaX = 2*(end.
x - start.
x) +
ABS(end.
y % 2) -
ABS(start.
y % 2);
307 int32_t deltaX = (end.
x - start.
x) +
ABS(end.
y % 2) -
ABS(start.
y % 2);
308 int32_t deltaY = end.
y - start.
y;
312 int8_t signX = (start.
x < end.
x) ? 1 : -1;
313 int8_t signY = (start.
y < end.
y) ? 1 : -1;
315 coords.push_back(current);
317 if (
ABS(deltaY) <
ABS(doubleDeltaX)) {
318 int32_t errX = 3 *
ABS(doubleDeltaX);
319 int32_t errY = 3 *
ABS(deltaY);
320 while (current.
x != end.
x || current.
y != end.
y) {
322 if (err >
ABS(doubleDeltaX)) {
326 if (current.
y % 2 == 0 && current.
x != end.
x) {
332 if (current.
y % 2 == 0 && current.
x != end.
x) {
340 if (current.
y % 2 != 0 && current.
x != end.
x) {
346 if (current.
y % 2 != 0 && current.
x != end.
x) {
363 coords.push_back(current);
366 int32_t errX =
ABS(doubleDeltaX);
367 int32_t errY =
ABS(deltaY);
368 while (current.
x != end.
x || current.
y != end.
y) {
374 if (current.
y % 2 == 0 && current.
x != end.
x) {
380 if (current.
y % 2 == 0 && current.
x != end.
x) {
385 }
else if (signX == 1) {
388 if (current.
y % 2 != 0 && current.
x != end.
x) {
394 if (current.
y % 2 != 0 && current.
x != end.
x) {
406 if (current.
y % 2 == 0 && current.
x != end.
x) {
412 if (current.
y % 2 == 0 && current.
x != end.
x) {
417 }
else if (signX == 1) {
420 if (current.
y % 2 != 0 && current.
x != end.
x) {
426 if (current.
y % 2 != 0 && current.
x != end.
x) {
435 coords.push_back(current);
static const double VERTICAL_MULTIP_INV
const std::string & getType() const
Type of cellgrid.
double getXZigzagOffset(double y)
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
void setZShift(const double zshift)
Set the cellgrid z shift.
double getAdjacentCost(const ModelCoordinate &curpos, const ModelCoordinate &target)
Returns distance const from curpos to target point only cells adjacent to curpos are considered in th...
ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate &map_coord)
Transforms given point from map coordinates to layer coordinates.
std::vector< ModelCoordinate > toMultiCoordinates(const ModelCoordinate &position, const std::vector< ModelCoordinate > &orig, bool reverse)
Returns point vector with coordinates for a multi object.
static const double HEX_EDGE_GRADIENT
static Logger _log(LM_AUDIO)
std::vector< ModelCoordinate > getCoordinatesInLine(const ModelCoordinate &start, const ModelCoordinate &end)
Returns point vector with coordinates for a line from start to end.
DoubleMatrix m_inverse_matrix
void setXShift(const double &xshift)
Set the cellgrid x shift.
HexGrid(bool axial=false)
void setYScale(const double scale)
Set the cellgrid y-scaling.
ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate &layer_coords)
Transforms given point from layer coordinates to map coordinates.
void setXScale(const double scale)
Set the cellgrid x-scaling.
static const double HEX_TO_EDGE
static const double HEX_WIDTH
void setYShift(const double yshift)
Set the cellgrid y shift.
const std::string & getName() const
Name of the cellgrid (DEPRECATED? -jwt)
CellGrid * clone()
Returns clone of this cellgrid.
double getHeuristicCost(const ModelCoordinate &curpos, const ModelCoordinate &target)
Returns distance const from curpos to target point.
void setAllowDiagonals(const bool allow_diagonals)
Set whether diagonal cell access is allowed.
ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate &exact_layer_coords)
Transforms given point from exact layer coordinates to cell precision layer coordinates.
DoublePoint3D ExactModelCoordinate
static const double HEX_TO_CORNER
void getVertices(std::vector< ExactModelCoordinate > &vtx, const ModelCoordinate &cell)
Fills given point vector with vertices from selected cell.
void setRotation(const double rotation)
Set the cellgrid rotation.
static const double VERTICAL_MULTIP
static const double HEX_EDGE_HALF
ModelCoordinate toLayerCoordinates(const ExactModelCoordinate &map_coord)
Transforms given point from map coordinates to layer coordinates.
bool isAccessible(const ModelCoordinate &curpos, const ModelCoordinate &target)
Tells if given target point is accessible from curpos only cells adjacent to curpos are considered in...
ModelCoordinate toLayerCoordinatesHelper(const ExactModelCoordinate &coords)
#define FL_DBG(logger, msg)