<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace SotAMapper
{
    /// <summary>
    /// convert between SotA map coords and (WPF drawing) canvas coords so that
    /// all data in the map scales into available rendering area on the canvas
    /// while preserving the aspect ratio of the data.
    /// 
    /// SotA Coords:  X,Y,Z => (North+,Up+,West+)
    /// Canvas Coord: X,Y => (Right+,Down+)
    /// </summary>
    public class MapCanvasConverter
    {
        private Map _map;
        private Canvas _canvas;
        private IEnumerable<MapCoord> _otherData;

        // margin maintained on the edge of the canvas so renderirng doesn't
        // occur right up to the edge.  specified as a % of the total width/height
        // of the drawing canvas
        private const double _canvasMarginWidthPercent = 5;
        private const double _canvasMarginHeightPercent = 5;

        // computed canvas margin values
        public double CanvasMarginX { get; private set; }
        public double CanvasMarginY { get; private set; }

        private double _mapUpperLeftX;
        private double _mapUpperLeftZ;

        private double _mapToCanvasScale;

        /// <summary>
        /// Converter needs the map data to be rendered, the canvas on which the
        /// data will be rendered, and any additional other map-like data to be rendered.
        /// "other" data would be, for example, the player position.
        /// </summary>
        public MapCanvasConverter(Map map, Canvas canvas, IEnumerable<MapCoord> otherData)
        {
            _map = map;
            _canvas = canvas;
            _otherData = otherData;

            // compute margin values, needed regardless of whether Init() succeeds

            var canvasWidth = _canvas.ActualWidth;
            var canvasHeight = _canvas.ActualHeight;

            CanvasMarginX = canvasWidth * (_canvasMarginWidthPercent / 100.0);
            CanvasMarginY = canvasHeight * (_canvasMarginHeightPercent / 100.0);
        }

        public bool Init()
        {
            if ((_map == null) || (_canvas == null))
                return false;

            // determine extents of map data

            float? minX = _map.MinLoc.X;
            float? minZ = _map.MinLoc.Z;
            float? maxX = _map.MaxLoc.X;
            float? maxZ = _map.MaxLoc.Z;

            if (_otherData != null)
            {<commit_msg>fixed crash when map data .csv file had no items<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace SotAMapper
{
    /// <summary>
    /// convert between SotA map coords and (WPF drawing) canvas coords so that
    /// all data in the map scales into available rendering area on the canvas
    /// while preserving the aspect ratio of the data.
    /// 
    /// SotA Coords:  X,Y,Z => (North+,Up+,West+)
    /// Canvas Coord: X,Y => (Right+,Down+)
    /// </summary>
    public class MapCanvasConverter
    {
        private Map _map;
        private Canvas _canvas;
        private IEnumerable<MapCoord> _otherData;

        // margin maintained on the edge of the canvas so renderirng doesn't
        // occur right up to the edge.  specified as a % of the total width/height
        // of the drawing canvas
        private const double _canvasMarginWidthPercent = 5;
        private const double _canvasMarginHeightPercent = 5;

        // computed canvas margin values
        public double CanvasMarginX { get; private set; }
        public double CanvasMarginY { get; private set; }

        private double _mapUpperLeftX;
        private double _mapUpperLeftZ;

        private double _mapToCanvasScale;

        /// <summary>
        /// Converter needs the map data to be rendered, the canvas on which the
        /// data will be rendered, and any additional other map-like data to be rendered.
        /// "other" data would be, for example, the player position.
        /// </summary>
        public MapCanvasConverter(Map map, Canvas canvas, IEnumerable<MapCoord> otherData)
        {
            _map = map;
            _canvas = canvas;
            _otherData = otherData;

            // compute margin values, needed regardless of whether Init() succeeds

            var canvasWidth = _canvas.ActualWidth;
            var canvasHeight = _canvas.ActualHeight;

            CanvasMarginX = canvasWidth * (_canvasMarginWidthPercent / 100.0);
            CanvasMarginY = canvasHeight * (_canvasMarginHeightPercent / 100.0);
        }

        public bool Init()
        {
            if ((_map == null) || (_canvas == null) || (_map.MinLoc == null) || (_map.MaxLoc == null))
                return false;

            // determine extents of map data

            float? minX = _map.MinLoc.X;
            float? minZ = _map.MinLoc.Z;
            float? maxX = _map.MaxLoc.X;
            float? maxZ = _map.MaxLoc.Z;

            if (_otherData != null)
            {
{'fraction_non_alphanumeric': 0.08732174252783746, 'fraction_numerical': 0.003907013088493847, 'mean_word_length': 2.067705212702217, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '6512389', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1336, 'n_words': 483}