<commit_before>using Mapsui.Providers;
using Mapsui.Rendering.iOS.ExtensionMethods;
using Mapsui.Styles;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using System.IO;
using Point = Mapsui.Geometries.Point;

namespace Mapsui.Rendering.iOS
{
    public class PointRenderer2
    {
        private const double RadiansPerDegree = 0.0174532925f;

        public static void RenderPoint(CALayer target, Point point, IStyle style, IViewport viewport, IFeature feature)
        {
            CALayer symbol;
			float rotation = 0;
			float scale = 1;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;
				rotation = (float)symbolStyle.SymbolRotation;
				scale = (float)symbolStyle.SymbolScale;

				if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle);
                }

                if (symbolStyle.Outline != null)
                {
                    symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
                    symbol.BorderWidth = (float)symbolStyle.Outline.Width;
                }

            }
            else if (style is VectorStyle)
            {
                var vectorStyle = (VectorStyle)style;
                symbol = CreateSymbolFromVectorStyle(vectorStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle(new VectorStyle());
            }

			symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
            target.AddSublayer(symbol);
        }

        private static CALayer CreateSymbolFromVectorStyle(VectorStyle style)
        {
            const int defaultWidth = 32;
            const int defaultHeight = 32;

            var symbol = new CAShapeLayer();

            if (style.Fill != null && style.Fill.Color != null)
            {
                symbol.FillColor = style.Fill.Color.ToCG();
            }
            else
            {
                symbol.BackgroundColor = new CGColor(0, 0, 0, 0);
            }

            if (style.Outline != null)
            {
                symbol.LineWidth = (float)style.Outline.Width;
                symbol.StrokeColor = style.Outline.Color.ToCG();
            }

            var frame = new RectangleF(-defaultWidth * 0.5f, -defaultHeight * 0.5f, defaultWidth, defaultHeight);
            symbol.Path = UIBezierPath.FromRoundedRect(frame, frame.Width / 2).CGPath;

            return symbol;
        }

        private static CALayer CreateSymbolFromBitmap(SymbolStyle style)
        {
            var symbol = new CALayer();
			var image = ToUIImage(BitmapRegistry.Instance.Get(style.BitmapId));

            symbol.Contents = image.CGImage;
            symbol.Frame = new RectangleF(-image.Size.Width * 0.5f, -image.Size.Height * 0.5f, image.Size.Width, image.Size.Height);

            symbol.Opacity = (float)style.Opacity;

            return symbol;
        }

        private static CGAffineTransform CreateAffineTransform(double rotation, Point position, float scale)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((float)position.X, (float)position.Y);
            var transformRotate = CGAffineTransform.MakeRotation((float)(rotation * RadiansPerDegree));
			var transformScale = CGAffineTransform.MakeScale (scale, scale);
            var transform = transformRotate * transformTranslate;
            return transform;
        }

        private static UIImage ToUIImage(Stream stream)
        {
            using (var data = NSData.FromArray(ToByteArray(stream)))
            {
                return UIImage.LoadFromData(data);
            }
        }

        private static byte[] ToByteArray(Stream input)
        {<commit_msg>Scaling ios point symbols<commit_after>using Mapsui.Providers;
using Mapsui.Rendering.iOS.ExtensionMethods;
using Mapsui.Styles;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using System.IO;
using Point = Mapsui.Geometries.Point;

namespace Mapsui.Rendering.iOS
{
    public class PointRenderer2
    {
        private const double RadiansPerDegree = 0.0174532925f;

        public static void RenderPoint(CALayer target, Point point, IStyle style, IViewport viewport, IFeature feature)
        {
            CALayer symbol;
			float rotation = 0;
			float scale = 1;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;
				rotation = (float)symbolStyle.SymbolRotation;
				scale = (float)symbolStyle.SymbolScale;

				if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle);
                }

                if (symbolStyle.Outline != null)
                {
                    symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
                    symbol.BorderWidth = (float)symbolStyle.Outline.Width;
                }

            }
            else if (style is VectorStyle)
            {
                var vectorStyle = (VectorStyle)style;
                symbol = CreateSymbolFromVectorStyle(vectorStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle(new VectorStyle());
            }

			symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
            target.AddSublayer(symbol);
        }

        private static CALayer CreateSymbolFromVectorStyle(VectorStyle style)
        {
            const int defaultWidth = 32;
            const int defaultHeight = 32;

            var symbol = new CAShapeLayer();

            if (style.Fill != null && style.Fill.Color != null)
            {
                symbol.FillColor = style.Fill.Color.ToCG();
            }
            else
            {
                symbol.BackgroundColor = new CGColor(0, 0, 0, 0);
            }

            if (style.Outline != null)
            {
                symbol.LineWidth = (float)style.Outline.Width;
                symbol.StrokeColor = style.Outline.Color.ToCG();
            }

            var frame = new RectangleF(-defaultWidth * 0.5f, -defaultHeight * 0.5f, defaultWidth, defaultHeight);
            symbol.Path = UIBezierPath.FromRoundedRect(frame, frame.Width / 2).CGPath;

            return symbol;
        }

        private static CALayer CreateSymbolFromBitmap(SymbolStyle style)
        {
            var symbol = new CALayer();
			var image = ToUIImage(BitmapRegistry.Instance.Get(style.BitmapId));

            symbol.Contents = image.CGImage;
            symbol.Frame = new RectangleF(-image.Size.Width * 0.5f, -image.Size.Height * 0.5f, image.Size.Width, image.Size.Height);

            symbol.Opacity = (float)style.Opacity;

            return symbol;
        }

        private static CGAffineTransform CreateAffineTransform(double rotation, Point position, float scale)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((float)position.X, (float)position.Y);
            var transformRotate = CGAffineTransform.MakeRotation((float)(rotation * RadiansPerDegree));
			var transformScale = CGAffineTransform.MakeScale (scale, scale);
            var transform = transformScale * transformRotate * transformTranslate;
            return transform;
        }

        private static UIImage ToUIImage(Stream stream)
        {
            using (var data = NSData.FromArray(ToByteArray(stream)))
            {
                return UIImage.LoadFromData(data);
            }
        }

        private static byte[] ToByteArray(Stream input)
        {
{'fraction_non_alphanumeric': 0.08348886400398159, 'fraction_numerical': 0.007963170337190495, 'mean_word_length': 1.8851399856424982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1673155', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2018, 'n_words': 448}