BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
9d9be10
Branches
Tags
master
dxfngc
src
point.cpp
supoort rotation around z axis
Stefan Schuermans
commited
9d9be10
at 2013-05-18 14:37:50
point.cpp
Blame
History
Raw
/* drawing (DXF) to G-code (NGC) converter * Copyright 2013 Stefan Schuermans <stefan@schuermans.info> * Copyleft: CC-BY-SA http://creativecommons.org/licenses/by-sa/3.0/ */ #include <math.h> #include "point.h" Point::Point(): mX(0.0), mY(0.0) { } Point::Point(double x, double y): mX(x), mY(y) { } double Point::abs_sq() const { return mX * mX + mY * mY; } double Point::abs() const { return sqrt(mX * mX + mY * mY); } Point Point::operator-() const { return Point(-mX, -mY); } Point Point::operator+(const Point &that) const { return Point(mX + that.mX, mY + that.mY); } Point Point::operator-(const Point &that) const { return Point(mX - that.mX, mY - that.mY); } Point Point::operator*(double factor) const { return Point(mX * factor, mY * factor); } Point Point::operator/(double factor) const { return Point(mX / factor, mY / factor); } Point &Point::operator+=(const Point &that) { mX += that.mX; mY += that.mY; return *this; } Point &Point::operator-=(const Point &that) { mX -= that.mX; mY -= that.mY; return *this; } Point &Point::operator*=(double factor) { mX *= factor; mY *= factor; return *this; } Point &Point::operator/=(double factor) { mX /= factor; mY /= factor; return *this; } /** * @brief check if point is equal to another one * @param[in] that other point * @param[in] eqDist maximum distance of two points to be considered equal */ bool Point::equals(const Point &that, double eqDist) const { return (*this - that).abs_sq() <= eqDist * eqDist; } /** * @brief rotate around origin * @param[in] rad angle in radians * @return rotated point */ Point Point::rotate(double rad) const { double c = cos(rad); double s = sin(rad); double rx = mX * c - mY * s; double ry = mY * c + mX * s; return Point(rx, ry); }