/usr/include/OpenLayer/Vec2D.hpp is in libopenlayer-dev 2.1-2.1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #ifndef OL_VEC2D_HPP
#define OL_VEC2D_HPP
#include <cmath>
#include <string>
#include <sstream>
#include "General.hpp"
#include "Declspec.hpp"
namespace ol {
class OL_LIB_DECLSPEC Vec2D {
public:
float x, y;
// CONSTRUCTORS //
Vec2D( float x = 0.0, float y = 0.0 )
: x( x ), y( y ) {}
static inline Vec2D PolarCoords( float angle, float magnitude ) {
return Vec2D( magnitude * std::cos( angle ), magnitude * std::sin( angle ));
}
// METHODS //
inline float GetAngle() const {
return std::atan2( y, x );
}
inline float GetMagnitude() const {
return std::sqrt( GetMagnitudeSquared() );
}
inline float GetMagnitudeSquared() const {
return x * x + y * y;
}
inline Vec2D Normalized() const {
float magnitude = GetMagnitude();
return Vec2D( x / magnitude, y / magnitude );
}
// OPERATORS //
inline void operator += ( const Vec2D &other ) {
x += other.x; y += other.y;
}
inline void operator -= ( const Vec2D &other ) {
x -= other.x; y -= other.y;
}
inline void operator *= ( float factor ) {
x *= factor; y *= factor;
}
inline void operator /= ( float divisor ) {
x /= divisor; y /= divisor;
}
inline bool operator == ( const Vec2D &other ) const {
return fabs(x - other.x) < 0.01 && fabs(y - other.y) < 0.01;
}
inline bool operator != ( const Vec2D &other ) const {
return !(*this == other);
}
inline std::string ToString() const {
std::ostringstream str;
str << "( " << x << ", " << y << " )";
return str.str();
}
inline std::string GetString() const {
return ToString();
}
};
// ADDITION AND SUBTRACTION //
inline Vec2D operator + ( Vec2D first, Vec2D second ) {
return Vec2D( first.x + second.x, first.y + second.y );
}
inline Vec2D operator - ( Vec2D first, Vec2D second ) {
return Vec2D( first.x - second.x, first.y - second.y );
}
// MULTIPLICATION AND DIVISION
inline Vec2D operator * ( Vec2D vec, float factor ) {
return Vec2D( factor * vec.x, factor * vec.y );
}
inline Vec2D operator * ( float factor, Vec2D vec ) {
return Vec2D( factor * vec.x, factor * vec.y );
}
inline Vec2D operator / ( Vec2D vec, float divisor ) {
return Vec2D( vec.x / divisor, vec.y / divisor );
}
// DOT PRODUCT //
inline float operator * ( Vec2D first, Vec2D second ) {
return first.x * second.x + first.y * second.y;
}
// SIGN //
inline Vec2D operator - ( Vec2D vec ) {
return Vec2D( -vec.x, -vec.y );
}
// NORMALIZATION
inline Vec2D operator ~ ( Vec2D vec ) {
return vec.Normalized();
}
// TESTS
// Checks if the points are in counter clockwise order //
inline OL_LIB_DECLSPEC bool IsCounterClockwise( const Vec2D first, const Vec2D second, const Vec2D third ) {
float dx1, dx2, dy1, dy2;
dx1 = second.x - first.x;
dy1 = second.y - first.y;
dx2 = third.x - second.x;
dy2 = third.y - second.y;
return dy1*dx2 < dy2*dx1;
}
}
#endif
|