#include "SFPoint2f.h" #include "SFString.h" #include using namespace X3DTK; using namespace std; const SFPoint2f SFPoint2f::null(0.0f, 0.0f); SFPoint2f::SFPoint2f() : x(0.0f), y(0.0f) { } SFPoint2f::SFPoint2f(float x, float y) { this->x = x; this->y = y; } SFPoint2f::SFPoint2f(const SFPoint2f &p) { x = p.x; y = p.y; } SFPoint2f &SFPoint2f::operator= (const SFPoint2f &v) { x = v.x; y = v.y; return *this; } SFPoint2f &SFPoint2f::operator+= (const SFVec2f &v) { x += v.x; y += v.y; return *this; } SFPoint2f &SFPoint2f::operator+= (const SFPoint2f &v) { x += v.x; y += v.y; return *this; } SFPoint2f &SFPoint2f::operator-= (const SFVec2f &v) { x -= v.x; y -= v.y; return *this; } SFPoint2f::SFPoint2f(const SFString &s) { istringstream iss(s, istringstream::in); iss >> x >> y; } SFPoint2f::SFPoint2f(const SFVec2f &V) { x = V.x; y = V.y; } // operations on points //overloading of the operators +, -, * namespace X3DTK { SFPoint2f operator+ (const SFPoint2f &v1, const SFVec2f &v2) { SFPoint2f res; res.x = v1.x + v2.x; res.y = v1.y + v2.y; return res; } SFPoint2f operator+ (const SFPoint2f &v1, const SFPoint2f &v2) { SFPoint2f res; res.x = v1.x + v2.x; res.y = v1.y + v2.y; return res; } SFPoint2f operator- (const SFPoint2f &v1, const SFVec2f &v2) { SFPoint2f res; res.x = v1.x - v2.x; res.y = v1.y - v2.y; return res; } SFVec2f operator- (const SFPoint2f &v1, const SFPoint2f &v2) { SFVec2f res; res.x = v1.x - v2.x; res.y = v1.y - v2.y; return res; } SFPoint2f operator* (const float a, const SFPoint2f &v) { SFPoint2f res; res.x = a * v.x; res.y = a * v.y; return res; } float distance(const SFPoint2f &A, const SFPoint2f &B) { return (A - B).norm(); } }