/* DatasetReader application (C#, .NET Framework)
   for the DATASET ID# 2024-HAND-CHAIR-GESTURES.
      
   Radu-Daniel Vatavu, Ph.D.
   MintViz Lab, MANSiD Research Center
   Stefan cel Mare University of Suceava
   Suceava 720229, Romania
   radu.vatavu @usm.ro
   http://www.eed.usv.ro/~vatavu

 The academic publication for this work, and what should be used to cite it, is:
  
	Alexandru-Tudor Andrei, Laura-Bianca Bilius, Radu-Daniel Vatavu. (2024).
    Take a Seat, Make a Gesture: Charting User Preferences for On-Chair and 
	From-Chair Gesture Input. Proceedings of the CHI Conference on Human Factors 
	in Computing Systems. New York, NY, USA: ACM, 17 pages.
    https://doi.org/10.1145/3613904.3642028

 This software is distributed under the "New BSD License" agreement:

 Copyright(c) 2024, Radu-Daniel Vatavu. All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
    *Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Stefan cel Mare University of Suceava, nor 
      the names of its contributors may be used to endorse or promote products 
      derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Radu-Daniel Vatavu BE LIABLE FOR 
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using Geometry;
using System.Linq;

namespace GestureSharpToolkit
{
    public class GestureFeatures
    {
        /// <summary>
        /// Computes the production time of a [gesture]
        /// </summary>
        public static double ProductionTime(MovementPath gesture, PointSource source = PointSource.Raw)
        {
            Point[] points = gesture.GetPoints(source);
            if (points.Length <= 1)
                return 0;
            return points[points.Length - 1].T - points[0].T;
        }

        /// <summary>
        /// Computes the average magnitude of linear acceleration of a [gesture]
        /// </summary>
        public static double MeanAcceleration(MovementPath gesture, PointSource source = PointSource.Raw)
        {
            Point[] points = gesture.GetPoints(source);
            if (points.Length < 1) 
                return 0;
            return gesture.GetPoints(source).Average(p => p.Norm);
        }

        /// <summary>
        /// Computes the number of axes on which the average acceleration is larger than a specified threshold (0.1g)
        /// </summary>
        public static double NumAxesOfMovement(MovementPath gesture, PointSource source = PointSource.Raw)
        {
            Point[] points = gesture.GetPoints(source);
            if (points.Length < 1)
                return 0;

            double avgX = points.Average(p => Math.Abs(p.X));
            double avgY = points.Average(p => Math.Abs(p.Y));
            double avgZ = points.Average(p => Math.Abs(p.Z));

            return (avgX > 0.1 ? 1 : 0) + (avgY > 0.1 ? 1 : 0) + (avgZ > 0.1 ? 1 : 0);
        }
    }
}