package org.mbari.seepsearch.core;

/**
 * <p>Exclusion filter based on ROV altitude. User can specify upper and/or
 * lower acceptable bounds.</p>
 * Use as:<br>
 * RovAltittudeFilter filter = new ROVAltitudeFilter();<br>
 * filter.setMaxAltitude(someAltitude);<br>
 * filter.setMinAltitude(someAltitudeThatIsLess);<br>
 * boolean accept = filter.accept(someRovAltitude);<br>
 * // If OK do something with the ROV data value.<br>
 *
 * <hr><br>
 *
 * <p>MBARI provides this documentation and code &quot;as is&quot;, with no
 * warranty, express or implied, of its quality or consistency. It is provided
 * without support and without obligation on the part of the Monterey Bay
 * Aquarium Research Institute to assist in its use, correction, modification,
 * or enhancement. This information should not be published or distributed to
 * third parties without specific written permission from MBARI.</p><br>
 *
 * Copyright 2002 MBARI.<br>
 * MBARI Proprietary Information. All rights reserved.<br><hr><br>
 *
 * $Log: RovAltitudeFilter.java,v $
 * Revision 1.2  2002/02/27 23:55:28  brian
 * Modified GridUtil to ignore rov fixes equal to 0 pressure. Other minor bug fixes.
 *
 * Revision 1.1  2002/02/06 00:39:54  brian
 * Started developing a panel to connect to VARS
 *<br><hr><br>
 *
 * @author  : $Author: brian $
 * @version : $Revision: 1.2 $
 */
public class RovAltitudeFilter {

    /**
     * Default Constructor. The default constructor does not apply any filter.
     * Use <i>setMaxAltitude</i> and<i>setMinAltitude</> to specify filter
     * parameters.
     */
    public RovAltitudeFilter() {
    }

    /**
     *
     * @param altitude An altitude value
     * @return true if the altitude argument is between the max and min altitudes.
     */
    public boolean accept(double altitude) {

        boolean acceptRovFix = false;
        // Check to see if the point is within the accepted altitude range

        if (Double.isNaN(maxAltitude)) { // Use all points
            acceptRovFix = true;
        } else {
            if (Double.isNaN(minAltitude)) { // Use all points < maxAltitude
                if (altitude <= maxAltitude) {
                    acceptRovFix = true;
                }
            } else {
                // Use points between min and max altitudes
                if ((altitude <= maxAltitude) & (altitude >= minAltitude)) {
                    acceptRovFix = true;
                }
            }
        }


        return acceptRovFix;

    }

    /**
     * Sets the upper limit of acceptable altitudes. If the maxAltitude is NaN,
     * no filtering is used and <i>accept()</> will always return true.
     * @param maxAltitude Maximum acceptable altitude.
     */
    public void setMaxAltitude(double maxAltitude) {
        this.maxAltitude = maxAltitude;
    }

    /**
     *
     * @return The maximum acceptable altitude.
     */
    public double getMaxAltitude() {
        return maxAltitude;
    }

    /**
     * Sets the lower limit of acceptable altitudes. If the minAltitude is NaN,
     * <i>accept()</> will return true for all values less than the maximum
     * altitude.
     * @param minAltitude Minimum acceptable altitude.
     */
    public void setMinAltitude(double minAltitude) {
        this.minAltitude = minAltitude;
    }

    /**
     *
     * @return The minimum acceptable altitude.
     */
    public double getMinAltitude() {
        return minAltitude;
    }

    private double maxAltitude = Double.NaN;
    private double minAltitude = Double.NaN;
}