31 #include "model/structures/instance.h"
32 #include "model/structures/layer.h"
33 #include "model/structures/map.h"
35 #include "searchspace.h"
39 SearchSpace::SearchSpace(Layer* layer)
40 : m_upperX(0), m_upperY(0), m_lowerX(0), m_lowerY(0), m_layer(layer) {
42 Map* map = layer->getMap();
43 const std::list<Layer*>& layers = map->getLayers();
44 ModelCoordinate min, max;
46 for(std::list<Layer*>::const_iterator i = layers.begin();
50 ModelCoordinate newMin, newMax;
51 (*i)->getMinMaxCoordinates(newMin, newMax, layer);
53 if(newMin.x < min.x) {
57 if(newMax.x > max.x) {
61 if(newMin.y < min.y) {
65 if(newMax.y > max.y) {
76 bool SearchSpace::isInSearchSpace(
const Location& location)
const {
77 if(location.getLayer() != m_layer) {
80 ModelCoordinate coordinates = location.getLayerCoordinates();
81 if(coordinates.x >= m_lowerX && coordinates.x <= m_upperX
82 && coordinates.y >= m_lowerY && coordinates.y <= m_upperY) {
88 ModelCoordinate SearchSpace::translateCoordsToSearchSpace(
const ModelCoordinate& coords)
const {
89 ModelCoordinate newcoords;
90 newcoords.x = coords.x - m_lowerX;
91 newcoords.y = coords.y - m_lowerY;
95 int32_t SearchSpace::convertCoordToInt(
const ModelCoordinate& coord)
const {
96 ModelCoordinate newcoords = translateCoordsToSearchSpace(coord);
97 return newcoords.x + (newcoords.y * getWidth());
100 ModelCoordinate SearchSpace::convertIntToCoord(
const int32_t cell)
const {
101 ModelCoordinate coord;
102 int32_t width = getWidth();
103 coord.x = (cell % width) + m_lowerX;
104 coord.y = (cell / width) + m_lowerY;
108 int32_t SearchSpace::getMaxIndex()
const {
111 int32_t max_index = getWidth() + (getWidth() * getHeight());
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...