/// Copyright (c) 2009 Ruben Penalva. All rights reserved.
/// Redistribution and use in source and binary forms, with or without modification, 
/// are permitted provided that the following conditions are met:
///    1. Redistributions of source code must retain the above copyright notice, this 
///    list of conditions and the following disclaimer.
///    2. 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.
///    3. The name of the author may not be used to endorse or promote products derived
///    from this software without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.

/// @file Logic.h
/// This source file is part of Gpu Quadratic Curve Render Test.
/// The file holds the Logic class interface.
/// @author Ruben Penalva (ruben.penalva@rpenalva.com)

#ifndef _LOGIC_H_
#define _LOGIC_H_

#include "Point.h"
#include "Line.h"

#include <vector>

namespace GpuQuadraticCurveRender
{

/// @brief It handles all the logic of the test. Its called by Runner, 
/// which act as a controller between Logic and Render. It contains
/// the points, segments and lines of the letters queried.
class Logic
{
public:
	/// Constructor
	Logic(void);

	/// Destructor
	~Logic(void);

	/// @brief Enable/Disable points showing
	/// @note Probably this is not the best site for
	/// this method
	void EnablePoints(void);

	/// @brief Enable/Disable lines showing
	/// @note Probably this is not the best site for
	/// this method
	void EnableLines(void);

	/// @brief Enable/Disable triangles showing
	/// @note Probably this is not the best site for
	/// this method
	void EnableTriangles(void);

	/// @brief check if points are enabled
	bool ArePointsEnabled(void);

	/// @brief check if lines are enabled
	bool AreLinesEnabled(void);
	
	/// @brief check if triangles are enabled
	bool AreTrianglesEnabled(void);

	/// @brief Gets quadratic curve control points
	const std::vector<Point>& GetQuadraticControlPoints(void) const;

	/// @brief Gets quadratic curve control lines
	const std::vector<Line>& GetQuadraticLines(void) const;

	/// @brief Gets quadratic curve control indices
	const std::vector<int>& GetQuadraticIndices(void) const;

	/// @brief Sets the position of a control point of the curve
	/// @param pointIndex the index of the point: 0-2 
	/// @param point the new point
	void SetQuadraticControlPoint(int pointIndex, const Point& point);

	/// @brief checks for a intersection beetwen a point an the control points
	/// @param point the point to be checked
	/// @param controlPointIndex index of the control point intersected (output)
	/// @param pointSixe size of the point
	/// @return true if there is a intersection, false otherwise
	bool AreQuadraticControlPointsIntersected(const Point& point, int& controlPointIndex, float pointSize);

private:
	/// Quadratic curve control points
	std::vector<Point> m_quadraticControlPoints;

	/// Quadratic curve lines
	std::vector<Line> m_quadraticLines;

	/// Quadratic curve indices
	std::vector<int> m_quadraticIndices;

	/// Are points enabled?
	bool m_enabledPoints;
	
	/// Are lines enabled?
	bool m_enabledLines;

	/// Are triangles enabled?
	bool m_enabledTriangles;

	/// @note hide copy constructor from interface user
	Logic(const Logic&);

	/// @note hide assignment operator from interface user
	Logic& operator=(const Logic&);

	bool AreControlPointsIntersected(const std::vector<Point>& points, const Point& point, int& controlPointIndex, float pointSize);
};

}

#endif