Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_CURVES_INCLUDED
Toshihiro Shimizu 890ddd
#define T_CURVES_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TGEOMETRY_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  TSegment Class to manage a segment
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TSegment
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPointD m_c0, m_c1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TSegment()
Toshihiro Shimizu 890ddd
		: m_c0(), m_c1(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! p0,p1  are the two control points
Toshihiro Shimizu 890ddd
	TSegment(const TPointD &p0, const TPointD &p1)
Toshihiro Shimizu 890ddd
		: m_c0(p0), m_c1(p1 - p0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSegment(double x0, double y0,
Toshihiro Shimizu 890ddd
			 double x1, double y1)
Toshihiro Shimizu 890ddd
		: m_c0(x0, y0), m_c1(x1 - x0, y1 - y0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSegment(const TSegment &src)
Toshihiro Shimizu 890ddd
		: m_c0(src.m_c0), m_c1(src.m_c1) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the point of segment at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getPoint(double t) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_c0 + t * m_c1;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return speed of segment.
Toshihiro Shimizu 890ddd
	TPointD getSpeed(double = 0) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_c1;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TPointD getP0() const { return m_c0; }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TPointD getP1() const { return m_c0 + m_c1; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b p.
Toshihiro Shimizu 890ddd
	void setP0(const TPointD &p)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_c1 += m_c0 - p;
Toshihiro Shimizu 890ddd
		m_c0 = p;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b p.
Toshihiro Shimizu 890ddd
	void setP1(const TPointD &p) { m_c1 = p - m_c0; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const TSegment &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_c0 == c.m_c0 && m_c1 == c.m_c1;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator!=(const TSegment &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return !operator==(c);
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return rect that contains the segment.
Toshihiro Shimizu 890ddd
	TRectD getBBox() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TRectD(getP0(), getP1());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the length of segment
Toshihiro Shimizu 890ddd
	double getLength() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return norm(m_c1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return true if segment is a point
Toshihiro Shimizu 890ddd
	bool isPoint(double err2 = TConsts::epsilon) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return norm2(m_c1) < err2;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TSegment &segment);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TAffine, TSegment
Toshihiro Shimizu 890ddd
inline TSegment operator*(const TAffine &aff, const TSegment &seg)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TSegment(aff * seg.getP0(), aff * seg.getP1());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
   TQuadratic class to manage a quadratic 
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TQuadratic
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPointD
Toshihiro Shimizu 890ddd
		m_p0,
Toshihiro Shimizu 890ddd
		m_p1,
Toshihiro Shimizu 890ddd
		m_p2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TQuadratic()
Toshihiro Shimizu 890ddd
		: m_p0(), m_p1(), m_p2() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! p0,p1,p2 are the three control points
Toshihiro Shimizu 890ddd
	TQuadratic(const TPointD &p0,
Toshihiro Shimizu 890ddd
			   const TPointD &p1,
Toshihiro Shimizu 890ddd
			   const TPointD &p2)
Toshihiro Shimizu 890ddd
		: m_p0(p0), m_p1(p1), m_p2(p2) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TQuadratic(const TQuadratic &src)
Toshihiro Shimizu 890ddd
		: m_p0(src.m_p0), m_p1(src.m_p1), m_p2(src.m_p2) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TQuadratic &operator=(const TQuadratic &src)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_p0 = src.m_p0;
Toshihiro Shimizu 890ddd
		m_p1 = src.m_p1;
Toshihiro Shimizu 890ddd
		m_p2 = src.m_p2;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the point of quadratic at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getPoint(double t) const;
Toshihiro Shimizu 890ddd
	double getX(double t) const;
Toshihiro Shimizu 890ddd
	double getY(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return speed of quadratic at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getSpeed(double t) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return 2 * ((t - 1) * m_p0 + (1.0 - 2.0 * t) * m_p1 + t * m_p2);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the y value of quadratic speed at parameter \b t.
Toshihiro Shimizu 890ddd
	double getSpeedY(double t) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return 2 * ((t - 1) * m_p0.y + (1.0 - 2.0 * t) * m_p1.y + t * m_p2.y);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return acceleration of quadratic.
Toshihiro Shimizu 890ddd
	TPointD getAcceleration(double = 0) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return 2.0 * (m_p0 + m_p2 - 2.0 * m_p1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Return curvature of quadratic at parameter \b t.
Toshihiro Shimizu 890ddd
	/*! Calcolo della curvatura per una Quadratica.
Toshihiro Shimizu 890ddd
        Vedi Farin pag.176 per la spiegazione della formula
Toshihiro Shimizu 890ddd
        usata.
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
	double getCurvature(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TPointD getP0() const { return m_p0; }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TPointD getP1() const { return m_p1; }
Toshihiro Shimizu 890ddd
	//!Return third control point \b P2.
Toshihiro Shimizu 890ddd
	TPointD getP2() const { return m_p2; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b p.
Toshihiro Shimizu 890ddd
	void setP0(const TPointD &p) { m_p0 = p; }
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b p.
Toshihiro Shimizu 890ddd
	void setP1(const TPointD &p) { m_p1 = p; }
Toshihiro Shimizu 890ddd
	//!Set the value of third control point \b P2 to \b p.
Toshihiro Shimizu 890ddd
	void setP2(const TPointD &p) { m_p2 = p; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const TQuadratic &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_p0 == c.m_p0 && m_p1 == c.m_p1 && m_p2 == c.m_p2;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator!=(const TQuadratic &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return !operator==(c);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return a parameter that correspond to the point \b p in the quadratic.
Toshihiro Shimizu 890ddd
	double getT(const TPointD &p) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getX(double y, double &x0, double &x1) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getY(double x, double &y0, double &y1) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
      N.B. if t==0 o t==1 return a quadratic with all points equal
Toshihiro Shimizu 890ddd
     */
Toshihiro Shimizu 890ddd
	void split(double t, TQuadratic &first, TQuadratic &second) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return rect that contains the quadratic.
Toshihiro Shimizu 890ddd
	TRectD getBBox() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
      Return length of an arc between parameters t0 t1.
Toshihiro Shimizu 890ddd
      N.B. Length returned is always positive. 
Toshihiro Shimizu 890ddd
      \note t0 and t1 are clamped to [0,1] interval
Toshihiro Shimizu 890ddd
      \note if t0>=t1 returns 0
Toshihiro Shimizu 890ddd
     */
Toshihiro Shimizu 890ddd
	double getLength(double t0, double t1) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getLength(double t1 = 1) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return getLength(0, t1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getApproximateLength(double t0, double t1, double error) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void reverse()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPointD app;
Toshihiro Shimizu 890ddd
		app = m_p0;
Toshihiro Shimizu 890ddd
		m_p0 = m_p2;
Toshihiro Shimizu 890ddd
		m_p2 = app;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TAffine, TQuadratic
Toshihiro Shimizu 890ddd
inline TQuadratic operator*(const TAffine &aff, const TQuadratic &curve)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TQuadratic quad;
Toshihiro Shimizu 890ddd
	quad.setP0(aff * curve.getP0());
Toshihiro Shimizu 890ddd
	quad.setP1(aff * curve.getP1());
Toshihiro Shimizu 890ddd
	quad.setP2(aff * curve.getP2());
Toshihiro Shimizu 890ddd
	return quad;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TQuadratic &curve);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline std::ostream &operator<<(std::ostream &out, const TQuadratic *curve)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(curve);
Toshihiro Shimizu 890ddd
	return out << *curve;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
   TCubic class to manage a cubic 
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TCubic
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPointD m_p0, m_p1, m_p2, m_p3;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TCubic()
Toshihiro Shimizu 890ddd
		: m_p0(), m_p1(), m_p2(), m_p3() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! p0,p1,p2,p3 are the four control points
Toshihiro Shimizu 890ddd
	TCubic(const TPointD &p0,
Toshihiro Shimizu 890ddd
		   const TPointD &p1,
Toshihiro Shimizu 890ddd
		   const TPointD &p2,
Toshihiro Shimizu 890ddd
		   const TPointD &p3)
Toshihiro Shimizu 890ddd
		: m_p0(p0), m_p1(p1), m_p2(p2), m_p3(p3) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TCubic(const TCubic &src)
Toshihiro Shimizu 890ddd
		: m_p0(src.m_p0), m_p1(src.m_p1), m_p2(src.m_p2), m_p3(src.m_p3) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TCubic &operator=(const TCubic &src)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_p0 = src.m_p0;
Toshihiro Shimizu 890ddd
		m_p1 = src.m_p1;
Toshihiro Shimizu 890ddd
		m_p2 = src.m_p2;
Toshihiro Shimizu 890ddd
		m_p3 = src.m_p3;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TPointD getP0() const { return m_p0; }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TPointD getP1() const { return m_p1; }
Toshihiro Shimizu 890ddd
	//!Return third control point \b P2.
Toshihiro Shimizu 890ddd
	TPointD getP2() const { return m_p2; }
Toshihiro Shimizu 890ddd
	//!Return fourth control point \b P3.
Toshihiro Shimizu 890ddd
	TPointD getP3() const { return m_p3; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b p.
Toshihiro Shimizu 890ddd
	void setP0(const TPointD &p0) { m_p0 = p0; }
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b p.
Toshihiro Shimizu 890ddd
	void setP1(const TPointD &p1) { m_p1 = p1; }
Toshihiro Shimizu 890ddd
	//!Set the value of third control point \b P2 to \b p.
Toshihiro Shimizu 890ddd
	void setP2(const TPointD &p2) { m_p2 = p2; }
Toshihiro Shimizu 890ddd
	//!Set the value of fourth control point \b P3 to \b p.
Toshihiro Shimizu 890ddd
	void setP3(const TPointD &p3) { m_p3 = p3; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const TCubic &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_p0 == c.m_p0 && m_p1 == c.m_p1 && m_p2 == c.m_p2 && m_p3 == c.m_p3;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator!=(const TCubic &c) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return !operator==(c);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return rect that contains the cubic.
Toshihiro Shimizu 890ddd
	TRectD getBBox() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TRectD(tmin(m_p0.x, m_p1.x, m_p2.x, m_p3.x),
Toshihiro Shimizu 890ddd
					  tmin(m_p0.y, m_p1.y, m_p2.y, m_p3.y),
Toshihiro Shimizu 890ddd
					  tmax(m_p0.x, m_p1.x, m_p2.x, m_p3.x),
Toshihiro Shimizu 890ddd
					  tmax(m_p0.y, m_p1.y, m_p2.y, m_p3.y));
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the point of cubic at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getPoint(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return speed of cubic at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getSpeed(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return acceleration of cubic at parameter \b t.
Toshihiro Shimizu 890ddd
	TPointD getAcceleration(double t) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return 6.0 * ((m_p2 - 2 * m_p1 + m_p0) * (1 - t) + (m_p3 - 2 * m_p2 + m_p1) * t);
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
      Return length of an arc between parameters t0 t1.
Toshihiro Shimizu 890ddd
      N.B. Length returned is always positive. 
Toshihiro Shimizu 890ddd
      \note t0 and t1 are clamped to [0,1] interval
Toshihiro Shimizu 890ddd
      \note if t0>=t1 returns 0
Toshihiro Shimizu 890ddd
     */
Toshihiro Shimizu 890ddd
	double getLength(double t0, double t1) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline double getLength(double t1 = 1.0) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return getLength(0.0, t1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! 
Toshihiro Shimizu 890ddd
      N.B. if t==0 o t==1 return a quadratic with all points equal
Toshihiro Shimizu 890ddd
     */
Toshihiro Shimizu 890ddd
	void split(double t, TCubic &first, TCubic &second) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\relates TAffine, TCubic
Toshihiro Shimizu 890ddd
inline TCubic operator*(const TAffine &aff, const TCubic &curve)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TCubic out;
Toshihiro Shimizu 890ddd
	out.setP0(aff * curve.getP0());
Toshihiro Shimizu 890ddd
	out.setP1(aff * curve.getP1());
Toshihiro Shimizu 890ddd
	out.setP2(aff * curve.getP2());
Toshihiro Shimizu 890ddd
	out.setP3(aff * curve.getP3());
Toshihiro Shimizu 890ddd
	return out;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TCubic &curve);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline std::ostream &operator<<(std::ostream &out, const TCubic *curve)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(curve);
Toshihiro Shimizu 890ddd
	return out << *curve;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  TSegment Class to manage a segment with thickness
Toshihiro Shimizu 890ddd
  \!relates TSegment
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TThickSegment : public TSegment
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	double m_thickP0;
Toshihiro Shimizu 890ddd
	double m_thickP1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	//! m_thickP0, m_thickP1 are thickness of segment control points
Toshihiro Shimizu 890ddd
	TThickSegment()
Toshihiro Shimizu 890ddd
		: TSegment(), m_thickP0(0), m_thickP1(0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickSegment(const TThickSegment &thickSegment)
Toshihiro Shimizu 890ddd
		: TSegment(thickSegment), m_thickP0(thickSegment.m_thickP0), m_thickP1(thickSegment.m_thickP1) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickSegment(const TSegment &seg)
Toshihiro Shimizu 890ddd
		: TSegment(seg), m_thickP0(0), m_thickP1(0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickSegment(const TPointD &p0, double thickP0,
Toshihiro Shimizu 890ddd
				  const TPointD &p1, double thickP1)
Toshihiro Shimizu 890ddd
		: TSegment(p0, p1), m_thickP0(thickP0), m_thickP1(thickP1) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickSegment(const TThickPoint &thickP0,
Toshihiro Shimizu 890ddd
				  const TThickPoint &thickP1)
Toshihiro Shimizu 890ddd
		: TSegment(thickP0, thickP1), m_thickP0(thickP0.thick), m_thickP1(thickP1.thick) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickSegment &operator=(const TThickSegment &other)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_c0.x = other.m_c0.x;
Toshihiro Shimizu 890ddd
		m_c1.x = other.m_c1.x;
Toshihiro Shimizu 890ddd
		m_c0.y = other.m_c0.y;
Toshihiro Shimizu 890ddd
		m_c1.y = other.m_c1.y;
Toshihiro Shimizu 890ddd
		m_thickP0 = other.m_thickP0;
Toshihiro Shimizu 890ddd
		m_thickP1 = other.m_thickP1;
Toshihiro Shimizu 890ddd
		return *this;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b TThickPoint \b p0.
Toshihiro Shimizu 890ddd
	void setThickP0(const TThickPoint &p0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_c0.x = p0.x;
Toshihiro Shimizu 890ddd
		m_c0.y = p0.y;
Toshihiro Shimizu 890ddd
		m_thickP0 = p0.thick;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b TThickPoint \b p1.
Toshihiro Shimizu 890ddd
	void setThickP1(const TThickPoint &p1)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_c1.x = p1.x - m_c0.x;
Toshihiro Shimizu 890ddd
		m_c1.y = p1.y - m_c0.y;
Toshihiro Shimizu 890ddd
		m_thickP1 = p1.thick;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP0() const { return TThickPoint(m_c0, m_thickP0); }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP1() const { return TThickPoint(m_c0 + m_c1, m_thickP1); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the \b TThickPoint of segment at parameter \b t.
Toshihiro Shimizu 890ddd
	TThickPoint getThickPoint(double t) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TThickPoint(m_c0 + t * m_c1, (1 - t) * m_thickP0 + t * m_thickP1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TThickSegment operator*(const TAffine &aff, const TThickSegment &ts)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TThickSegment out(ts);
Toshihiro Shimizu 890ddd
	out.setP0(aff * ts.getP0());
Toshihiro Shimizu 890ddd
	out.setP1(aff * ts.getP1());
Toshihiro Shimizu 890ddd
	return out;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TThickSegment &segment);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline std::ostream &operator<<(std::ostream &out, const TThickSegment *segment)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(segment);
Toshihiro Shimizu 890ddd
	return out << *segment;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  Class TThickQuadratic: manage a curve with thick
Toshihiro Shimizu 890ddd
  \!relates TQuadratic
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TThickQuadratic : public TQuadratic
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	double m_thickP0;
Toshihiro Shimizu 890ddd
	double m_thickP1;
Toshihiro Shimizu 890ddd
	double m_thickP2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TThickQuadratic();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! thickP0, thickP1, thickP2 are thickness of quadratic control points
Toshihiro Shimizu 890ddd
	TThickQuadratic(const TPointD &p0, double thickP0,
Toshihiro Shimizu 890ddd
					const TPointD &p1, double thickP1,
Toshihiro Shimizu 890ddd
					const TPointD &p2, double thickP2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickQuadratic(const TThickPoint &p0,
Toshihiro Shimizu 890ddd
					const TThickPoint &p1,
Toshihiro Shimizu 890ddd
					const TThickPoint &p2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickQuadratic(const TThickQuadratic &thickQuadratic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickQuadratic(const TQuadratic &quadratic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP0(const TThickPoint &p);
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP1(const TThickPoint &p);
Toshihiro Shimizu 890ddd
	//!Set the value of third control point \b P2 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP2(const TThickPoint &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the \b TThickPoint of quadratic at parameter \b t.
Toshihiro Shimizu 890ddd
	TThickPoint getThickPoint(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP0() const { return TThickPoint(m_p0, m_thickP0); }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP1() const { return TThickPoint(m_p1, m_thickP1); }
Toshihiro Shimizu 890ddd
	//!Return third control point \b P2.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP2() const { return TThickPoint(m_p2, m_thickP2); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void split(double t, TThickQuadratic &first, TThickQuadratic &second) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD getBBox() const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TThickQuadratic operator*(const TAffine &aff, const TThickQuadratic &tq)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TThickQuadratic out(tq);
Toshihiro Shimizu 890ddd
	out.setP0(aff * tq.getP0());
Toshihiro Shimizu 890ddd
	out.setP1(aff * tq.getP1());
Toshihiro Shimizu 890ddd
	out.setP2(aff * tq.getP2());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return out;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TThickQuadratic transformQuad(const TAffine &aff, const TThickQuadratic &tq, bool doChangeThickness = false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!doChangeThickness)
Toshihiro Shimizu 890ddd
		return aff * tq;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickQuadratic out(tq);
Toshihiro Shimizu 890ddd
	double det = aff.det();
Toshihiro Shimizu 890ddd
	det = (det < 0) ? sqrt(-det) : sqrt(det);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	out.setThickP0(TThickPoint(aff * tq.getP0(), tq.getThickP0().thick * det));
Toshihiro Shimizu 890ddd
	out.setThickP1(TThickPoint(aff * tq.getP1(), tq.getThickP1().thick * det));
Toshihiro Shimizu 890ddd
	out.setThickP2(TThickPoint(aff * tq.getP2(), tq.getThickP2().thick * det));
Toshihiro Shimizu 890ddd
	return out;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TThickQuadratic &tq);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline std::ostream &operator<<(std::ostream &out, const TThickQuadratic *tq)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(tq);
Toshihiro Shimizu 890ddd
	return out << *tq;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  Class TThickCubic: manage a cubic with thick
Toshihiro Shimizu 890ddd
  \!relates TCubic
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
class DVAPI TThickCubic : public TCubic
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	double m_thickP0;
Toshihiro Shimizu 890ddd
	double m_thickP1;
Toshihiro Shimizu 890ddd
	double m_thickP2;
Toshihiro Shimizu 890ddd
	double m_thickP3;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TThickCubic();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! thickP0, thickP1, thickP2, thickP3 are thickness of cubic control points
Toshihiro Shimizu 890ddd
	TThickCubic(const TPointD &p0, double thickP0,
Toshihiro Shimizu 890ddd
				const TPointD &p1, double thickP1,
Toshihiro Shimizu 890ddd
				const TPointD &p2, double thickP2,
Toshihiro Shimizu 890ddd
				const TPointD &p3, double thickP3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickCubic(const TThickPoint &p0,
Toshihiro Shimizu 890ddd
				const TThickPoint &p1,
Toshihiro Shimizu 890ddd
				const TThickPoint &p2,
Toshihiro Shimizu 890ddd
				const TThickPoint &p3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  tonino ***************************************************************
Toshihiro Shimizu 890ddd
	TThickCubic(const T3DPointD &p0,
Toshihiro Shimizu 890ddd
				const T3DPointD &p1,
Toshihiro Shimizu 890ddd
				const T3DPointD &p2,
Toshihiro Shimizu 890ddd
				const T3DPointD &p3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  tonino ***************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickCubic(const TThickCubic &thickCubic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickCubic(const TCubic &cubic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of first control point \b P0 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP0(const TThickPoint &p);
Toshihiro Shimizu 890ddd
	//!Set the value of second control point \b P1 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP1(const TThickPoint &p);
Toshihiro Shimizu 890ddd
	//!Set the value of third control point \b P2 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP2(const TThickPoint &p);
Toshihiro Shimizu 890ddd
	//!Set the value of fourth control point \b P3 to \b TThickPoint \b p.
Toshihiro Shimizu 890ddd
	void setThickP3(const TThickPoint &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the \b TThickPoint of cubic at parameter \b t.
Toshihiro Shimizu 890ddd
	TThickPoint getThickPoint(double t) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return first control point \b P0.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP0() const { return TThickPoint(m_p0, m_thickP0); }
Toshihiro Shimizu 890ddd
	//!Return second control point \b P1.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP1() const { return TThickPoint(m_p1, m_thickP1); }
Toshihiro Shimizu 890ddd
	//!Return third control point \b P2.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP2() const { return TThickPoint(m_p2, m_thickP2); }
Toshihiro Shimizu 890ddd
	//!Return fourth control point \b P3.
Toshihiro Shimizu 890ddd
	TThickPoint getThickP3() const { return TThickPoint(m_p3, m_thickP3); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void split(double t, TThickCubic &first, TThickCubic &second) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TThickCubic operator*(const TAffine &aff, const TThickCubic &tc)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TThickCubic out(tc);
Toshihiro Shimizu 890ddd
	out.setP0(aff * tc.getP0());
Toshihiro Shimizu 890ddd
	out.setP1(aff * tc.getP1());
Toshihiro Shimizu 890ddd
	out.setP2(aff * tc.getP2());
Toshihiro Shimizu 890ddd
	out.setP3(aff * tc.getP3());
Toshihiro Shimizu 890ddd
	return out;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
DVAPI std::ostream &operator<<(std::ostream &out, const TThickCubic &tc);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
inline std::ostream &operator<<(std::ostream &out, const TThickCubic *tc)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(tc);
Toshihiro Shimizu 890ddd
	return out << *tc;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //__T_CURVES_INCLUDED
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//  End Of File
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------