mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-24 01:54:22 +00:00
Added some length-squared methods to Line and Point
This commit is contained in:
parent
66793fc09b
commit
d48167a0b7
3 changed files with 11 additions and 2 deletions
|
|
@ -324,9 +324,9 @@ template <>
|
|||
inline float juce_hypot (float a, float b) noexcept
|
||||
{
|
||||
#if JUCE_MSVC
|
||||
return (_hypotf (a, b));
|
||||
return _hypotf (a, b);
|
||||
#else
|
||||
return (hypotf (a, b));
|
||||
return hypotf (a, b);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ public:
|
|||
/** Returns the length of the line. */
|
||||
ValueType getLength() const noexcept { return start.getDistanceFrom (end); }
|
||||
|
||||
/** Returns the length of the line. */
|
||||
ValueType getLengthSquared() const noexcept { return start.getDistanceSquaredFrom (end); }
|
||||
|
||||
/** Returns true if the line's start and end x coordinates are the same. */
|
||||
bool isVertical() const noexcept { return start.x == end.x; }
|
||||
|
||||
|
|
|
|||
|
|
@ -147,6 +147,12 @@ public:
|
|||
/** Returns the straight-line distance between this point and another one. */
|
||||
ValueType getDistanceFrom (Point other) const noexcept { return juce_hypot (x - other.x, y - other.y); }
|
||||
|
||||
/** Returns the square of the straight-line distance between this point and the origin. */
|
||||
ValueType getDistanceSquaredFromOrigin() const noexcept { return x * x + y * y; }
|
||||
|
||||
/** Returns the square of the straight-line distance between this point and another one. */
|
||||
ValueType getDistanceSquaredFrom (Point other) const noexcept { return (*this - other).getDistanceSquaredFromOrigin(); }
|
||||
|
||||
/** Returns the angle from this point to another one.
|
||||
|
||||
The return value is the number of radians clockwise from the 12 o'clock direction,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue