// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#ifndef POLAR_H
#define POLAR_H
///
/// A polar vector
///
/// This will use the polar coordinate system consisting of a angle from a
/// reference direction and a distance.
struct Polar {
public:
///
/// The angle in degrees, clockwise rotation
///
/// The angle is normalized to -180 .. 180
float angle;
///
/// The distance in meters
///
/// The distance should never be negative
float distance;
///
/// Create a new polar vector with zero degrees and distance
///
Polar();
///
/// Create a new polar vector
///
/// The angle in degrees, clockwise rotation
/// The distance in meters
Polar(float angle, float distance);
///
/// A polar vector with zero degrees and distance
///
const static Polar zero;
///
/// Negate the polar vector.
///
/// This will rotate the vector by 180 degrees. Distance will stay the same.
/// The negated vector
Polar operator-();
///
/// Substract a polar vector from this coordinate
///
/// The vector to subtract from this vector
/// The result of the subtraction
Polar operator-(const Polar& v) const;
///
/// Add another polar vector to this polar vector
///
/// The vector to add
/// The result of adding the vector
Polar operator+(const Polar& v) const;
///
/// Scale the vector uniformly up
///
/// The scaling factor
/// The scaled vector
/// This operation will scale the distance of the vector. The angle will be
/// unaffected.
Polar operator*(float factor) const;
///
/// Scale the vector uniformly down
///
/// The scaling factor
/// The scaled vector
/// This operation will scale the distance of the vector. The angle will be
/// unaffected.
Polar operator/(const float& factor);
///
/// The distance between two vectors
///
/// The first vector
/// The second vector
/// The distance between the two vectors
static float Distance(const Polar& v1, const Polar& v2);
///
/// Rotate the vector
///
/// The vector to rotate
/// Angle in radias to rotate
/// The rotated vector
static Polar Rotate(Polar v, float angle);
};
#endif