BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
1030916
Branches
Tags
master
dxfngc
src
point.cpp
license CC-BY-SA --> GPL (more suitable for source code)
Stefan Schuermans
commited
1030916
at 2013-05-27 17:35:02
point.cpp
Blame
History
Raw
/* drawing (DXF) to G-code (NGC) converter * Copyright 2013 Stefan Schuermans <stefan@schuermans.info> * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html */ #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); }