Changeset 1028


Ignore:
Timestamp:
11/26/20 01:26:40 (4 years ago)
Author:
Maciej Komosinski
Message:

Separated Pt2D

Location:
cpp/common
Files:
2 edited

Legend:

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

    r909 r1028  
    3838        bool operator==(const XY &p) const { return (fabs(double(x - p.x)) < 1e-20) && (fabs(double(y - p.y)) < 1e-20); }
    3939        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)); }
    4142        T magnitude() const { return sqrt(x * x + y * y); }
    4243        T length() const { return sqrt(x * x + y * y); }
  • cpp/common/Convert.h

    r1005 r1028  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include "nonstd_math.h"
    1010#include "nonstd_stl.h"
    11 #include "2d.h"
    1211#include <stdint.h>
    1312#include <cmath>
    14 
    15 
    16 typedef XY<double> Pt2D;
    1713
    1814#ifdef LINUX
     
    4945                return dx * dx + dy * dy;
    5046        }
    51         static double odleglosc_sq(const Pt2D& p1, const Pt2D& p2) //odleglosc do kwadratu
    52         {
    53                 return odleglosc_sq(p1.x, p1.y, p2.x, p2.y);
    54         }
    5547
    5648        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         }
    6149
    6250        //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);}
     
    8573};
    8674
    87 
    88 
    89 struct Angle //normalized angle in radians [0,2pi) and degrees [0,360) with pre-computed sine and cosine and degree as integer [0,359]
    90 {
    91 private:
    92         double angle; //in radians, read-only
    93 public:
    94         double angle_deg; //read-only
    95         int angle_deg_int; //read-only
    96 
    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 
    11275#endif
Note: See TracChangeset for help on using the changeset viewer.