// Copyright 2022 James Pace
// All Rights Reserved.
//
// For a license to this software contact
// James Pace at jpace121@gmail.com.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#ifndef J7S__COMMON_HPP_
#define J7S__COMMON_HPP_

namespace j7s
{

// The state after a single iteration of the solver.
enum class IterationState
{
    OK,
    CONVERGED
};

// A coordinate is pair of a cost input and the resulting the cost.
// We save them together to minimize cost function evaluations.
// This isn't the cleanest thing in the world, but it's worth saving
// evaluations.
struct Coordinate
{
    double input;
    double cost;

    Coordinate() : input{0.0}, cost{0.0} {};
    Coordinate(double input, double cost) : input{input}, cost{cost} {};

    // Sort by cost.
    bool operator<(const Coordinate & other) const { return (cost < other.cost); }
    bool operator<=(const Coordinate & other) const { return (cost <= other.cost); }
    bool operator>(const Coordinate & other) const { return (cost > other.cost); }
    bool operator>=(const Coordinate & other) const { return (cost >= other.cost); }
    bool operator==(const Coordinate & other) const { return (cost == other.cost); }
    bool operator!=(const Coordinate & other) const { return (cost != other.cost); }
};

}  // namespace j7s

#endif  // J7S__COMMON_HPP_
