<commit_before>﻿//   PartSpaceManager.cs
//
//  Author:
//       <NAME> <<EMAIL>>
//
//  Copyright (c) 2016 <NAME>

using UnityEngine;

namespace AT_Utils
{
    public class SpawnSpaceManager : ConfigNodeObject
    {
        protected Part part;
        protected Vessel vessel => part.vessel;

        [Persistent] public string SpawnSpace = string.Empty;
        [Persistent] public Vector3 SpawnOffset = Vector3.zero;
        [Persistent] public string SpawnTransform = string.Empty;
        protected Transform spawn_transform, spawn_transform_rotated;

        SpatialSensor Sensor;
        public bool SpawnSpaceEmpty => Sensor == null || Sensor.Empty;

        #region AutoRotation
        static readonly Quaternion xrot = Quaternion.Euler(90, 0, 0);
        static readonly Quaternion yrot = Quaternion.Euler(0, 90, 0);
        static readonly Quaternion zrot = Quaternion.Euler(0, 0, 90);
        static readonly Quaternion[,] swaps =
        {
            {Quaternion.identity,     zrot,                     yrot},
            {zrot.Inverse(),         Quaternion.identity,     xrot},
            {yrot.Inverse(),         xrot.Inverse(),         Quaternion.identity}
        };

        class SortedVector3
        {
            public float a, b, c;
            public uint i0, i1, i2;

            public uint this[int idx]
            {
                get
                {
                    if(idx == 0) return i0;
                    if(idx == 1) return i1;
                    if(idx == 2) return i2;
                    throw new System.ArgumentOutOfRangeException(nameof(idx));
                }
            }

            void add(float d, uint i)
            {
                if(d > a)
                {
                    b = a;
                    c = b;
                    a = d;
                    i2 = i1;
                    i1 = i0;
                    i0 = i;
                }
                else if(d > b)
                {
                    c = b;
                    b = d;
                    i2 = i1;
                    i1 = i;
                }
                else
                {
                    c = d;
                    i2 = i;
                }
            }

            public SortedVector3(Vector3 vec)
            {
                a = vec.x;
                b = c = float.NegativeInfinity;
                add(vec.y, 1);
                add(vec.z, 2);
            }
        }
        #endregion

        public MeshFilter Space { get; protected set; }
        private Metric spaceMetric;
        SortedVector3 spawn_space_sorted_size;
        public Metric SpaceMetric
        {
            get => spaceMetric;
            set
            {
                spaceMetric = value;
                spawn_space_sorted_size = new SortedVector3(spaceMetric.size);
            }
        }

        public virtual bool Valid => !SpaceMetric.Empty && spawn_transform != null;

        public override void Load(ConfigNode node)
        {
            base.Load(node);
            //deprecated config conversion
            if(string.IsNullOrEmpty(SpawnSpace))
                node.TryGetValue("HangarSpace", ref SpawnSpace);
        }

        public void UpdateMetric()
        {
            if(string.IsNullOrEmpty(SpawnSpace))
                return;
            SpaceMetric = new Metric(part, SpawnSpace, true);
        }

        public void Init(Part part)
        {
            this.part = part;
            if(!string.IsNullOrEmpty(SpawnSpace))
            {
                Space = part.FindModelComponent<MeshFilter>(SpawnSpace);
                if(Space != null)
                {
                    flip_mesh_if_needed(Space);
                    Space.gameObject.layer = 2; // IgnoreRaycast
                    UpdateMetric();
                }
            }<commit_msg>SSM: updating SpaceMetric from part when SpawnSpace is not defined<commit_after>﻿//   PartSpaceManager.cs
//
//  Author:
//       <NAME> <<EMAIL>>
//
//  Copyright (c) 2016 <NAME>

using UnityEngine;

namespace AT_Utils
{
    public class SpawnSpaceManager : ConfigNodeObject
    {
        protected Part part;
        protected Vessel vessel => part.vessel;

        [Persistent] public string SpawnSpace = string.Empty;
        [Persistent] public Vector3 SpawnOffset = Vector3.zero;
        [Persistent] public string SpawnTransform = string.Empty;
        protected Transform spawn_transform, spawn_transform_rotated;

        SpatialSensor Sensor;
        public bool SpawnSpaceEmpty => Sensor == null || Sensor.Empty;

        #region AutoRotation
        static readonly Quaternion xrot = Quaternion.Euler(90, 0, 0);
        static readonly Quaternion yrot = Quaternion.Euler(0, 90, 0);
        static readonly Quaternion zrot = Quaternion.Euler(0, 0, 90);
        static readonly Quaternion[,] swaps =
        {
            {Quaternion.identity,     zrot,                     yrot},
            {zrot.Inverse(),         Quaternion.identity,     xrot},
            {yrot.Inverse(),         xrot.Inverse(),         Quaternion.identity}
        };

        class SortedVector3
        {
            public float a, b, c;
            public uint i0, i1, i2;

            public uint this[int idx]
            {
                get
                {
                    if(idx == 0) return i0;
                    if(idx == 1) return i1;
                    if(idx == 2) return i2;
                    throw new System.ArgumentOutOfRangeException(nameof(idx));
                }
            }

            void add(float d, uint i)
            {
                if(d > a)
                {
                    b = a;
                    c = b;
                    a = d;
                    i2 = i1;
                    i1 = i0;
                    i0 = i;
                }
                else if(d > b)
                {
                    c = b;
                    b = d;
                    i2 = i1;
                    i1 = i;
                }
                else
                {
                    c = d;
                    i2 = i;
                }
            }

            public SortedVector3(Vector3 vec)
            {
                a = vec.x;
                b = c = float.NegativeInfinity;
                add(vec.y, 1);
                add(vec.z, 2);
            }
        }
        #endregion

        public MeshFilter Space { get; protected set; }
        private Metric spaceMetric;
        SortedVector3 spawn_space_sorted_size;
        public Metric SpaceMetric
        {
            get => spaceMetric;
            set
            {
                spaceMetric = value;
                spawn_space_sorted_size = new SortedVector3(spaceMetric.size);
            }
        }

        public virtual bool Valid => !SpaceMetric.Empty && spawn_transform != null;

        public override void Load(ConfigNode node)
        {
            base.Load(node);
            //deprecated config conversion
            if(string.IsNullOrEmpty(SpawnSpace))
                node.TryGetValue("HangarSpace", ref SpawnSpace);
        }

        public void UpdateMetric()
        {
            SpaceMetric = string.IsNullOrEmpty(SpawnSpace)
                ? new Metric(part, true)
                : new Metric(part, SpawnSpace, true);
        }

        public void Init(Part part)
        {
            this.part = part;
            if(!string.IsNullOrEmpty(SpawnSpace))
            {
                Space = part.FindModelComponent<MeshFilter>(SpawnSpace);
                if(Space != null)
                {
                    flip_mesh_if_needed(Space);
                    Space.gameObject.layer = 2; // IgnoreRaycast
                    UpdateMetric();
                }
            }
{'fraction_non_alphanumeric': 0.08354855371900827, 'fraction_numerical': 0.011363636363636364, 'mean_word_length': 1.13008800880088, 'pattern_counts': {'":': 0, '<': 13, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2198626', 'n_tokens_mistral': 2140, 'n_tokens_neox': 1997, 'n_words': 481}