BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
5dbde65
Branches
Tags
master
dxfngc
src
point.cpp
implement scaling
Stefan Schuermans
commited
5dbde65
at 2013-07-06 20:31:45
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); } /** * @brief scale differently in X and Y direction * @param[in] fx scale factor in X direction * @param[in] fy scale factor in Y direction * @return scaled point */ Point Point::scale_xy(double fx, double fy) const { return Point(fx * mX, fy * mY); }