Skip to content

Commit

Permalink
Update SimpleHexGrid origin to work properly when no points are actua…
Browse files Browse the repository at this point in the history
…lly located.
  • Loading branch information
abellgithub committed May 26, 2021
1 parent bc84145 commit 71fe5d3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion filters/private/hexer/HexGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Hexagon *HexGrid::findHexagon(Point p)
Hexagon *HexGrid::getHexagon(HexKey key)
{
// Stick a hexagon into the map if necessary.
HexMap::value_type hexpair(key, Hexagon(key.x(), key.y()));
HexMap::value_type hexpair(key, Hexagon(key));
std::pair<HexMap::iterator,bool> retval;
retval = m_hexes.insert(hexpair);
HexMap::iterator it = retval.first;
Expand Down
3 changes: 3 additions & 0 deletions filters/private/hexer/Hexagon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class Hexagon
m_dense_neighbors(0)
{}

Hexagon(HexKey key) : Hexagon(key.x(), key.y())
{}

void increment()
{ m_count++; }

Expand Down
2 changes: 0 additions & 2 deletions filters/private/hexer/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <vector>
#include <ostream>

#include <pdal/private/Mathpair.hpp>

#include "Segment.hpp"

namespace pdal
Expand Down
2 changes: 0 additions & 2 deletions filters/private/hexer/Segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ Point Segment::pos(HexGrid *grid, const Point& offset) const
pos.m_x = m_hex->x() * grid->width();
pos.m_y = m_hex->y() * grid->height();
if (m_hex->xodd())
{
pos.m_y += (grid->height() / 2);
}
return pos + offset + grid->origin();
}

Expand Down
11 changes: 4 additions & 7 deletions pdal/private/SimpleHexGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,10 @@ using namespace std;
namespace pdal
{

SimpleHexGrid::SimpleHexGrid() : m_height(-1.0), m_width(-1.0),
m_origin(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max())
SimpleHexGrid::SimpleHexGrid() : m_height(-1.0), m_width(-1.0), m_origin(0, 0), m_first(true)
{}

SimpleHexGrid::SimpleHexGrid(double height) :
m_origin(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max())
SimpleHexGrid::SimpleHexGrid(double height) : m_origin(0, 0), m_first(true)
{
initialize(height);
}
Expand Down Expand Up @@ -108,8 +104,9 @@ HexKey SimpleHexGrid::findHexagon(Point p)
{
int x, y;

if (m_origin.m_x == std::numeric_limits<double>::max())
if (m_first)
{
m_first = false;
m_origin = p;
return HexKey(0, 0);
}
Expand Down
2 changes: 2 additions & 0 deletions pdal/private/SimpleHexGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class SimpleHexGrid
double m_width;
/// Origin of the hex grid in point coordinates.
Point m_origin;
/// First query done.
bool m_first;
/// Offsets of vertices of hexagon, going anti-clockwise from upper-left
Point m_offsets[6];
/// Offset of the center of the hexagons.
Expand Down

0 comments on commit 71fe5d3

Please sign in to comment.