<commit_before>﻿//----------------------------------------------------------------------------
// <copyright file="MarkerHolder.cs" company="Delft University of Technology">
//     Copyright 2015, Delft University of Technology
//
//     This software is licensed under the terms of the MIT License.
//     A copy of the license should be included with this software. If not,
//     see http://opensource.org/licenses/MIT for the full license.
// </copyright>
//----------------------------------------------------------------------------
namespace Projection
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using Network;
    using UnityEngine;

    /// <summary>
    /// A class that handles marker registration and updates positions.
    /// </summary>
    public class MarkerHolder : MonoBehaviour
    {
        /// <summary>
        /// Scale of the object.
        /// </summary>
        [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Unity Property")]
        public float Scale = 1;

        /// <summary>
        /// Collection of all registered to this class. 
        /// </summary>
        private Dictionary<int, Marker> markerTable = new Dictionary<int, Marker>();

        /// <summary>
        /// How long are we willing to wait after losing track of a marker. 
        /// </summary>
        private long patience = 1; // 1000 * 10000; // 1000 milliseconds 

        /// <summary>
        /// Gets or sets the central level marker, this should be visible. 
        /// </summary>
        public Marker Parent { get; set; }

        /// <summary>
        /// Registers a new marker.
        /// <para>
        /// The <c>register</c> argument should not be null or contain a null Marker.
        /// </para>
        /// <para>
        /// This method adds the indicated marker as a child to the parent marker, or sets
        /// the marker as parent marker if no parent marker existed yet.
        /// </para>
        /// </summary>
        /// <param name="register">The marker register parameter that registers the new marker.</param>
        public void OnMarkerRegister(MarkerRegister register)
        {
            if (register == null)
            {
                throw new ArgumentNullException("register");
            }

            if (register.RegisteredMarker == null)
            {
                throw new ArgumentException("Invalid marker", "register");
            }

            this.markerTable.Add(register.RegisteredMarker.ID, register.RegisteredMarker);
        }

        /// <summary>
        /// Gets a marker by ID.
        /// </summary>
        /// <returns>The Marker.</returns>
        /// <param name="id">The ID.</param>
        /// <exception cref="KeyNotFoundException">If the marker is not (yet) registered.</exception>
        public Marker GetMarker(int id)
        {
            if (this.markerTable.ContainsKey(id))
            {
                return this.markerTable[id];
            }
            else
            {
                throw new KeyNotFoundException("this marker is not registered");
            }
        }

        /// <summary>
        /// Updates the position of all markers.
        /// </summary>
        public void Update()
        {
            if (this.Parent == null || this.Parent.LocalPosition == null)
            {
				Debug.Log ("No marker is visible");
                return;
            }

            foreach (Marker marker in this.markerTable.Values)
            {
                marker.UpdatePosition(this.Parent);
            }
        }

        /// <summary>
        /// Receives and handles all server updates.
        /// </summary>
        /// <param name="update">The update to be handled.</param>
        public void OnServerUpdate(AbstractUpdate update)
        {
            if (update == null)
            {
                throw new ArgumentNullException("update");
            }

            if (update.Type == UpdateType.UpdatePosition)
            {
                this.OnPositionUpdate(update as PositionUpdate);
            }
            else if (update.Type == UpdateType.UpdateRotation)
            {
                this.OnRotationUpdate(update as RotationUpdate);
            }
        }

        /// <summary>
        /// Called whenever a marker is seen by the detector.
        /// <para>
        /// The <c>position</c> argument should not be null.
        /// </para>
        /// <para>
        /// This method updates the local position of the marker, and possibly changes the parent of 
        /// all markers to the indicated marker if the current parent is no longer visible.
        /// </para>
        /// </summary>
        /// <param name="position">The marker position, not null.</param>
        /// <exception cref="ArgumentNullException">If <c>position == null</c>.</exception>
        public void OnMarkerSeen(MarkerPosition position)
        {
            if (position == null)
            {
                throw new ArgumentNullException("position");
            }
            Marker marker = this.GetMarker(position.ID);
            this.SelectParent(marker);
            marker.LocalPosition = position;
        }

        /// <summary>
        /// Sees if the marker is more suited for being the level marker then the old marker. 
        /// If updatedMarker has been seen more recently then the parent+patience and the updateMarker is complete then replace.
        /// </summary>
        /// <param name="updatedMarker">The new parent Marker, not null.</param>
        public void SelectParent(Marker updatedMarker)
        {
            if (updatedMarker == null)
            {
                throw new ArgumentNullException("updatedMarker");
            }

            if (this.Parent == null || this.Parent.LocalPosition.TimeStamp.Ticks + this.patience < updatedMarker.LocalPosition.TimeStamp.Ticks)
            {
                if (updatedMarker.LocalPosition != null && updatedMarker.RemotePosition != null)
                {
                    this.Parent = updatedMarker;
                }
            }
        }

        /// <summary>
        /// Called whenever a RotationUpdate is received from the remote server.
        /// <para>
        /// The <c>update</c> argument should not be null. This method will update the rotation <commit_msg>extra safety check<commit_after>﻿//----------------------------------------------------------------------------
// <copyright file="MarkerHolder.cs" company="Delft University of Technology">
//     Copyright 2015, Delft University of Technology
//
//     This software is licensed under the terms of the MIT License.
//     A copy of the license should be included with this software. If not,
//     see http://opensource.org/licenses/MIT for the full license.
// </copyright>
//----------------------------------------------------------------------------
namespace Projection
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using Network;
    using UnityEngine;

    /// <summary>
    /// A class that handles marker registration and updates positions.
    /// </summary>
    public class MarkerHolder : MonoBehaviour
    {
        /// <summary>
        /// Scale of the object.
        /// </summary>
        [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Unity Property")]
        public float Scale = 1;

        /// <summary>
        /// Collection of all registered to this class. 
        /// </summary>
        private Dictionary<int, Marker> markerTable = new Dictionary<int, Marker>();

        /// <summary>
        /// How long are we willing to wait after losing track of a marker. 
        /// </summary>
        private long patience = 1; // 1000 * 10000; // 1000 milliseconds 

        /// <summary>
        /// Gets or sets the central level marker, this should be visible. 
        /// </summary>
        public Marker Parent { get; set; }

        /// <summary>
        /// Registers a new marker.
        /// <para>
        /// The <c>register</c> argument should not be null or contain a null Marker.
        /// </para>
        /// <para>
        /// This method adds the indicated marker as a child to the parent marker, or sets
        /// the marker as parent marker if no parent marker existed yet.
        /// </para>
        /// </summary>
        /// <param name="register">The marker register parameter that registers the new marker.</param>
        public void OnMarkerRegister(MarkerRegister register)
        {
            if (register == null)
            {
                throw new ArgumentNullException("register");
            }

            if (register.RegisteredMarker == null)
            {
                throw new ArgumentException("Invalid marker", "register");
            }

            this.markerTable.Add(register.RegisteredMarker.ID, register.RegisteredMarker);
        }

        /// <summary>
        /// Gets a marker by ID.
        /// </summary>
        /// <returns>The Marker.</returns>
        /// <param name="id">The ID.</param>
        /// <exception cref="KeyNotFoundException">If the marker is not (yet) registered.</exception>
        public Marker GetMarker(int id)
        {
            if (this.markerTable.ContainsKey(id))
            {
                return this.markerTable[id];
            }
            else
            {
                throw new KeyNotFoundException("this marker is not registered");
            }
        }

        /// <summary>
        /// Updates the position of all markers.
        /// </summary>
        public void Update()
        {
            if (this.Parent == null || this.Parent.LocalPosition == null)
            {
				Debug.Log ("No marker is visible");
                return;
            }

            foreach (Marker marker in this.markerTable.Values)
            {
                marker.UpdatePosition(this.Parent);
            }
        }

        /// <summary>
        /// Receives and handles all server updates.
        /// </summary>
        /// <param name="update">The update to be handled.</param>
        public void OnServerUpdate(AbstractUpdate update)
        {
            if (update == null)
            {
                throw new ArgumentNullException("update");
            }

            if (update.Type == UpdateType.UpdatePosition)
            {
                this.OnPositionUpdate(update as PositionUpdate);
            }
            else if (update.Type == UpdateType.UpdateRotation)
            {
                this.OnRotationUpdate(update as RotationUpdate);
            }
        }

        /// <summary>
        /// Called whenever a marker is seen by the detector.
        /// <para>
        /// The <c>position</c> argument should not be null.
        /// </para>
        /// <para>
        /// This method updates the local position of the marker, and possibly changes the parent of 
        /// all markers to the indicated marker if the current parent is no longer visible.
        /// </para>
        /// </summary>
        /// <param name="position">The marker position, not null.</param>
        /// <exception cref="ArgumentNullException">If <c>position == null</c>.</exception>
        public void OnMarkerSeen(MarkerPosition position)
        {
            if (position == null)
            {
                throw new ArgumentNullException("position");
            }
            Marker marker = this.GetMarker(position.ID);
            this.SelectParent(marker);
            marker.LocalPosition = position;
        }

        /// <summary>
        /// Sees if the marker is more suited for being the level marker then the old marker. 
        /// If updatedMarker has been seen more recently then the parent+patience and the updateMarker is complete then replace.
        /// </summary>
        /// <param name="updatedMarker">The new parent Marker, not null.</param>
        public void SelectParent(Marker updatedMarker)
        {
            if (updatedMarker == null)
            {
                throw new ArgumentNullException("updatedMarker");
            }

            if (this.Parent == null || this.Parent.LocalPosition.TimeStamp.Ticks + this.patience < updatedMarker.LocalPosition.TimeStamp.Ticks)
            {
                if (updatedMarker.LocalPosition != null && updatedMarker.RemotePosition != null && updatedMarker.RemotePosition!=null)
                {
                    this.Parent = updatedMarker;
                }
            }
        }

        /// <summary>
        /// Called whenever a RotationUpdate is received from the remote server.
        /// <para>
        /// The <c>update</c> argument should not be null. This method will update the rotation 
{'fraction_non_alphanumeric': 0.130522556099076, 'fraction_numerical': 0.0035717058777855423, 'mean_word_length': 1.5364316660102402, 'pattern_counts': {'":': 0, '<': 125, '<?xml version=': 0, '>': 123, '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': '927254', 'n_tokens_mistral': 3096, 'n_tokens_neox': 2951, 'n_words': 981}