Changeset 1028
 Timestamp:
 11/26/20 01:26:40 (3 years ago)
 Location:
 cpp/common
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

cpp/common/2d.h
r909 r1028 38 38 bool operator==(const XY &p) const { return (fabs(double(x  p.x)) < 1e20) && (fabs(double(y  p.y)) < 1e20); } 39 39 bool operator!=(const XY &p) const { return !operator==(p); } 40 T distanceTo(const XY &p) const { return sqrt(double((p.x  x) * (p.x  x) + (p.y  y) * (p.y  y))); } 40 T distanceTo(const XY &p) const { return sqrt(distanceToSq(p)); } 41 T distanceToSq(const XY &p) const { return double((p.x  x) * (p.x  x) + (p.y  y) * (p.y  y)); } 41 42 T magnitude() const { return sqrt(x * x + y * y); } 42 43 T length() const { return sqrt(x * x + y * y); } 
cpp/common/Convert.h
r1005 r1028 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 199920 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 19992020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #include "nonstd_math.h" 10 10 #include "nonstd_stl.h" 11 #include "2d.h"12 11 #include <stdint.h> 13 12 #include <cmath> 14 15 16 typedef XY<double> Pt2D;17 13 18 14 #ifdef LINUX … … 49 45 return dx * dx + dy * dy; 50 46 } 51 static double odleglosc_sq(const Pt2D& p1, const Pt2D& p2) //odleglosc do kwadratu52 {53 return odleglosc_sq(p1.x, p1.y, p2.x, p2.y);54 }55 47 56 48 static double odleglosc(double x1, double y1, double x2, double y2) { return sqrt(odleglosc_sq(x1, y1, x2, y2)); } 57 static double odleglosc(const Pt2D& p1, const Pt2D& p2)58 {59 return sqrt(odleglosc_sq(p1, p2));60 }61 49 62 50 //static float odleglosc(int x1,int y1,int x2,int y2) {float dx=x1x2; float dy=y1y2; return sqrt(dx*dx+dy*dy);} … … 85 73 }; 86 74 87 88 89 struct Angle //normalized angle in radians [0,2pi) and degrees [0,360) with precomputed sine and cosine and degree as integer [0,359]90 {91 private:92 double angle; //in radians, readonly93 public:94 double angle_deg; //readonly95 int angle_deg_int; //readonly96 97 Angle() { set(0); }98 Angle(double k) { set(k); }99 Angle(Angle &kt) { set(kt.get()); }100 Angle(double dy, double dx) { set(dy, dx); }101 Angle(const Pt2D& xy) { set(xy); }102 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; }103 void set(double dy, double dx) { set(Convert::atan_2(dy, dx)); }104 void set(const Pt2D& xy) { set(xy.y, xy.x); }105 void add(double dk) { set(angle + dk); }106 void add(Angle &kt) { set(angle + kt.get()); }107 double get() { return angle; }108 double sine, cosine;109 };110 111 112 75 #endif
Note: See TracChangeset
for help on using the changeset viewer.