/* Copyright 2015, Michele Santullo * This file is part of DoorKeeper. * * DoorKeeper is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DoorKeeper is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DoorKeeper. If not, see . */ namespace dk { template TileIterator::TileIterator (qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parArea) : m_tile_range(parArea), m_data(parData), m_pixel_conv(parPixConv) { DK_ASSERT(parData); DK_ASSERT(&m_pixel_conv != nullptr); } template TileIterator::TileIterator (qualif_vector_type* parData, const PixelConv& parPixConv, const coords& parStart, const coords& parArea) : m_tile_range(parStart, parArea), m_data(parData), m_pixel_conv(parPixConv) { DK_ASSERT(parData); DK_ASSERT(&m_pixel_conv != nullptr); } template void TileIterator::increment() { ++m_tile_range; } template void TileIterator::decrement() { --m_tile_range; } template void TileIterator::advance (size_t parAdvance) { constexpr auto M = std::numeric_limits::max(); typedef typename std::conditional< (static_cast::type>(std::numeric_limits::max()) > static_cast::type>(M)), size_t, CoordinateScalarType >::type LargestType; while (parAdvance) { const auto inc = std::min(static_cast(parAdvance), static_cast(M)); m_tile_range += inc; parAdvance -= static_cast(inc); } } template auto TileIterator::distance_to (const TileIterator& parOther) -> difference_type { return std::distance(to_index(m_tile_range), to_index(parOther.m_tile_range)); } template bool TileIterator::equal (const TileIterator& parOther) const { return m_data == parOther.m_data and m_tile_range.position() == parOther.m_tile_range.position(); } template auto TileIterator::dereference() const -> reference { const auto index = to_index(m_tile_range); DK_ASSERT(m_data); DK_ASSERT(index >= 0); DK_ASSERT(static_cast::type>(index) < m_data->size()); return Tile(&(*m_data)[index], m_tile_range, coords(0), &m_pixel_conv); } template inline Vector make_past_end_coords (const Vector& parTo) { Vector retval(0); //for (CoordinateDistType d = 0; d < D - 1; ++d) { //retval[d] = parFrom[d]; //} retval[D - 1] = parTo[D - 1] + 1; return retval; } } //namespace dk