use std::slice;
use tui::style::Color;
use tui::widgets::canvas::Shape;

pub struct PointsIterator<'a> {
    iter: slice::Iter<'a, (f64, f64)>,
}

impl<'a> From<&'a [(f64, f64)]> for PointsIterator<'a> {
    fn from(data: &'a [(f64, f64)]) -> PointsIterator<'a> {
        PointsIterator { iter: data.iter() }
    }
}

impl<'a> Iterator for PointsIterator<'a> {
    type Item = (f64, f64);
    fn next(&mut self) -> Option<Self::Item> {
        match self.iter.next() {
            Some(p) => Some(*p),
            None => None,
        }
    }
}

/// Shape to draw a world map with the given resolution and color
pub struct Circle {
    pub circle: &'static [(f64, f64)],
    pub color: Color,
}

impl Default for Circle {
    fn default() -> Circle {
        Circle {
            circle: &CIRCLE,
            color: Color::Reset,
        }
    }
}

impl<'a> Shape<'a> for Circle {
    fn color(&self) -> Color {
        self.color
    }
    fn points(&'a self) -> Box<dyn Iterator<Item = (f64, f64)> + 'a> {
        Box::new(self.into_iter())
    }
}

impl<'a> IntoIterator for &'a Circle {
    type Item = (f64, f64);
    type IntoIter = PointsIterator<'a>;
    fn into_iter(self) -> Self::IntoIter {
        PointsIterator::from(self.circle)
    }
}

pub static CIRCLE: [(f64, f64); 500] = [
    (49.984209, 1.256505),
    (49.936848, 2.512216),
    (49.857945, 3.76634),
    (49.747551, 5.018086),
    (49.605735, 6.266662),
    (49.432587, 7.511279),
    (49.228217, 8.751153),
    (48.992753, 9.985499),
    (48.726344, 11.213538),
    (48.429158, 12.434494),
    (48.101384, 13.647597),
    (47.743227, 14.852079),
    (47.354915, 16.04718),
    (46.936693, 17.232146),
    (46.488824, 18.406228),
    (46.011592, 19.568683),
    (45.505299, 20.718779),
    (44.970263, 21.855788),
    (44.406822, 22.978993),
    (43.815334, 24.087684),
    (43.196171, 25.18116),
    (42.549724, 26.258731),
    (41.876402, 27.319717),
    (41.17663, 28.363447),
    (40.45085, 29.389263),
    (39.69952, 30.396515),
    (38.923115, 31.384568),
    (38.122126, 32.352798),
    (37.297057, 33.300593),
    (36.448431, 34.227355),
    (35.576784, 35.132498),
    (34.682665, 36.015451),
    (33.76664, 36.875656),
    (32.829288, 37.712569),
    (31.871199, 38.525662),
    (30.892981, 39.314422),
    (29.895249, 40.078349),
    (28.878635, 40.816963),
    (27.843781, 41.529795),
    (26.79134, 42.216396),
    (25.721977, 42.876333),
    (24.636367, 43.509188),
    (23.535197, 44.114561),
    (22.419161, 44.692071),
    (21.288965, 45.241353),
    (20.145322, 45.762059),
    (18.988955, 46.25386),
    (17.820594, 46.716447),
    (16.640977, 47.149527),
    (15.45085, 47.552826),
    (14.250963, 47.926089),
    (13.042075, 48.269082),
    (11.82495, 48.581587),
    (10.600355, 48.863406),
    (9.369066, 49.114363),
    (8.131858, 49.334297),
    (6.889515, 49.523071),
    (5.642819, 49.680566),
    (4.39256, 49.80668),
    (3.139526, 49.901336),
    (1.884509, 49.964474),
    (0.628302, 49.996052),
    (-0.628302, 49.996052),
    (-1.884509, 49.964474),
    (-3.139526, 49.901336),
    (-4.39256, 49.80668),
    (-5.642819, 49.680566),
    (-6.889515, 49.523071),
    (-8.131858, 49.334297),
    (-9.369066, 49.114363),
    (-10.600355, 48.863406),
    (-11.82495, 48.581587),
    (-13.042075, 48.269082),
    (-14.250963, 47.926089),
    (-15.45085, 47.552826),
    (-16.640977, 47.149527),
    (-17.820594, 46.716447),
    (-18.988955, 46.25386),
    (-20.145322, 45.762059),
    (-21.288965, 45.241353),
    (-22.419161, 44.692071),
    (-23.535197, 44.114561),
    (-24.636367, 43.509188),
    (-25.721977, 42.876333),
    (-26.79134, 42.216396),
    (-27.843781, 41.529795),
    (-28.878635, 40.816963),
    (-29.895249, 40.078349),
    (-30.892981, 39.314422),
    (-31.871199, 38.525662),
    (-32.829288, 37.712569),
    (-33.76664, 36.875656),
    (-34.682665, 36.015451),
    (-35.576784, 35.132498),
    (-36.448431, 34.227355),
    (-37.297057, 33.300593),
    (-38.122126, 32.352798),
    (-38.923115, 31.384568),
    (-39.69952, 30.396515),
    (-40.45085, 29.389263),
    (-41.17663, 28.363447),
    (-41.876402, 27.319717),
    (-42.549724, 26.258731),
    (-43.196171, 25.18116),
    (-43.815334, 24.087684),
    (-44.406822, 22.978993),
    (-44.970263, 21.855788),
    (-45.505299, 20.718779),
    (-46.011592, 19.568683),
    (-46.488824, 18.406228),
    (-46.936693, 17.232146),
    (-47.354915, 16.04718),
    (-47.743227, 14.852079),
    (-48.101384, 13.647597),
    (-48.429158, 12.434494),
    (-48.726344, 11.213538),
    (-48.992753, 9.985499),
    (-49.228217, 8.751153),
    (-49.432587, 7.511279),
    (-49.605735, 6.266662),
    (-49.747551, 5.018086),
    (-49.857945, 3.76634),
    (-49.936848, 2.512216),
    (-49.984209, 1.256505),
    (-50.0, 0.0),
    (-49.984209, -1.256505),
    (-49.936848, -2.512216),
    (-49.857945, -3.76634),
    (-49.747551, -5.018086),
    (-49.605735, -6.266662),
    (-49.432587, -7.511279),
    (-49.228217, -8.751153),
    (-48.992753, -9.985499),
    (-48.726344, -11.213538),
    (-48.429158, -12.434494),
    (-48.101384, -13.647597),
    (-47.743227, -14.852079),
    (-47.354915, -16.04718),
    (-46.936693, -17.232146),
    (-46.488824, -18.406228),
    (-46.011592, -19.568683),
    (-45.505299, -20.718779),
    (-44.970263, -21.855788),
    (-44.406822, -22.978993),
    (-43.815334, -24.087684),
    (-43.196171, -25.18116),
    (-42.549724, -26.258731),
    (-41.876402, -27.319717),
    (-41.17663, -28.363447),
    (-40.45085, -29.389263),
    (-39.69952, -30.396515),
    (-38.923115, -31.384568),
    (-38.122126, -32.352798),
    (-37.297057, -33.300593),
    (-36.448431, -34.227355),
    (-35.576784, -35.132498),
    (-34.682665, -36.015451),
    (-33.76664, -36.875656),
    (-32.829288, -37.712569),
    (-31.871199, -38.525662),
    (-30.892981, -39.314422),
    (-29.895249, -40.078349),
    (-28.878635, -40.816963),
    (-27.843781, -41.529795),
    (-26.79134, -42.216396),
    (-25.721977, -42.876333),
    (-24.636367, -43.509188),
    (-23.535197, -44.114561),
    (-22.419161, -44.692071),
    (-21.288965, -45.241353),
    (-20.145322, -45.762059),
    (-18.988955, -46.25386),
    (-17.820594, -46.716447),
    (-16.640977, -47.149527),
    (-15.45085, -47.552826),
    (-14.250963, -47.926089),
    (-13.042075, -48.269082),
    (-11.82495, -48.581587),
    (-10.600355, -48.863406),
    (-9.369066, -49.114363),
    (-8.131858, -49.334297),
    (-6.889515, -49.523071),
    (-5.642819, -49.680566),
    (-4.39256, -49.80668),
    (-3.139526, -49.901336),
    (-1.884509, -49.964474),
    (-0.628302, -49.996052),
    (0.628302, -49.996052),
    (1.884509, -49.964474),
    (3.139526, -49.901336),
    (4.39256, -49.80668),
    (5.642819, -49.680566),
    (6.889515, -49.523071),
    (8.131858, -49.334297),
    (9.369066, -49.114363),
    (10.600355, -48.863406),
    (11.82495, -48.581587),
    (13.042075, -48.269082),
    (14.250963, -47.926089),
    (15.45085, -47.552826),
    (16.640977, -47.149527),
    (17.820594, -46.716447),
    (18.988955, -46.25386),
    (20.145322, -45.762059),
    (21.288965, -45.241353),
    (22.419161, -44.692071),
    (23.535197, -44.114561),
    (24.636367, -43.509188),
    (25.721977, -42.876333),
    (26.79134, -42.216396),
    (27.843781, -41.529795),
    (28.878635, -40.816963),
    (29.895249, -40.078349),
    (30.892981, -39.314422),
    (31.871199, -38.525662),
    (32.829288, -37.712569),
    (33.76664, -36.875656),
    (34.682665, -36.015451),
    (35.576784, -35.132498),
    (36.448431, -34.227355),
    (37.297057, -33.300593),
    (38.122126, -32.352798),
    (38.923115, -31.384568),
    (39.69952, -30.396515),
    (40.45085, -29.389263),
    (41.17663, -28.363447),
    (41.876402, -27.319717),
    (42.549724, -26.258731),
    (43.196171, -25.18116),
    (43.815334, -24.087684),
    (44.406822, -22.978993),
    (44.970263, -21.855788),
    (45.505299, -20.718779),
    (46.011592, -19.568683),
    (46.488824, -18.406228),
    (46.936693, -17.232146),
    (47.354915, -16.04718),
    (47.743227, -14.852079),
    (48.101384, -13.647597),
    (48.429158, -12.434494),
    (48.726344, -11.213538),
    (48.992753, -9.985499),
    (49.228217, -8.751153),
    (49.432587, -7.511279),
    (49.605735, -6.266662),
    (49.747551, -5.018086),
    (49.857945, -3.76634),
    (49.936848, -2.512216),
    (49.984209, -1.256505),
    (50.0, -0.0),
    (35.0, 0.0),
    (34.988947, 0.879553),
    (34.955793, 1.758551),
    (34.900562, 2.636438),
    (34.823286, 3.51266),
    (34.724015, 4.386663),
    (34.602811, 5.257896),
    (34.459752, 6.125807),
    (34.294927, 6.989849),
    (34.108441, 7.849477),
    (33.900411, 8.704146),
    (33.670969, 9.553318),
    (33.420259, 10.396455),
    (33.148441, 11.233026),
    (32.855685, 12.062502),
    (32.542177, 12.884359),
    (32.208115, 13.698078),
    (31.853709, 14.503145),
    (31.479184, 15.299052),
    (31.084776, 16.085295),
    (30.670734, 16.861379),
    (30.23732, 17.626812),
    (29.784807, 18.381112),
    (29.313481, 19.123802),
    (28.823641, 19.854413),
    (28.315595, 20.572484),
    (27.789664, 21.27756),
    (27.246181, 21.969198),
    (26.685488, 22.646959),
    (26.10794, 23.310415),
    (25.513902, 23.959149),
    (24.903749, 24.592749),
    (24.277866, 25.210816),
    (23.636648, 25.812959),
    (22.980501, 26.398798),
    (22.30984, 26.967963),
    (21.625086, 27.520095),
    (20.926674, 28.054844),
    (20.215045, 28.571874),
    (19.490647, 29.070856),
    (18.753938, 29.551477),
    (18.005384, 30.013433),
    (17.245457, 30.456431),
    (16.474638, 30.880193),
    (15.693413, 31.28445),
    (14.902275, 31.668947),
    (14.101725, 32.033441),
    (13.292268, 32.377702),
    (12.474416, 32.701513),
    (11.648684, 33.004669),
    (10.815595, 33.286978),
    (9.975674, 33.548263),
    (9.129453, 33.788357),
    (8.277465, 34.007111),
    (7.420249, 34.204384),
    (6.558346, 34.380054),
    (5.692301, 34.534008),
    (4.82266, 34.66615),
    (3.949973, 34.776396),
    (3.074792, 34.864676),
    (2.197668, 34.930935),
    (1.319156, 34.975132),
    (0.439811, 34.997237),
    (-0.439811, 34.997237),
    (-1.319156, 34.975132),
    (-2.197668, 34.930935),
    (-3.074792, 34.864676),
    (-3.949973, 34.776396),
    (-4.82266, 34.66615),
    (-5.692301, 34.534008),
    (-6.558346, 34.380054),
    (-7.420249, 34.204384),
    (-8.277465, 34.007111),
    (-9.129453, 33.788357),
    (-9.975674, 33.548263),
    (-10.815595, 33.286978),
    (-11.648684, 33.004669),
    (-12.474416, 32.701513),
    (-13.292268, 32.377702),
    (-14.101725, 32.033441),
    (-14.902275, 31.668947),
    (-15.693413, 31.28445),
    (-16.474638, 30.880193),
    (-17.245457, 30.456431),
    (-18.005384, 30.013433),
    (-18.753938, 29.551477),
    (-19.490647, 29.070856),
    (-20.215045, 28.571874),
    (-20.926674, 28.054844),
    (-21.625086, 27.520095),
    (-22.30984, 26.967963),
    (-22.980501, 26.398798),
    (-23.636648, 25.812959),
    (-24.277866, 25.210816),
    (-24.903749, 24.592749),
    (-25.513902, 23.959149),
    (-26.10794, 23.310415),
    (-26.685488, 22.646959),
    (-27.246181, 21.969198),
    (-27.789664, 21.27756),
    (-28.315595, 20.572484),
    (-28.823641, 19.854413),
    (-29.313481, 19.123802),
    (-29.784807, 18.381112),
    (-30.23732, 17.626812),
    (-30.670734, 16.861379),
    (-31.084776, 16.085295),
    (-31.479184, 15.299052),
    (-31.853709, 14.503145),
    (-32.208115, 13.698078),
    (-32.542177, 12.884359),
    (-32.855685, 12.062502),
    (-33.148441, 11.233026),
    (-33.420259, 10.396455),
    (-33.670969, 9.553318),
    (-33.900411, 8.704146),
    (-34.108441, 7.849477),
    (-34.294927, 6.989849),
    (-34.459752, 6.125807),
    (-34.602811, 5.257896),
    (-34.724015, 4.386663),
    (-34.823286, 3.51266),
    (-34.900562, 2.636438),
    (-34.955793, 1.758551),
    (-34.988947, 0.879553),
    (-35.0, 0.0),
    (-34.988947, -0.879553),
    (-34.955793, -1.758551),
    (-34.900562, -2.636438),
    (-34.823286, -3.51266),
    (-34.724015, -4.386663),
    (-34.602811, -5.257896),
    (-34.459752, -6.125807),
    (-34.294927, -6.989849),
    (-34.108441, -7.849477),
    (-33.900411, -8.704146),
    (-33.670969, -9.553318),
    (-33.420259, -10.396455),
    (-33.148441, -11.233026),
    (-32.855685, -12.062502),
    (-32.542177, -12.884359),
    (-32.208115, -13.698078),
    (-31.853709, -14.503145),
    (-31.479184, -15.299052),
    (-31.084776, -16.085295),
    (-30.670734, -16.861379),
    (-30.23732, -17.626812),
    (-29.784807, -18.381112),
    (-29.313481, -19.123802),
    (-28.823641, -19.854413),
    (-28.315595, -20.572484),
    (-27.789664, -21.27756),
    (-27.246181, -21.969198),
    (-26.685488, -22.646959),
    (-26.10794, -23.310415),
    (-25.513902, -23.959149),
    (-24.903749, -24.592749),
    (-24.277866, -25.210816),
    (-23.636648, -25.812959),
    (-22.980501, -26.398798),
    (-22.30984, -26.967963),
    (-21.625086, -27.520095),
    (-20.926674, -28.054844),
    (-20.215045, -28.571874),
    (-19.490647, -29.070856),
    (-18.753938, -29.551477),
    (-18.005384, -30.013433),
    (-17.245457, -30.456431),
    (-16.474638, -30.880193),
    (-15.693413, -31.28445),
    (-14.902275, -31.668947),
    (-14.101725, -32.033441),
    (-13.292268, -32.377702),
    (-12.474416, -32.701513),
    (-11.648684, -33.004669),
    (-10.815595, -33.286978),
    (-9.975674, -33.548263),
    (-9.129453, -33.788357),
    (-8.277465, -34.007111),
    (-7.420249, -34.204384),
    (-6.558346, -34.380054),
    (-5.692301, -34.534008),
    (-4.82266, -34.66615),
    (-3.949973, -34.776396),
    (-3.074792, -34.864676),
    (-2.197668, -34.930935),
    (-1.319156, -34.975132),
    (-0.439811, -34.997237),
    (0.439811, -34.997237),
    (1.319156, -34.975132),
    (2.197668, -34.930935),
    (3.074792, -34.864676),
    (3.949973, -34.776396),
    (4.82266, -34.66615),
    (5.692301, -34.534008),
    (6.558346, -34.380054),
    (7.420249, -34.204384),
    (8.277465, -34.007111),
    (9.129453, -33.788357),
    (9.975674, -33.548263),
    (10.815595, -33.286978),
    (11.648684, -33.004669),
    (12.474416, -32.701513),
    (13.292268, -32.377702),
    (14.101725, -32.033441),
    (14.902275, -31.668947),
    (15.693413, -31.28445),
    (16.474638, -30.880193),
    (17.245457, -30.456431),
    (18.005384, -30.013433),
    (18.753938, -29.551477),
    (19.490647, -29.070856),
    (20.215045, -28.571874),
    (20.926674, -28.054844),
    (21.625086, -27.520095),
    (22.30984, -26.967963),
    (22.980501, -26.398798),
    (23.636648, -25.812959),
    (24.277866, -25.210816),
    (24.903749, -24.592749),
    (25.513902, -23.959149),
    (26.10794, -23.310415),
    (26.685488, -22.646959),
    (27.246181, -21.969198),
    (27.789664, -21.27756),
    (28.315595, -20.572484),
    (28.823641, -19.854413),
    (29.313481, -19.123802),
    (29.784807, -18.381112),
    (30.23732, -17.626812),
    (30.670734, -16.861379),
    (31.084776, -16.085295),
    (31.479184, -15.299052),
    (31.853709, -14.503145),
    (32.208115, -13.698078),
    (32.542177, -12.884359),
    (32.855685, -12.062502),
    (33.148441, -11.233026),
    (33.420259, -10.396455),
    (33.670969, -9.553318),
    (33.900411, -8.704146),
    (34.108441, -7.849477),
    (34.294927, -6.989849),
    (34.459752, -6.125807),
    (34.602811, -5.257896),
    (34.724015, -4.386663),
    (34.823286, -3.51266),
    (34.900562, -2.636438),
    (34.955793, -1.758551),
    (34.988947, -0.879553),
];
