GazeData.cs 2.6 KB
Newer Older
1 2 3 4 5 6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

7
namespace TrackerBridge
8
{
9
    public struct GazeData
10 11 12 13 14 15
    {
        public readonly float leftX;
        public readonly float leftY;
        public readonly float rightX;
        public readonly float rightY;

16 17 18 19
        public readonly long trackerTimeStamp;
        public readonly long systemTimeStamp;

        public GazeData(float leftX, float leftY, float rightX, float rightY, long trackerTimeStamp, long systemTimeStamp)
20 21 22 23 24
        {
            this.leftX = leftX;
            this.leftY = leftY;
            this.rightX = rightX;
            this.rightY = rightY;
25 26 27
            this.trackerTimeStamp = trackerTimeStamp;
            this.systemTimeStamp = systemTimeStamp;
        }   
28 29 30

        public override string ToString()
        {
31 32
            FormattableString message = $"{leftX};{leftY};{rightX};{rightY};{trackerTimeStamp};{systemTimeStamp}";
            return FormattableString.Invariant(message);
33
        }
34 35 36 37 38 39 40 41 42 43 44 45 46

        public static GazeData operator +(GazeData a, GazeData b)
        {
            GazeData result = new GazeData(a.leftX + b.leftX,
                                           a.leftY + b.leftY,
                                           a.rightX + b.rightX,
                                           a.rightY + b.rightY,
                                           Math.Abs(a.trackerTimeStamp - b.trackerTimeStamp),
                                           Math.Abs(a.systemTimeStamp - b.systemTimeStamp));

            return result;
        }

47 48 49 50 51 52 53 54 55 56 57 58
        public static GazeData operator -(GazeData a, GazeData b)
        {
            GazeData result = new GazeData(a.leftX - b.leftX,
                                           a.leftY - b.leftY,
                                           a.rightX - b.rightX,
                                           a.rightY - b.rightY,
                                           Math.Abs(a.trackerTimeStamp - b.trackerTimeStamp),
                                           Math.Abs(a.systemTimeStamp - b.systemTimeStamp));

            return result;
        }

59 60 61 62 63 64 65 66 67 68 69
        public static GazeData operator /(GazeData a, Single b)
        {
            GazeData result = new GazeData(a.leftX / b,
                                           a.leftY / b,
                                           a.rightX / b,
                                           a.rightY / b,
                                           a.trackerTimeStamp / Convert.ToInt64(b),
                                           a.systemTimeStamp / Convert.ToInt64(b));

            return result;
        }
70 71
    }
}