<commit_before>﻿using UnityEngine;

namespace UnExt {

    public static class LayerMaskExtensions {

        /// <summary>
        /// Convert a layer mask (power of two) to its corresponding
        /// game object layer value (binary mask with a single 1).
        /// </summary>
        /// <param name="layerMask"></param>
        /// <returns>n such that 2 to the power of n = layer mask value.</returns>
        public static int MaskValue(this LayerMask layerMask) {
            int value = layerMask.value;

            for (int mask = 0; mask < 32; ++mask) {
                if (value == 1 << mask) {
                    return mask;
                }
            }

            throw new System.InvalidOperationException( "Cannot calculate a mask for a non power of two value" );
        }

    }

}
<commit_msg>Added some extension methods for LayerMask management.<commit_after>﻿using UnityEngine;

namespace UnExt {

    public static class LayerMaskExtensions {

        /// <summary>
        /// Convert a layer mask (power of two) to its corresponding
        /// game object layer value (binary mask with a single 1).
        /// </summary>
        /// <param name="layerMask"></param>
        /// <returns>n such that 2 to the power of n = layer mask value.</returns>
        public static int MaskValue(this LayerMask layerMask) {
            int value = layerMask.value;

            for (int mask = 0; mask < 32; ++mask) {
                if (value == 1 << mask) {
                    return mask;
                }
            }

            throw new System.InvalidOperationException( "Cannot calculate a mask for a non power of two value" );
        }

        public static LayerMask CreateMask(GameObject go) {
            return new LayerMask() { value = Mathf.RoundToInt(Mathf.Pow(2, go.layer)) };
        }

        public static bool Matches(this LayerMask layerMask, GameObject go) {
            return layerMask.ContainsLayer(CreateMask(go));
        }

        /// <summary>
        /// Determine if a layer mask contains at least one layer from an int mask.
        /// </summary>
        /// <param name="layerMask"></param>
        /// <param name="layer">An int containing the layers to check.</param>
        /// <returns>
        /// <code>false</code> if none of the layers in layer is in this LayerMask;
        /// <code>true</code> otherwise.
        /// </returns>
        public static bool ContainsLayer(this LayerMask layerMask, int layer) {
            return (layerMask.value & layer) != 0;
        }

        /// <summary>
        /// Determine if a layer mask contains all the layers from an int mask.
        /// </summary>
        /// <param name="layerMask"></param>
        /// <param name="layer">An int containing the layers to check.</param>
        /// <returns>
        /// <code>true</code> if all of the layers in layer are in this LayerMask;
        /// <code>false</code> otherwise.
        /// </returns>
        public static bool ContainsLayers(this LayerMask layerMask, int layers) {
            return (layerMask.value & layers) == layers;
        }

    }

}

{'fraction_non_alphanumeric': 0.11373801916932907, 'fraction_numerical': 0.0044728434504792336, 'mean_word_length': 1.7930419268510258, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, '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': '7532360', 'n_tokens_mistral': 829, 'n_tokens_neox': 781, 'n_words': 296}