2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-07-05 15:53:10 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-07-05 15:53:10 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-07-05 15:53:10 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file vector2d.h
|
|
|
|
/// @see vector2d.cpp
|
|
|
|
/// @ingroup utility visual_ts
|
|
|
|
///
|
2007-07-05 15:53:10 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#pragma once
|
2007-07-05 15:53:10 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <cmath>
|
2007-07-05 15:53:10 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#endif
|
2007-07-05 15:53:10 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// DOCME
|
|
|
|
/// @class Vector2D
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
|
|
|
/// DOCME
|
2007-07-05 15:53:10 +02:00
|
|
|
class Vector2D {
|
2011-11-06 18:18:20 +01:00
|
|
|
float x, y;
|
2007-07-05 15:53:10 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
typedef float Vector2D::*unspecified_bool_type;
|
|
|
|
public:
|
|
|
|
float X() const { return x; }
|
|
|
|
float Y() const { return y; }
|
|
|
|
|
2011-12-07 00:13:06 +01:00
|
|
|
Vector2D();
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D(float x, float y) : x(x), y(y) { }
|
|
|
|
Vector2D(wxPoint pt) : x(pt.x), y(pt.y) { }
|
|
|
|
Vector2D(Vector2D x, Vector2D y) : x(x.x), y(y.y) { }
|
|
|
|
Vector2D(float x, Vector2D y) : x(x), y(y.y) { }
|
|
|
|
Vector2D(Vector2D x, float y) : x(x.x), y(y) { }
|
|
|
|
|
|
|
|
bool operator ==(const Vector2D r) const { return x == r.x && y == r.y; }
|
|
|
|
bool operator !=(const Vector2D r) const { return x != r.x || y != r.y; }
|
|
|
|
operator unspecified_bool_type() const;
|
|
|
|
|
|
|
|
Vector2D operator -() const { return Vector2D(-x, -y); }
|
|
|
|
Vector2D operator +(const Vector2D r) const { return Vector2D(x + r.x, y + r.y); }
|
|
|
|
Vector2D operator -(const Vector2D r) const { return Vector2D(x - r.x, y - r.y); }
|
|
|
|
Vector2D operator *(const Vector2D r) const { return Vector2D(x * r.x, y * r.y); }
|
|
|
|
Vector2D operator /(const Vector2D r) const { return Vector2D(x / r.x, y / r.y); }
|
|
|
|
Vector2D operator +(float param) const { return Vector2D(x + param, y + param); }
|
|
|
|
Vector2D operator -(float param) const { return Vector2D(x - param, y - param); }
|
|
|
|
Vector2D operator *(float param) const { return Vector2D(x * param, y * param); }
|
|
|
|
Vector2D operator /(float param) const { return Vector2D(x / param, y / param); }
|
|
|
|
|
|
|
|
Vector2D Unit() const;
|
|
|
|
Vector2D SingleAxis() const;
|
|
|
|
|
|
|
|
Vector2D Perpendicular() const { return Vector2D(-y, x); }
|
|
|
|
|
|
|
|
Vector2D Max(Vector2D param) const;
|
|
|
|
Vector2D Min(Vector2D param) const;
|
|
|
|
Vector2D Round(float step) const;
|
|
|
|
|
|
|
|
float Cross(const Vector2D param) const { return x * param.y - y * param.x; }
|
|
|
|
float Dot(const Vector2D param) const { return x * param.x + y * param.y; }
|
|
|
|
|
|
|
|
float Len() const { return sqrt(x*x + y*y); }
|
|
|
|
float SquareLen() const { return x*x + y*y; }
|
|
|
|
float Angle() const { return atan2(y, x); }
|
|
|
|
|
|
|
|
/// Get as string with given separator
|
|
|
|
wxString Str(char sep = ',') const;
|
|
|
|
/// Get as string surrounded by parentheses with given separator
|
|
|
|
wxString PStr(char sep = ',') const;
|
|
|
|
/// Get as string with given separator with values rounded to ints
|
|
|
|
wxString DStr(char sep = ',') const;
|
|
|
|
|
|
|
|
static Vector2D FromAngle(float angle) { return Vector2D(cos(-angle), sin(-angle)); }
|
2007-07-05 15:53:10 +02:00
|
|
|
};
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D operator * (float f, Vector2D v);
|
|
|
|
Vector2D operator / (float f, Vector2D v);
|
|
|
|
Vector2D operator + (float f, Vector2D v);
|
|
|
|
Vector2D operator - (float f, Vector2D v);
|