#include "stdafx.h"
#include "Chokepoint.h"

// TODO: improve this: isInLocation() functions should only take into account the tiles crossed
//       by the chokepoint line segment

bool Chokepoint::isInLocation(BWAPI::Position position) const
{
  const std::pair<BWAPI::Position, BWAPI::Position>& sides = m_chokepoint->getSides();

  return is_between<int, true>(sides.first.x(), sides.second.x())(position.x())
      && is_between<int, true>(sides.first.y(), sides.second.y())(position.y());
}

bool Chokepoint::isInLocation(BWAPI::TilePosition tile) const
{
  const std::pair<BWAPI::Position, BWAPI::Position>& sides = m_chokepoint->getSides();
  const BWAPI::Position pos1(
    std::min(sides.first.x(), sides.second.x()) - TILE_SIZE,
    std::min(sides.first.y(), sides.second.y()) - TILE_SIZE);
  const BWAPI::Position pos2(
    std::max(sides.first.x(), sides.second.x()) + TILE_SIZE,
    std::max(sides.first.y(), sides.second.y()) + TILE_SIZE);
  const std::pair<BWAPI::TilePosition, BWAPI::TilePosition> tiles = std::make_pair(BWAPI::TilePosition(pos1),
                                                                                   BWAPI::TilePosition(pos2));
  return is_between<int, true>(tiles.first.x(), tiles.second.x())(tile.x())
      && is_between<int, true>(tiles.first.y(), tiles.second.y())(tile.y());
}