57 #pragma warning( disable : 4231 )
68 inline MENGE_API
float sqr(
float a) {
90 inline Vector2d( Type x, Type y ): _x(x), _y(y) {}
106 inline Type
x()
const {
return _x; }
113 inline Type
y()
const {
return _y; }
121 inline void set( Type x, Type y ) {
183 return _x * v.
_x + _y * v.
_y;
207 const float invS = 1.f / s;
244 return _x == v.
_x && _y == v.
_y;
256 return _x != v.
_x || _y != v.
_y;
280 const float invS = 1.f / s;
322 float len = sqrtf( _x * _x + _y * _y );
339 return sqrt( _x * _x + _y * _y );
350 float dx = _x - p.
_x;
351 float dy = _y - p.
_y;
352 return sqrtf( dx * dx + dy * dy );
365 return sqrtf( dx * dx + dy * dy );
376 float dx = _x - p.
_x;
377 float dy = _y - p.
_y;
378 return dx * dx + dy * dy ;
391 return dx * dx + dy * dy;
414 typedef Vector2d<float>
Vector2;
429 template<
class Type >
438 MATHEXTERN
template MENGE_API Vector2d<float> operator*(
float s,
const Vector2d<float>& v);
449 template<
class Type >
450 inline MENGE_API
Logger& operator<<(Logger& logger, const Vector2d<Type>& v ) {
451 logger <<
"(" << v.x() <<
"," << v.y() <<
")";
465 template<
class Type >
466 inline MENGE_API std::ostream& operator<<(std::ostream& os, const Vector2d<Type>& v ) {
467 os <<
"(" << v.x() <<
"," << v.y() <<
")";
475 MATHEXTERN
template MENGE_API Logger& operator<<(Logger& os, const Vector2d<float>& v );
484 template<
class Type >
485 inline MENGE_API Type abs(
const Vector2d<Type>& v ) {
486 return std::sqrt( v * v );
493 MATHEXTERN
template MENGE_API
float abs(
const Vector2d<float>& v );
503 template<
class Type >
504 inline MENGE_API Type absSq(
const Vector2d<Type>& v ) {
512 MATHEXTERN
template MENGE_API
float absSq(
const Vector2d<float>& v );
524 template<
class Type >
525 inline MENGE_API Type det(
const Vector2d<Type>& v1,
const Vector2d<Type>& v2) {
526 return v1.x() * v2.y() - v1.y() * v2.x();
533 MATHEXTERN
template MENGE_API
float det(
const Vector2d<float>& v1,
const Vector2d<float>& v2);
543 template<
class Type >
544 inline MENGE_API Vector2d<Type> norm(
const Vector2d<Type>& vector) {
545 float mag = abs( vector );
550 return Vector2d<Type>(1.f, 0.f);
560 MATHEXTERN
template MENGE_API Vector2d<float> norm(
const Vector2d<float>& vector);
572 template<
class Type >
573 inline MENGE_API
bool equivalent(
const Vector2d<Type> & v1,
const Vector2d<Type> & v2,
float threshSqd=0.000001f ) {
574 return absSq( v1 - v2 ) < threshSqd;
581 MATHEXTERN
template MENGE_API
bool equivalent(
const Vector2d<float> & v1,
const Vector2d<float> & v2,
float threshSqd );
592 template<
class Type >
593 inline MENGE_API Type leftOf(
const Vector2d<Type>& a,
const Vector2d<Type>& b,
const Vector2d<Type>& c) {
594 return det(a - c, b - a);
601 MATHEXTERN
template MENGE_API
float leftOf(
const Vector2d<float>& a,
const Vector2d<float>& b,
const Vector2d<float>& c);
609 #pragma warning( default : 4231 )
611 #endif //__VECTOR2_H__
Vector2d()
Default constructor. It does NOT initialize the fields.
Definition: Vector2.h:82
void set(const Vector2d &v)
Set the x- and y-values from a vector.
Definition: Vector2.h:131
Vector2d< Type > operator-() const
Vector negation. Creates a new vector which is the negation of this vector.
Definition: Vector2.h:169
Vector2d & operator+=(const Vector2d &v)
Perform in-place vector addition on this vector.
Definition: Vector2.h:292
Vector2d< Type > operator*(float s) const
Computes the scalar multiplication of this vector with the given scalar value.
Definition: Vector2.h:194
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Type _x
x-component of the vector
Definition: Vector2.h:397
Sets up the proper compiler directives for platform and dll export/import.
float distance(float x, float y) const
Compute the distance from this vector to another point.
Definition: Vector2.h:362
float operator*(const Vector2d &v) const
Computes the dot product of this vector with the given vector.
Definition: Vector2.h:182
Templated vector in R2.
Definition: Vector2.h:76
A compilation of file system operations.
MENGE_API const float EPS
Suitably small number for testing for functional zero values.
Definition: geomQuery.cpp:52
float distance(const Vector2d &p) const
Compute the distance from this vector to another point.
Definition: Vector2.h:349
void negate()
Negate the vector in place.
Definition: Vector2.h:313
void set(Type x, Type y)
Set the x- and y-values from scalar values.
Definition: Vector2.h:121
An html logger - writes messages to a formatted html file.
Definition: Logger.h:59
void setX(Type x)
Set the x-value.
Definition: Vector2.h:141
Vector2d & operator/=(float s)
Perform in-place scalar division on this vector.
Definition: Vector2.h:279
Vector2d operator+(const Vector2d &v) const
Computes the vector sum of this vector with the given vector.
Definition: Vector2.h:219
The specificaiton of a message logger for menge, such that all messages to the system get properly re...
Type _y
y-component of the vector
Definition: Vector2.h:402
Vector2d & operator*=(float s)
Perform in-place scalar multiplication on this vector.
Definition: Vector2.h:267
Some common mathematical constants.
Vector2d operator-(const Vector2d &v) const
Computes the vector difference of this vector with the given vector.
Definition: Vector2.h:231
void zero()
Set the vector to zero.
Definition: Vector2.h:157
The namespace for math primitives for simulation and visualization.
Vector2d & operator-=(const Vector2d &v)
Perform in-place vector subtraction on this vector.
Definition: Vector2.h:304
Type Length() const
Compute the magnitude (aka length) of the vector.
Definition: Vector2.h:338
bool operator!=(const Vector2d &v) const
Reports if this vector is the different from the given vector.
Definition: Vector2.h:255
bool operator==(const Vector2d &v) const
Reports if this vector is the same as the given vector.
Definition: Vector2.h:243
void setY(Type y)
Set the y-value.
Definition: Vector2.h:150
Logger logger
Globally available Logger.
Definition: Logger.cpp:49
void normalize()
Normalize the vector in place.
Definition: Vector2.h:321
float distanceSq(const Vector2d &p) const
Compute the squared-distance from this vector to another point.
Definition: Vector2.h:375
Vector2d(const Vector2d &v)
Copy constructor.
Definition: Vector2.h:97
Vector2d(Type x, Type y)
Constructor with arguments.
Definition: Vector2.h:90
Type x() const
Get the x-value.
Definition: Vector2.h:106
Vector2d< Type > operator/(float s) const
Computes the scalar division of this vector with the given scalar value.
Definition: Vector2.h:206
Type y() const
Get the y-value.
Definition: Vector2.h:113
float distanceSq(float x, float y) const
Compute the squared-distance from this vector to another point.
Definition: Vector2.h:388