#ifndef __JPOINT2D__ #define __JPOINT2D__ #include "JGeometry2D/JVector2D.hh" #include "JGeometry2D/JAngle2D.hh" #include "JGeometry2D/JRotation2D.hh" namespace JGEOMETRY2D { /** * Data structure for point in two dimensions. */ class JPoint2D : public JVector2D { public: /** * Default constructor. */ JPoint2D() : JVector2D() {} /** * Constructor. * * \param pos position */ JPoint2D(const JVector2D& pos) : JVector2D(pos) {} /** * Constructor. * * \param x x value * \param y y value */ JPoint2D(const double x, const double y) : JVector2D(x,y) {} /** * Constructor. * * \param angle angle */ JPoint2D(const JAngle2D& angle) : JVector2D(angle.getDX(), angle.getDY()) {} /** * Get position. * * \return position */ const JPoint2D& getPosition() const { return static_cast(*this); } /** * Get position. * * \return position */ JPoint2D& getPosition() { return static_cast(*this); } /** * Set position. * * \param pos position */ void setPosition(const JVector2D& pos) { static_cast(*this) = pos; } /** * Transform. * * \param T matrix */ JPoint2D& transform(const JMatrix2D& T) { T.transform(__x, __y); return *this; } /** * Rotate. * * \param R rotation matrix */ JPoint2D& rotate(const JRotation2D& R) { R.rotate(__x, __y); return *this; } /** * Rotate back. * * \param R rotation matrix */ JPoint2D& rotate_back(const JRotation2D& R) { R.rotate_back(__x, __y); return *this; } /** * Get squared of distance to point. * * \param point JPoint2D * \return distance */ double getDistanceSquared(const JPoint2D& point) const { const double dx = getX() - point.getX(); const double dy = getY() - point.getY(); return dx*dx + dy*dy; } /** * Get distance to point. * * \param point JPoint2D * \return distance */ double getDistance(const JPoint2D& point) const { return sqrt(getDistanceSquared(point)); } /** * Get dot product. * * \param point JPoint2D * \return dot product */ double getDot(const JPoint2D& point) const { return getX() * point.getX() + getY() * point.getY(); } }; /** * Distance. * * \param first JPoint2D * \param second JPoint2D * \return distance */ inline double distance(const JPoint2D& first, const JPoint2D& second) { return first.getDistance(second); } /** * Dot product. * * \param first JPoint2D * \param second JPoint2D * \return dot product */ inline double dot(const JPoint2D& first, const JPoint2D& second) { return first.getDot(second); } } #endif