| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #ifndef RS_VECTOR_H |
| | #define RS_VECTOR_H |
| | #include <cstddef> |
| | #include <iosfwd> |
| | #include <vector> |
| |
|
| | class QPointF; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | class RS_Vector { |
| | public: |
| | RS_Vector()=default; |
| | RS_Vector(double vx, double vy, double vz=0.0); |
| | explicit RS_Vector(double angle); |
| | |
| | explicit RS_Vector(bool valid); |
| | explicit RS_Vector(const QPointF& point); |
| | ~RS_Vector()=default; |
| |
|
| | |
| | |
| | |
| | explicit operator bool() const; |
| |
|
| | bool isValid() const |
| | { |
| | return valid; |
| | } |
| |
|
| | void set(double angle); |
| | void set(double vx, double vy, double vz=0.0); |
| | void plus(const RS_Vector& other); |
| | void minus(const RS_Vector& other); |
| | void setPolar(double radius, double angle); |
| | |
| | |
| | static RS_Vector polar(double rho, double theta); |
| | |
| |
|
| | double distanceTo(const RS_Vector& v) const; |
| | double angle() const; |
| | double angleTo(const RS_Vector& v) const; |
| | double angleBetween(const RS_Vector& v1, const RS_Vector& v2) const; |
| | double magnitude() const; |
| | double squared() const; |
| | double squaredTo(const RS_Vector& v1) const; |
| | RS_Vector lerp(const RS_Vector& v, double t) const; |
| |
|
| | bool isInWindow(const RS_Vector& firstCorner, const RS_Vector& secondCorner) const; |
| | bool isInWindowOrdered(const RS_Vector& vLow, const RS_Vector& vHigh) const; |
| |
|
| | RS_Vector toInteger(); |
| |
|
| | RS_Vector& move(const RS_Vector& offset); |
| | RS_Vector& rotate(double ang); |
| | RS_Vector rotated(double angle) const; |
| | RS_Vector& rotate(const RS_Vector& angleVector); |
| | RS_Vector rotated(const RS_Vector& angleVector) const; |
| | RS_Vector& rotate(const RS_Vector& center, double ang); |
| | RS_Vector& rotate(const RS_Vector& center, const RS_Vector& angleVector); |
| | RS_Vector& scale(double factor); |
| | RS_Vector& scale(const RS_Vector& factor); |
| | RS_Vector scale(const RS_Vector& factor) const; |
| | RS_Vector& scale(const RS_Vector& center, const RS_Vector& factor); |
| | RS_Vector& mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2); |
| | |
| | |
| | |
| | |
| | |
| | |
| | RS_Vector relative(double distance, double angle) const; |
| | |
| | |
| | |
| | |
| | |
| | |
| | RS_Vector& shear(double k); |
| | double dotP(const RS_Vector& v1) const; |
| | RS_Vector normalized() const; |
| | RS_Vector& normalize(); |
| |
|
| | RS_Vector crossP(const RS_Vector& vp) const; |
| |
|
| | RS_Vector operator + (const RS_Vector& v) const; |
| | RS_Vector operator + (double d) const; |
| | RS_Vector operator - (const RS_Vector& v) const; |
| | RS_Vector operator - (double d) const; |
| | RS_Vector operator * (const RS_Vector& v) const; |
| | RS_Vector operator / (const RS_Vector& v) const; |
| | RS_Vector operator * (double s) const; |
| | RS_Vector operator / (double s) const; |
| | RS_Vector operator - () const; |
| |
|
| | RS_Vector operator += (const RS_Vector& v); |
| | RS_Vector operator -= (const RS_Vector& v); |
| | RS_Vector operator *= (const RS_Vector& v); |
| | RS_Vector operator /= (const RS_Vector& v); |
| | RS_Vector operator *= (double s); |
| | RS_Vector operator /= (double s); |
| |
|
| | bool operator == (const RS_Vector& v) const; |
| | bool operator != (const RS_Vector& v) const { |
| | return !operator==(v); |
| | } |
| | |
| | |
| | |
| | |
| | |
| | bool operator == (bool valid) const; |
| | bool operator != (bool valid) const; |
| |
|
| | static bool isValid(const RS_Vector& v) { |
| | return v.valid; |
| | } |
| |
|
| | static RS_Vector minimum(const RS_Vector& v1, const RS_Vector& v2); |
| | static RS_Vector maximum(const RS_Vector& v1, const RS_Vector& v2); |
| | |
| | static RS_Vector crossP(const RS_Vector& v1, const RS_Vector& v2); |
| | static double dotP(const RS_Vector& v1, const RS_Vector& v2); |
| | static double posInLine(const RS_Vector& start, |
| | const RS_Vector& end, |
| | const RS_Vector& pos); |
| |
|
| | |
| | RS_Vector flipXY(void) const; |
| |
|
| | friend RS_Vector operator * (double scale, const RS_Vector& vp); |
| | friend std::ostream& operator << (std::ostream&, const RS_Vector& v); |
| |
|
| | #ifdef RS_TEST |
| |
|
| | static bool test(); |
| | #endif |
| |
|
| | public: |
| | double x=0.; |
| | double y=0.; |
| | double z=0.; |
| | bool valid=false; |
| | }; |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | class RS_VectorSolutions { |
| | public: |
| | typedef RS_Vector value_type; |
| | RS_VectorSolutions() = default; |
| | RS_VectorSolutions(std::vector<RS_Vector> vectors); |
| | RS_VectorSolutions(std::initializer_list<RS_Vector> list); |
| | RS_VectorSolutions(int num); |
| |
|
| | void alloc(size_t num); |
| | void clear(); |
| | |
| | |
| | |
| | |
| | |
| | RS_Vector get(size_t i) const; |
| | const RS_Vector& back() const; |
| | RS_Vector& back(); |
| | const RS_Vector& front() const; |
| | RS_Vector& front(); |
| | RS_Vector& at(size_t i); |
| | const RS_Vector& at(size_t i) const; |
| | const RS_Vector& operator [] (const size_t i) const; |
| | RS_Vector& operator [] (const size_t i); |
| | size_t getNumber() const; |
| | bool isEmpty(); |
| | size_t size() const; |
| | bool empty() const; |
| | void resize(size_t n); |
| | bool hasValid() const; |
| | void set(size_t i, const RS_Vector& v); |
| | void push_back(const RS_Vector& v); |
| | void removeAt(const size_t i); |
| | RS_VectorSolutions& push_back(const RS_VectorSolutions& v); |
| | void setTangent(bool t); |
| | bool isTangent() const; |
| | RS_Vector getClosest(const RS_Vector& coord, |
| | double* dist=nullptr, size_t* index=nullptr) const; |
| | double getClosestDistance(const RS_Vector& coord, |
| | int counts = -1); |
| | const std::vector<RS_Vector>& getVector() const; |
| | std::vector<RS_Vector>::const_iterator cbegin() const; |
| | std::vector<RS_Vector>::const_iterator cend() const; |
| | std::vector<RS_Vector>::const_iterator begin() const; |
| | std::vector<RS_Vector>::const_iterator end() const; |
| | std::vector<RS_Vector>::iterator begin(); |
| | std::vector<RS_Vector>::iterator end(); |
| | void rotate(double ang); |
| | void rotate(const RS_Vector& angleVector); |
| | void rotate(const RS_Vector& center, double ang); |
| | void rotate(const RS_Vector& center, const RS_Vector& angleVector); |
| | void move(const RS_Vector& vp); |
| | void scale(const RS_Vector& center, const RS_Vector& factor); |
| | void scale(const RS_Vector& factor); |
| |
|
| | |
| | RS_VectorSolutions flipXY(void) const; |
| |
|
| | friend std::ostream& operator << (std::ostream& os, |
| | const RS_VectorSolutions& s); |
| |
|
| | private: |
| | std::vector<RS_Vector> vector; |
| | bool tangent = false; |
| | }; |
| |
|
| | #endif |
| |
|