< Summary

Class:Itinero.IO.Osm.Tiles.TileRange
Assembly:Itinero.IO.Osm.Tiles
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm.Tiles/TileRange.cs
Covered lines:0
Uncovered lines:55
Coverable lines:55
Total lines:104
Line coverage:0% (0 of 55)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)0%20%
get_Left()100%10%
get_Right()100%10%
get_Top()100%10%
get_Bottom()100%10%
get_Zoom()100%10%
GetEnumerator()100%10%
System.Collections.IEnumerable.GetEnumerator()100%10%
.ctor(...)100%10%
MoveNext()0%80%
Reset()100%10%
get_Current()100%10%
System.Collections.IEnumerator.get_Current()100%10%
Dispose()100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm.Tiles/TileRange.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4
 5namespace Itinero.IO.Osm.Tiles;
 6
 7internal struct TileRange : IEnumerable<Tile>
 8{
 9    public TileRange(
 10        ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude, float? e)
 11            bottomRight) box, int zoom)
 012    {
 013        var topLeft = Tile.WorldToTile(box.topLeft.longitude, box.topLeft.latitude, zoom);
 014        var bottomRight = Tile.WorldToTile(box.bottomRight.longitude, box.bottomRight.latitude, zoom);
 15
 016        this.Left = topLeft.X;
 017        this.Top = topLeft.Y;
 018        this.Right = bottomRight.X;
 019        this.Bottom = bottomRight.Y;
 020        this.Zoom = zoom;
 21
 022        if (this.Top > this.Bottom)
 023        {
 024            throw new ArgumentException("Invalid tile range, top is lower than bottom.");
 25        }
 026    }
 27
 028    public uint Left { get; }
 29
 030    public uint Right { get; }
 31
 032    public uint Top { get; }
 33
 034    public uint Bottom { get; }
 35
 036    public int Zoom { get; }
 37
 38    public IEnumerator<Tile> GetEnumerator()
 039    {
 040        return new TileRangeEnumerator(this);
 041    }
 42
 43    IEnumerator IEnumerable.GetEnumerator()
 044    {
 045        return this.GetEnumerator();
 046    }
 47
 48    private struct TileRangeEnumerator : IEnumerator<Tile>
 49    {
 50        private readonly TileRange _tileRange;
 51
 52        public TileRangeEnumerator(TileRange tileRange)
 053        {
 054            _tileRange = tileRange;
 055            _x = uint.MaxValue;
 056            _y = uint.MaxValue;
 057        }
 58
 59        private uint _x;
 60        private uint _y;
 61
 62        public bool MoveNext()
 063        {
 064            if (_x == uint.MaxValue)
 065            {
 066                _x = _tileRange.Left;
 067                _y = _tileRange.Top;
 068                return true;
 69            }
 70
 071            if (_tileRange.Left > _tileRange.Right)
 072            { // not supported.
 073                throw new Exception("Tile ranges crossing date line not supported.");
 74            }
 75
 076            if (_x == _tileRange.Right)
 077            { // move y.
 078                if (_y == _tileRange.Bottom)
 079                { // enumeration finished.
 080                    return false;
 81                }
 82
 083                _y++;
 084                _x = _tileRange.Left;
 085                return true;
 86            }
 87
 088            _x++;
 089            return true;
 090        }
 91
 92        public void Reset()
 093        {
 094            _x = uint.MaxValue;
 095            _y = uint.MaxValue;
 096        }
 97
 098        public Tile Current => new(_x, _y, _tileRange.Zoom);
 99
 0100        object IEnumerator.Current => this.Current;
 101
 0102        public void Dispose() { }
 103    }
 104}