# Changeset 1028

Ignore:
Timestamp:
11/26/20 01:26:40 (3 years ago)
Message:

Separated Pt2D

Location:
cpp/common
Files:
2 edited

Unmodified
Removed
• ## cpp/common/2d.h

 r909 bool operator==(const XY &p) const { return (fabs(double(x - p.x)) < 1e-20) && (fabs(double(y - p.y)) < 1e-20); } bool operator!=(const XY &p) const { return !operator==(p); } T distanceTo(const XY &p) const { return sqrt(double((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))); } T distanceTo(const XY &p) const { return sqrt(distanceToSq(p)); } T distanceToSq(const XY &p) const { return double((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)); } T magnitude() const { return sqrt(x * x + y * y); } T length() const { return sqrt(x * x + y * y); }
• ## cpp/common/Convert.h

 r1005 // This file is a part of Framsticks SDK.  http://www.framsticks.com/ // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski. // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #include "nonstd_math.h" #include "nonstd_stl.h" #include "2d.h" #include #include typedef XY Pt2D; #ifdef LINUX return dx * dx + dy * dy; } static double odleglosc_sq(const Pt2D& p1, const Pt2D& p2) //odleglosc do kwadratu { return odleglosc_sq(p1.x, p1.y, p2.x, p2.y); } static double odleglosc(double x1, double y1, double x2, double y2) { return sqrt(odleglosc_sq(x1, y1, x2, y2)); } static double odleglosc(const Pt2D& p1, const Pt2D& p2) { return sqrt(odleglosc_sq(p1, p2)); } //static float odleglosc(int x1,int y1,int x2,int y2) {float dx=x1-x2; float dy=y1-y2; return sqrt(dx*dx+dy*dy);} }; struct Angle //normalized angle in radians [0,2pi) and degrees [0,360) with pre-computed sine and cosine and degree as integer [0,359] { private: double angle; //in radians, read-only public: double angle_deg; //read-only int angle_deg_int; //read-only Angle() { set(0); } Angle(double k) { set(k); } Angle(Angle &kt) { set(kt.get()); } Angle(double dy, double dx) { set(dy, dx); } Angle(const Pt2D& xy) { set(xy); } void set(double k) { k = fmod(k, M_PI * 2); if (k < 0) k += M_PI * 2; angle = k; sine = sin(k); cosine = cos(k); angle_deg = Convert::toDegrees(angle); angle_deg_int = roundToInt(angle_deg); angle_deg_int %= 360; } void set(double dy, double dx) { set(Convert::atan_2(dy, dx)); } void set(const Pt2D& xy) { set(xy.y, xy.x); } void add(double dk) { set(angle + dk); } void add(Angle &kt) { set(angle + kt.get()); } double get() { return angle; } double sine, cosine; }; #endif
Note: See TracChangeset for help on using the changeset viewer.