ultimatepp/uppsrc/Painter/Math.cpp
cxl dd88989c82 Painter fixed to work in Linux, MoveableWithSwap removed (GCC problems, possibly undefined behaviour of code)
git-svn-id: svn://ultimatepp.org/upp/trunk@867 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2009-02-15 13:11:54 +00:00

55 lines
830 B
C++

#include "Painter.h"
NAMESPACE_UPP
double SquareDist(const Pointf& p1, const Pointf& p2)
{
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
Pointf Mid(const Pointf& a, const Pointf& b)
{
return 0.5 * (a + b);
}
Pointf Orthogonal(const Pointf& p)
{
return Pointf(-p.y, p.x);
}
double Squared(const Pointf& p)
{
return p.x * p.x + p.y * p.y;
}
double Length(const Pointf& p)
{
return sqrt(Squared(p));
}
double Bearing(const Pointf& p)
{
return atan2(p.y, p.x);
}
double Distance(const Pointf& p1, const Pointf& p2)
{
return Length(p1 - p2);
}
double SquaredDistance(const Pointf& p1, const Pointf& p2)
{
return Squared(p1 - p2);
}
Pointf Polar(double a)
{
return Pointf(cos(a), sin(a));
}
Pointf Polar(const Pointf& p, double r, double a)
{
return p + r * Polar(a);
}
END_UPP_NAMESPACE