<commit_before>﻿using UnityEngine;
using System.Collections;
using System.Linq;
using System;

namespace HexTiles
{
    public class HexTileMap : MonoBehaviour
    {
        [SerializeField]
        private float hexWidth = 1f;

        /// <summary>
        /// Hashtable of all hex tiles that are part of this map.
        /// </summary>
        private Hashtable Tiles
        {
            get
            {
                // Lazy init hexes hashtable
                if (tiles == null)
                {
                    // Add all the existing tiles in the scene that are part of this map
                    tiles = new Hashtable();
                    foreach (var tile in GetComponentsInChildren<HexTile>())
                    {
                        tiles.Add(QuantizeVector3ToHexCoords(tile.transform.position), tile);
                    }
                }
                return tiles;
            }
        }
        private Hashtable tiles;

        /// <summary>
        /// Highlighted tile for editing
        /// </summary>
        public HexCoords SelectedTile
        {
            get
            {
                return selectedTile;
            }
            private set
            {
                selectedTile = value;
            }
        }
        private HexCoords selectedTile;

        void OnDrawGizmos()
        {
            DrawGizmos(false);
        }

        void OnDrawGizmosSelected()
        {
            DrawGizmos(true);
        }

        void DrawGizmos(bool selected)
        {
            DrawHexGizmo(HexCoordsToWorldPosition(SelectedTile), selected);
        }

        /// <summary>
        /// Draws the outline of a hex at the specified position.
        /// Can be grey or green depending on whether it's highlighted or not.
        /// </summary>
        private void DrawHexGizmo(Vector3 position, bool highlight = false)
        {
            Gizmos.color = highlight ? Color.green : Color.gray;

            var verts = HexMetrics.GetHexVertices(hexWidth)
                .Select(v => v + position)
                .ToArray();

            for (var i = 0; i < verts.Length; i++)
            {
                Gizmos.DrawLine(verts[i], verts[(i + 1) % verts.Length]);
            }
        }

        /// <summary>
        /// Take a vector in world space and return the closest hex coords.
        /// </summary>
        public HexCoords QuantizeVector3ToHexCoords(Vector3 vIn)
        {
            var q = vIn.x * 2f/3f / (hexWidth/2f);
            var r = (-(float)vIn.x / 3f + Mathf.Sqrt(3f)/3f * (float)vIn.z) / (hexWidth/2f);

            return new HexCoords 
            { 
                Q = Mathf.RoundToInt(q), 
                R = Mathf.RoundToInt(r),<commit_msg>Refactored the way gizmos are drawn for HexTileMap<commit_after>﻿using UnityEngine;
using System.Collections;
using System.Linq;
using System;

namespace HexTiles
{
    public class HexTileMap : MonoBehaviour
    {
        [SerializeField]
        private float hexWidth = 1f;

        /// <summary>
        /// Hashtable of all hex tiles that are part of this map.
        /// </summary>
        private Hashtable Tiles
        {
            get
            {
                // Lazy init hexes hashtable
                if (tiles == null)
                {
                    // Add all the existing tiles in the scene that are part of this map
                    tiles = new Hashtable();
                    foreach (var tile in GetComponentsInChildren<HexTile>())
                    {
                        tiles.Add(QuantizeVector3ToHexCoords(tile.transform.position), tile);
                    }
                }
                return tiles;
            }
        }
        private Hashtable tiles;

        /// <summary>
        /// Highlighted tile for editing
        /// </summary>
        public HexCoords SelectedTile
        {
            get
            {
                return selectedTile;
            }
            set
            {
                selectedTile = value;
            }
        }
        private HexCoords selectedTile;

        /// <summary>
        /// Tile that the mouse is currently hovering over.
        /// </summary>
        public HexCoords HighlightedTile
        {
            get
            {
                return highlightedTile;
            }
            set
            {
                highlightedTile = value;
            }
        }
        private HexCoords highlightedTile;

        void OnDrawGizmos()
        {
            DrawHexGizmo(HexCoordsToWorldPosition(SelectedTile), Color.green);

            DrawHexGizmo(HexCoordsToWorldPosition(HighlightedTile), Color.grey);
        }

        /// <summary>
        /// Draws the outline of a hex at the specified position.
        /// Can be grey or green depending on whether it's highlighted or not.
        /// </summary>
        private void DrawHexGizmo(Vector3 position, Color color)
        {
            Gizmos.color = color;

            var verts = HexMetrics.GetHexVertices(hexWidth)
                .Select(v => v + position)
                .ToArray();

            for (var i = 0; i < verts.Length; i++)
            {
                Gizmos.DrawLine(verts[i], verts[(i + 1) % verts.Length]);
            }
        }

        /// <summary>
        /// Take a vector in world space and return the closest hex coords.
        /// </summary>
        public HexCoords QuantizeVector3ToHexCoords(Vector3 vIn)
        {
            var q = vIn.x * 2f/3f / (hexWidth/2f);
            var r = (-(float)vIn.x / 3f + Mathf.Sqrt(3f)/3f * (float)vIn.z) / (hexWidth/2f);

            return new HexCoords 
            { 
                Q = Mathf.RoundToInt(q), 
                R = Mathf.RoundToInt(r),
{'fraction_non_alphanumeric': 0.08881179531656548, 'fraction_numerical': 0.004856895056374675, 'mean_word_length': 1.2305609284332688, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908918', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1500, 'n_words': 403}