<commit_before>﻿using BruTile;
using Mapsui.Geometries;
using Mapsui.Layers;
using Mapsui.Providers;
using Mapsui.Styles;
using System;
using System.Collections.Generic;
using System.IO;

namespace Mapsui.Tests.Common
{
    public static class ArrangeRenderingTests
    {
        public static readonly List<Func<Map>> Samples = new List<Func<Map>>();

        static ArrangeRenderingTests()
        {
            Samples.Add(Labels);
            Samples.Add(PointsWithVectorStyle);
            Samples.Add(PointsWithBitmapSymbols);
            Samples.Add(PointsWithBitmapRotatedAndOffset);
            Samples.Add(PointsWithDifferentSymbolTypes);
            Samples.Add(PointsWithWorldUnits);
            Samples.Add(Polygon);
            Samples.Add(Line);
            Samples.Add(Tiles);
        }

        public static Map PointsWithVectorStyle()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            map.Layers.Add(new MemoryLayer
                {
                    Style = null,
                    DataSource = Utilities.CreateProviderWithPointsWithVectorStyle()
                });
            return map;
        }

        public static Map PointsWithBitmapSymbols()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            var layer = new MemoryLayer
                {
                    Style = null,
                    DataSource = Utilities.CreateProviderWithPointsWithSymbolStyles()
                };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithBitmapRotatedAndOffset()
        {
            var map = new Map { Viewport = { Center = new Point(80, 80), Width = 200, Height = 200, Resolution = 1 } };
            var layer = new MemoryLayer { DataSource = Utilities.CreateProviderWithRotatedBitmapSymbols() };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithDifferentSymbolTypes()
        {
            var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
            var features = new Features
                {
                    Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Ellipse}),
                    Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Rectangle})
                };
            var layer = new MemoryLayer { DataSource = new MemoryProvider(features) };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithWorldUnits()
        {
            var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
            var features = new Features
                {
                    Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {UnitType = UnitType.Pixel}),
                    Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {UnitType = UnitType.WorldUnit})
                };
            var layer = new MemoryLayer { DataSource = new MemoryProvider(features) };
            map.Layers.Add(layer);
            return map;
        }

        public static Map Polygon()
        {
            var map = new Map
            {
                Viewport =
                    {
                        Center = new Point(0, 0),
                        Width = 600,
                        Height = 400,
                        Resolution = 63000
                    }
            };

            var layer = new MemoryLayer();
            var provider = Utilities.CreatePolygonProvider();
            layer.DataSource = provider;
            map.Layers.Add(layer);
            return map;
        }

        public static Map Line()
        {
            var map = new Map
            {
                Viewport =
                    {
                        Center = new Point(0, 0),
                        Width = 600,
                        Height = 400,
                        Resolution = 63000
                    }
            };

            var layer = new MemoryLayer { Style = null };
            var provider = Utilities.CreateLineProvider();
            layer.DataSource = provider;
            map.Layers.Add(layer);
            return map;
        }

        public static Map Tiles()
        {
            var map = new Map
            {
                Viewport =
                {
                    Center = new Point(-7641856, 4804912),
                    Width = 600,
                    Height = 400,
                    Resolution = 51116
                }
            };

            var tileIndexes = new[]
            {
                new TileIndex(0, 0, "1"),
                new TileIndex(1, 0, "1"),
                new TileIndex(0, 1, "1"),
                new TileIndex(1, 1, "1")
            };

            var features = TileIndexToFeatures(tileIndexes, new SampleTileSource());
            map.Layers.Add(new MemoryLayer { DataSource = new MemoryProvider(features) });
            return map;
        }

        private static List<IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource)
        {
            var features = new List<IFeature>();
            foreach (var tileIndex in tileIndexes)
            {
                var tileInfo = new TileInfo
                {
                    Index = tileIndex,
                    Extent =
                        TileTransform.TileToWorld(new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level,
                            tileSource.Schema)
                };

                var feature = new Feature
                {
                    Geometry = new Raster(new MemoryStream(tileSource.Provider.GetTile(tileInfo)),
                            tileInfo.Extent.ToBoundingBox())
                };

                features.Add(feature);
            }
            return features;
        }

        public static Map Labels()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            map.Layers.Add(new MemoryLayer
            {
                Style = null,
                DataSource = CreateProviderWithLabels()
            });
            return map;

        }

        public static MemoryProvider CreateProviderWithLabels()
        {
            var features = new Features
                {
                    new Feature
                        {
                            Geometry = new Point(50, 50),
                            Styles = new[] {new VectorStyle {Fill = new Brush(Color.Gray), Outline = new Pen(Color.Black)}}<commit_msg>Adding layer names to ArrangeRenderingTests<commit_after>﻿using BruTile;
using Mapsui.Geometries;
using Mapsui.Layers;
using Mapsui.Providers;
using Mapsui.Styles;
using System;
using System.Collections.Generic;
using System.IO;

namespace Mapsui.Tests.Common
{
    public static class ArrangeRenderingTests
    {
        public static readonly List<Func<Map>> Samples = new List<Func<Map>>();

        static ArrangeRenderingTests()
        {
            Samples.Add(Labels);
            Samples.Add(PointsWithVectorStyle);
            Samples.Add(PointsWithBitmapSymbols);
            Samples.Add(PointsWithBitmapRotatedAndOffset);
            Samples.Add(PointsWithDifferentSymbolTypes);
            Samples.Add(PointsWithWorldUnits);
            Samples.Add(Polygon);
            Samples.Add(Line);
            Samples.Add(Tiles);
        }

        public static Map PointsWithVectorStyle()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            map.Layers.Add(new MemoryLayer
            {
                Style = null,
                DataSource = Utilities.CreateProviderWithPointsWithVectorStyle()
                ,
                LayerName = "Points with VectorStyle"
            });
            return map;
        }

        public static Map PointsWithBitmapSymbols()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            var layer = new MemoryLayer
            {
                Style = null,
                DataSource = Utilities.CreateProviderWithPointsWithSymbolStyles(),
                LayerName = "Points with bitmaps"
            };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithBitmapRotatedAndOffset()
        {
            var map = new Map { Viewport = { Center = new Point(80, 80), Width = 200, Height = 200, Resolution = 1 } };
            var layer = new MemoryLayer
            {
                DataSource = Utilities.CreateProviderWithRotatedBitmapSymbols(), 
                LayerName = "Points with rotated bitmaps"
            };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithDifferentSymbolTypes()
        {
            var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
            var features = new Features
            {
                Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Ellipse}),
                Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Rectangle})
            };
            var layer = new MemoryLayer
            {
                DataSource = new MemoryProvider(features),
                LayerName = "Points with various symbol types"
            };
            map.Layers.Add(layer);
            return map;
        }

        public static Map PointsWithWorldUnits()
        {
            var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
            var features = new Features
            {
                Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {UnitType = UnitType.Pixel}),
                Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {UnitType = UnitType.WorldUnit})
            };
            var layer = new MemoryLayer { DataSource = new MemoryProvider(features), LayerName = "Points in world units"};
            map.Layers.Add(layer);
            return map;
        }

        public static Map Polygon()
        {
            var map = new Map
            {
                Viewport =
                {
                    Center = new Point(0, 0),
                    Width = 600,
                    Height = 400,
                    Resolution = 63000
                }
            };

            var layer = new MemoryLayer
            {
                DataSource = Utilities.CreatePolygonProvider(), 
                LayerName = "Polygon"
            };
            map.Layers.Add(layer);
            return map;
        }

        public static Map Line()
        {
            var map = new Map
            {
                Viewport =
                {
                    Center = new Point(0, 0),
                    Width = 600,
                    Height = 400,
                    Resolution = 63000
                }
            };

            var layer = new MemoryLayer
            {
                Style = null, 
                DataSource = Utilities.CreateLineProvider(), 
                LayerName = "Line"
            };

            map.Layers.Add(layer);
            return map;
        }

        public static Map Tiles()
        {
            var map = new Map
            {
                Viewport =
                {
                    Center = new Point(-7641856, 4804912),
                    Width = 600,
                    Height = 400,
                    Resolution = 51116
                }
            };

            var tileIndexes = new[]
            {
                new TileIndex(0, 0, "1"),
                new TileIndex(1, 0, "1"),
                new TileIndex(0, 1, "1"),
                new TileIndex(1, 1, "1")
            };

            var features = TileIndexToFeatures(tileIndexes, new SampleTileSource());
            map.Layers.Add(new MemoryLayer { DataSource = new MemoryProvider(features), LayerName = "Tiles"});
            return map;
        }

        private static List<IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource)
        {
            var features = new List<IFeature>();
            foreach (var tileIndex in tileIndexes)
            {
                var tileInfo = new TileInfo
                {
                    Index = tileIndex,
                    Extent =
                        TileTransform.TileToWorld(new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level,
                            tileSource.Schema)
                };

                var feature = new Feature
                {
                    Geometry = new Raster(new MemoryStream(tileSource.Provider.GetTile(tileInfo)),
                            tileInfo.Extent.ToBoundingBox())
                };

                features.Add(feature);
            }
            return features;
        }

        public static Map Labels()
        {
            var map = new Map { Viewport = { Center = new Point(100, 100), Width = 200, Height = 200, Resolution = 1 } };
            map.Layers.Add(new MemoryLayer
            {
                Style = null,
                DataSource = CreateProviderWithLabels(),
                LayerName = "Labels"
            });
            return map;

        }

        public static MemoryProvider CreateProviderWithLabels()
        {
            var features = new Features
                {
                    new Feature
                        {
                            Geometry = new Point(50, 50),
                            Styles = new[] {new VectorStyle {Fill = new Brush(Color.Gray), Outline = new Pen(Color.Black)}}
{'fraction_non_alphanumeric': 0.08479755538579067, 'fraction_numerical': 0.020695881658448503, 'mean_word_length': 1.3331173039533377, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5707272', 'n_tokens_mistral': 3905, 'n_tokens_neox': 3382, 'n_words': 901}