//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#pragma once

namespace VWFC
{
	namespace Math
	{
		class VWLine3D
		{
		public:
								VWLine3D();
								VWLine3D(const VWPoint3D& begPt, const VWPoint3D& endPt);
								VWLine3D(const VWLine3D& src);
			virtual				~VWLine3D();

			VWLine3D&			operator=(const VWLine3D& src);

			const VWPoint3D&	GetStart() const;
			VWPoint3D&			GetStart();
			const VWPoint3D&	GetEnd() const;
			VWPoint3D&			GetEnd();
			void				GetLine(VWPoint3D& outPtStart, VWPoint3D& outPtEnd) const;

			void				SetStart(const VWPoint3D& pt);
			void				SetEnd(const VWPoint3D& pt);
			void				SetLine(const VWPoint3D& ptStart, const VWPoint3D& ptEnd);

			void				ReverseSides();

			VWLine3D			operator+(const VWPoint3D& p) const;
			VWLine3D			operator-(const VWPoint3D& p) const;
			VWLine3D			operator*(double scalar) const;
			VWLine3D			operator/(double scalar) const;

			VWLine3D&			operator+=(const VWPoint3D& p);
			VWLine3D&			operator-=(const VWPoint3D& p);
			VWLine3D&			operator*=(double scalar);
			VWLine3D&			operator/=(double scalar);

		// math functions
		public:
			// return the center point of the line
			VWPoint2D			CenterPt() const;
			// return the length of the line
			double				GetLength() const;
			// min distance from a point to this line
			// this is the distance from the point to the nearest point on the line
			// which is the line perpendicular to the given one trough the specified point
			double				GetDistance(const VWPoint3D& pt) const;
			// get vertical distance from the point to the line
			// NOTE! no check if the point is on the projection of the line is check
			double				GetVerticalDistance(const VWPoint3D& pt) const;
			// return the direction vector of the line (end - start)
			VWPoint3D			GetDirectionVector() const;

		// tools
		public:
			static double	GetVerticalDistance(	double ax, double ay, double az,
													double bx, double by, double bz,
													double px, double py);

		protected:
			VWPoint3D			m_ptStart;
			VWPoint3D			m_ptEnd;
		};
	}
}