|
|
|
@@ -41,101 +41,101 @@ class Point |
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Creates a point at the origin */
|
|
|
|
Point() noexcept : x(), y() {}
|
|
|
|
JUCE_CONSTEXPR Point() noexcept : x(), y() {}
|
|
|
|
|
|
|
|
/** Creates a copy of another point. */
|
|
|
|
Point (const Point& other) noexcept : x (other.x), y (other.y) {}
|
|
|
|
JUCE_CONSTEXPR Point (const Point& other) noexcept : x (other.x), y (other.y) {}
|
|
|
|
|
|
|
|
/** Creates a point from an (x, y) position. */
|
|
|
|
Point (ValueType initialX, ValueType initialY) noexcept : x (initialX), y (initialY) {}
|
|
|
|
JUCE_CONSTEXPR Point (ValueType initialX, ValueType initialY) noexcept : x (initialX), y (initialY) {}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
/** Copies this point from another one. */
|
|
|
|
Point& operator= (const Point& other) noexcept { x = other.x; y = other.y; return *this; }
|
|
|
|
Point& operator= (const Point& other) noexcept { x = other.x; y = other.y; return *this; }
|
|
|
|
|
|
|
|
inline bool operator== (Point other) const noexcept { return x == other.x && y == other.y; }
|
|
|
|
inline bool operator!= (Point other) const noexcept { return x != other.x || y != other.y; }
|
|
|
|
JUCE_CONSTEXPR inline bool operator== (Point other) const noexcept { return x == other.x && y == other.y; }
|
|
|
|
JUCE_CONSTEXPR inline bool operator!= (Point other) const noexcept { return x != other.x || y != other.y; }
|
|
|
|
|
|
|
|
/** Returns true if the point is (0, 0). */
|
|
|
|
bool isOrigin() const noexcept { return x == ValueType() && y == ValueType(); }
|
|
|
|
JUCE_CONSTEXPR bool isOrigin() const noexcept { return x == ValueType() && y == ValueType(); }
|
|
|
|
|
|
|
|
/** Returns true if the coordinates are finite values. */
|
|
|
|
inline bool isFinite() const noexcept { return juce_isfinite(x) && juce_isfinite(y); }
|
|
|
|
JUCE_CONSTEXPR inline bool isFinite() const noexcept { return juce_isfinite(x) && juce_isfinite(y); }
|
|
|
|
|
|
|
|
/** Returns the point's x coordinate. */
|
|
|
|
inline ValueType getX() const noexcept { return x; }
|
|
|
|
JUCE_CONSTEXPR inline ValueType getX() const noexcept { return x; }
|
|
|
|
|
|
|
|
/** Returns the point's y coordinate. */
|
|
|
|
inline ValueType getY() const noexcept { return y; }
|
|
|
|
JUCE_CONSTEXPR inline ValueType getY() const noexcept { return y; }
|
|
|
|
|
|
|
|
/** Sets the point's x coordinate. */
|
|
|
|
inline void setX (ValueType newX) noexcept { x = newX; }
|
|
|
|
inline void setX (ValueType newX) noexcept { x = newX; }
|
|
|
|
|
|
|
|
/** Sets the point's y coordinate. */
|
|
|
|
inline void setY (ValueType newY) noexcept { y = newY; }
|
|
|
|
inline void setY (ValueType newY) noexcept { y = newY; }
|
|
|
|
|
|
|
|
/** Returns a point which has the same Y position as this one, but a new X. */
|
|
|
|
Point withX (ValueType newX) const noexcept { return Point (newX, y); }
|
|
|
|
JUCE_CONSTEXPR Point withX (ValueType newX) const noexcept { return Point (newX, y); }
|
|
|
|
|
|
|
|
/** Returns a point which has the same X position as this one, but a new Y. */
|
|
|
|
Point withY (ValueType newY) const noexcept { return Point (x, newY); }
|
|
|
|
JUCE_CONSTEXPR Point withY (ValueType newY) const noexcept { return Point (x, newY); }
|
|
|
|
|
|
|
|
/** Changes the point's x and y coordinates. */
|
|
|
|
void setXY (ValueType newX, ValueType newY) noexcept { x = newX; y = newY; }
|
|
|
|
void setXY (ValueType newX, ValueType newY) noexcept { x = newX; y = newY; }
|
|
|
|
|
|
|
|
/** Adds a pair of coordinates to this value. */
|
|
|
|
void addXY (ValueType xToAdd, ValueType yToAdd) noexcept { x += xToAdd; y += yToAdd; }
|
|
|
|
void addXY (ValueType xToAdd, ValueType yToAdd) noexcept { x += xToAdd; y += yToAdd; }
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
/** Returns a point with a given offset from this one. */
|
|
|
|
Point translated (ValueType deltaX, ValueType deltaY) const noexcept { return Point (x + deltaX, y + deltaY); }
|
|
|
|
JUCE_CONSTEXPR Point translated (ValueType deltaX, ValueType deltaY) const noexcept { return Point (x + deltaX, y + deltaY); }
|
|
|
|
|
|
|
|
/** Adds two points together */
|
|
|
|
Point operator+ (Point other) const noexcept { return Point (x + other.x, y + other.y); }
|
|
|
|
JUCE_CONSTEXPR Point operator+ (Point other) const noexcept { return Point (x + other.x, y + other.y); }
|
|
|
|
|
|
|
|
/** Adds another point's coordinates to this one */
|
|
|
|
Point& operator+= (Point other) noexcept { x += other.x; y += other.y; return *this; }
|
|
|
|
Point& operator+= (Point other) noexcept { x += other.x; y += other.y; return *this; }
|
|
|
|
|
|
|
|
/** Subtracts one points from another */
|
|
|
|
Point operator- (Point other) const noexcept { return Point (x - other.x, y - other.y); }
|
|
|
|
JUCE_CONSTEXPR Point operator- (Point other) const noexcept { return Point (x - other.x, y - other.y); }
|
|
|
|
|
|
|
|
/** Subtracts another point's coordinates to this one */
|
|
|
|
Point& operator-= (Point other) noexcept { x -= other.x; y -= other.y; return *this; }
|
|
|
|
Point& operator-= (Point other) noexcept { x -= other.x; y -= other.y; return *this; }
|
|
|
|
|
|
|
|
/** Multiplies two points together */
|
|
|
|
template <typename OtherType>
|
|
|
|
Point operator* (Point<OtherType> other) const noexcept { return Point ((ValueType) (x * other.x), (ValueType) (y * other.y)); }
|
|
|
|
JUCE_CONSTEXPR Point operator* (Point<OtherType> other) const noexcept { return Point ((ValueType) (x * other.x), (ValueType) (y * other.y)); }
|
|
|
|
|
|
|
|
/** Multiplies another point's coordinates to this one */
|
|
|
|
template <typename OtherType>
|
|
|
|
Point& operator*= (Point<OtherType> other) noexcept { *this = *this * other; return *this; }
|
|
|
|
Point& operator*= (Point<OtherType> other) noexcept { *this = *this * other; return *this; }
|
|
|
|
|
|
|
|
/** Divides one point by another */
|
|
|
|
template <typename OtherType>
|
|
|
|
Point operator/ (Point<OtherType> other) const noexcept { return Point ((ValueType) (x / other.x), (ValueType) (y / other.y)); }
|
|
|
|
JUCE_CONSTEXPR Point operator/ (Point<OtherType> other) const noexcept { return Point ((ValueType) (x / other.x), (ValueType) (y / other.y)); }
|
|
|
|
|
|
|
|
/** Divides this point's coordinates by another */
|
|
|
|
template <typename OtherType>
|
|
|
|
Point& operator/= (Point<OtherType> other) noexcept { *this = *this / other; return *this; }
|
|
|
|
Point& operator/= (Point<OtherType> other) noexcept { *this = *this / other; return *this; }
|
|
|
|
|
|
|
|
/** Returns a point whose coordinates are multiplied by a given scalar value. */
|
|
|
|
template <typename FloatType>
|
|
|
|
Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) (x * multiplier), (ValueType) (y * multiplier)); }
|
|
|
|
JUCE_CONSTEXPR Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) (x * multiplier), (ValueType) (y * multiplier)); }
|
|
|
|
|
|
|
|
/** Returns a point whose coordinates are divided by a given scalar value. */
|
|
|
|
template <typename FloatType>
|
|
|
|
Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) (x / divisor), (ValueType) (y / divisor)); }
|
|
|
|
JUCE_CONSTEXPR Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) (x / divisor), (ValueType) (y / divisor)); }
|
|
|
|
|
|
|
|
/** Multiplies the point's coordinates by a scalar value. */
|
|
|
|
template <typename FloatType>
|
|
|
|
Point& operator*= (FloatType multiplier) noexcept { x = (ValueType) (x * multiplier); y = (ValueType) (y * multiplier); return *this; }
|
|
|
|
Point& operator*= (FloatType multiplier) noexcept { x = (ValueType) (x * multiplier); y = (ValueType) (y * multiplier); return *this; }
|
|
|
|
|
|
|
|
/** Divides the point's coordinates by a scalar value. */
|
|
|
|
template <typename FloatType>
|
|
|
|
Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; }
|
|
|
|
Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; }
|
|
|
|
|
|
|
|
/** Returns the inverse of this point. */
|
|
|
|
Point operator-() const noexcept { return Point (-x, -y); }
|
|
|
|
JUCE_CONSTEXPR Point operator-() const noexcept { return Point (-x, -y); }
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
/** This type will be double if the Point's type is double, otherwise it will be float. */
|
|
|
|
|