/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Florian Biermann (fbie@itu.dk) and others.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

 package dk.itu.pitlab.libeyetracking.data;

import com.theeyetribe.client.data.GazeData;

import dk.itu.pitlab.libeyetracking.core.Utils;

/**
 * A single, immutable frame describing the eye tracking state at some point in time.
 *
 * It contains coordinates for the current gaze point on the screen in pixels, the average position of the eyes,
 * projected onto the screen in pixels, the inter-pupillary distance in pixels and the head roll, based on the position
 * of both eyes, in degree.
 *
 * @author Florian Biermann, fbie@itu.dk
 */
public class Frame {

    private final Point2D gazePoint, eyeCenter;
    private final float ipd, roll;

    public Frame(Point2D gazePoint, Point2D eyeCenter, float idp, float roll) {
        this.gazePoint = gazePoint;
        this.eyeCenter = eyeCenter;
        this.ipd = idp;
        this.roll = roll;
    }

    /**
     * @return The current gaze coordinates in pixels.
     */
    public Point2D getGazePoint() {
        return gazePoint;
    }

    /**
     * @return The current average eye position projected onto the screen, in pixels.
     */
    public Point2D getEyeCenter() {
        return eyeCenter;
    }

    /**
     * @return The inter-pupillary distance in pixels.
     */
    public float getIpd() {
        return ipd;
    }

    /**
     * @return The current head roll, based on the position of both eyes, in degree.
     */
    public float getRoll() {
        return roll;
    }

    private static Frame zero = new Frame(Point2D.getZero(), Point2D.getZero(), 0f, 0f);

    /**
     * Return the empty frame. There is only one static instance of the empty frame.
     *
     * @return The empty frame.
     */
    public static Frame getZero() {
        return zero;
    }

    /**
     * Construct a Frame instance from a TET GazeData instance. <code>data</code> contains much information which we do
     * not really require on a day-to-day basis. Moreover, it is mutable, but for making things safe, we want an
     * immutable type instead. This static method also computes the convenience data, like IDP, roll and so on.
     *
     * @param data The original, mutable frame.
     * @return An immutable frame.
     */
    public static Frame fromGazeData(GazeData data) {
        if (data == null)
            return zero;
        return new Frame(
                Conversion.toImmutable(data.smoothedCoordinates),
                Conversion.toImmutable(Utils.getEyesCenterPixel(data)),
                (float) Utils.getIpd(data),
                (float) Utils.getHeadRoll(data));
    }
}

@@ -1384,16 +1384,19 @@
  at some
+%0A *
  point i
@@ -1468,32 +1468,35 @@
 on the screen in
+%0A *
  pixels, the ave
@@ -1521,19 +1521,16 @@
 he eyes,
-%0A *
  project
@@ -1547,16 +1547,19 @@
 e screen
+%0A *
  in pixe
@@ -1609,24 +1609,27 @@
 and the head
+%0A *
  roll, based
@@ -1644,19 +1644,16 @@
 position
-%0A *
  of both
@@ -2983,16 +2983,23 @@
 GazeData
+%0A     *
  instanc
@@ -3057,18 +3057,18 @@
 h we
- do
 %0A     *
+ do
  not
@@ -3121,16 +3121,23 @@
 r, it is
+%0A     *
  mutable
@@ -3176,23 +3176,16 @@
  want an
-%0A     *
  immutab
@@ -3191,16 +3191,23 @@
 ble type
+%0A     *
  instead
@@ -3262,16 +3262,23 @@
 ce data,
+%0A     *
  like ID

format docstrings