1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-09 01:07:16 +01:00
SqMod/source/Base/Circle.hpp
Sandu Liviu Catalin 8088ba94c2 Updated the exception system in the main plugin to also include the location in the source files in debug builds.
Moved the functions that extract base types from strings as static functions under the associated type.
Revised some of the base shared code.
Fixed some of the functions in the String library that did not take into account the null terminator.
2016-03-21 22:37:58 +02:00

401 lines
15 KiB
C++

#ifndef _BASE_CIRCLE_HPP_
#define _BASE_CIRCLE_HPP_
// ------------------------------------------------------------------------------------------------
#include "SqBase.hpp"
#include "Base/Vector2.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Extract the values for components of the Circle type from a string.
*/
const Circle & GetCircle(CSStr str, SQChar delim);
/* ------------------------------------------------------------------------------------------------
* Class used to represent a two-dimensional circle.
*/
struct Circle
{
/* --------------------------------------------------------------------------------------------
* The type of value used by components of type.
*/
typedef float Value;
/* --------------------------------------------------------------------------------------------
* Helper instances for common values mostly used as return types or comparison.
*/
static const Circle NIL;
static const Circle MIN;
static const Circle MAX;
/* --------------------------------------------------------------------------------------------
* The delimiter character to be used when extracting values from strings.
*/
static SQChar Delim;
/* --------------------------------------------------------------------------------------------
* The position and radius components of this type.
*/
Vector2 pos;
Value rad;
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Circle();
/* --------------------------------------------------------------------------------------------
* Construct a circle at position 0,0 using the specified radius.
*/
Circle(Value rv);
/* --------------------------------------------------------------------------------------------
* Construct a circle at the specified position using the specified radius.
*/
Circle(const Vector2 & pv, Value rv);
/* --------------------------------------------------------------------------------------------
* Construct a circle at the specified position using the specified radius.
*/
Circle(Value xv, Value yv, Value rv);
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
Circle(const Circle & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
Circle(Circle && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Circle() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
Circle & operator = (const Circle & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
Circle & operator = (Circle && o) = default;
/* --------------------------------------------------------------------------------------------
* Radius assignment operator.
*/
Circle & operator = (Value r);
/* --------------------------------------------------------------------------------------------
* Position assignment operator.
*/
Circle & operator = (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Addition assignment operator.
*/
Circle & operator += (const Circle & c);
/* --------------------------------------------------------------------------------------------
* Subtraction assignment operator.
*/
Circle & operator -= (const Circle & c);
/* --------------------------------------------------------------------------------------------
* Multiplication assignment operator.
*/
Circle & operator *= (const Circle & c);
/* --------------------------------------------------------------------------------------------
* Division assignment operator.
*/
Circle & operator /= (const Circle & c);
/* --------------------------------------------------------------------------------------------
* Modulo assignment operator.
*/
Circle & operator %= (const Circle & c);
/* --------------------------------------------------------------------------------------------
* Radius addition assignment operator.
*/
Circle & operator += (Value r);
/* --------------------------------------------------------------------------------------------
* Radius subtraction assignment operator.
*/
Circle & operator -= (Value r);
/* --------------------------------------------------------------------------------------------
* Radius multiplication assignment operator.
*/
Circle & operator *= (Value r);
/* --------------------------------------------------------------------------------------------
* Radius division assignment operator.
*/
Circle & operator /= (Value r);
/* --------------------------------------------------------------------------------------------
* Radius modulo assignment operator.
*/
Circle & operator %= (Value r);
/* --------------------------------------------------------------------------------------------
* Position addition assignment operator.
*/
Circle & operator += (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Position subtraction assignment operator.
*/
Circle & operator -= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Position multiplication assignment operator.
*/
Circle & operator *= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Position division assignment operator.
*/
Circle & operator /= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Position modulo assignment operator.
*/
Circle & operator %= (const Vector2 & p);
/* --------------------------------------------------------------------------------------------
* Pre-increment operator.
*/
Circle & operator ++ ();
/* --------------------------------------------------------------------------------------------
* Pre-decrement operator.
*/
Circle & operator -- ();
/* --------------------------------------------------------------------------------------------
* Post-increment operator.
*/
Circle operator ++ (int);
/* --------------------------------------------------------------------------------------------
* Post-decrement operator.
*/
Circle operator -- (int);
/* --------------------------------------------------------------------------------------------
* Addition operator.
*/
Circle operator + (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Subtraction operator.
*/
Circle operator - (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Multiplication operator.
*/
Circle operator * (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Division operator.
*/
Circle operator / (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Modulo operator.
*/
Circle operator % (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Radius addition operator.
*/
Circle operator + (Value r) const;
/* --------------------------------------------------------------------------------------------
* Radius subtraction operator.
*/
Circle operator - (Value r) const;
/* --------------------------------------------------------------------------------------------
* Radius multiplication operator.
*/
Circle operator * (Value r) const;
/* --------------------------------------------------------------------------------------------
* Radius division operator.
*/
Circle operator / (Value r) const;
/* --------------------------------------------------------------------------------------------
* Radius modulo operator.
*/
Circle operator % (Value r) const;
/* --------------------------------------------------------------------------------------------
* Position addition operator.
*/
Circle operator + (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* Position subtraction operator.
*/
Circle operator - (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* Position multiplication operator.
*/
Circle operator * (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* Position division operator.
*/
Circle operator / (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* Position modulo operator.
*/
Circle operator % (const Vector2 & p) const;
/* --------------------------------------------------------------------------------------------
* Unary plus operator.
*/
Circle operator + () const;
/* --------------------------------------------------------------------------------------------
* Unary minus operator.
*/
Circle operator - () const;
/* --------------------------------------------------------------------------------------------
* Equality comparison operator.
*/
bool operator == (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Inequality comparison operator.
*/
bool operator != (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Less than comparison operator.
*/
bool operator < (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Greater than comparison operator.
*/
bool operator > (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Less than or equal comparison operator.
*/
bool operator <= (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Greater than or equal comparison operator.
*/
bool operator >= (const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Circle & c) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to retrieve the name from instances of this type.
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Set the specified radius.
*/
void Set(Value nr);
/* --------------------------------------------------------------------------------------------
* Copy the circle from another instance of this type.
*/
void Set(const Circle & nc);
/* --------------------------------------------------------------------------------------------
* Set the position from the specified position.
*/
void Set(const Vector2 & np);
/* --------------------------------------------------------------------------------------------
* Set the specified position and radius.
*/
void Set(const Vector2 & np, Value nr);
/* --------------------------------------------------------------------------------------------
* Set the specified position.
*/
void Set(Value nx, Value ny);
/* --------------------------------------------------------------------------------------------
* Set the specified position and radius.
*/
void Set(Value nx, Value ny, Value nr);
/* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter.
*/
void Set(CSStr values, SQChar delim);
/* --------------------------------------------------------------------------------------------
* Generate a randomly sized and positioned circle.
*/
void Generate();
/* --------------------------------------------------------------------------------------------
* Generate a randomly sized or positioned circle within the specified bounds.
*/
void Generate(Value min, Value max, bool r);
/* --------------------------------------------------------------------------------------------
* Generate a randomly positioned circle within the specified bounds.
*/
void Generate(Value xmin, Value xmax, Value ymin, Value ymax);
/* --------------------------------------------------------------------------------------------
* Generate a randomly sized and positioned circle within the specified bounds.
*/
void Generate(Value xmin, Value xmax, Value ymin, Value ymax, Value rmin, Value rmax);
/* --------------------------------------------------------------------------------------------
* Clear the component values to default.
*/
void Clear()
{
pos.Clear(); rad = 0.0;
}
/* --------------------------------------------------------------------------------------------
* Retrieve a new instance of this type with absolute component values.
*/
Circle Abs() const;
};
} // Namespace:: SqMod
#endif // _BASE_CIRCLE_HPP_