// A debugging function that can be used to make a particular hexagon // dense. void HexGrid::addDenseHexagon(int x, int y) { Hexagon *h = getHexagon(x, y); if (!h->dense()) { h->setCount(m_dense_limit); h->setDense(); m_miny = std::min(m_miny, h->y() - 1); if (h->possibleRoot()) m_pos_roots.insert(h); markNeighborBelow(h); } }
void HexGrid::addPoint(Point p) { Hexagon *h = findHexagon(p); if (!h->dense()) { h->increment(); if (dense(h)) { h->setDense(); m_miny = std::min(m_miny, h->y() - 1); if (h->possibleRoot()) { m_pos_roots.insert(h); } markNeighborBelow(h); } } }
void HexGrid::findParentPath(Path *p) { Segment s = p->rootSegment(); Hexagon *h = s.hex(); int y = h->y(); while (y >= m_miny) { HexPathMap::iterator it = m_hex_paths.find(h); if (it != m_hex_paths.end()) { Path *parentPath = it->second; if (parentPath == p->parent()) { p->setParent(NULL); } else if (!p->parent() && parentPath != p) { p->setParent(parentPath); } } h = getHexagon(h->x(), --y); } }
void HexGrid::addPoint(Point p) { if (m_width < 0) { m_sample.push_back(p); if (m_sample.size() >= m_maxSample) processSample(); return; } Hexagon *h = findHexagon(p); h->increment(); if (!h->dense()) { if (dense(h)) { h->setDense(); m_miny = std::min(m_miny, h->y() - 1); if (h->possibleRoot()) m_pos_roots.insert(h); markNeighborBelow(h); } } }
float Hexagon::Distance (const Hexagon& h) const { return max (max (abs (q - h.q), abs (r - h.r)), abs (y() - h.y())); }