1
0
Fork 0
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:
jules 2016-02-01 11:22:04 +00:00
parent 66793fc09b
commit d48167a0b7
3 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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; }

View file

@ -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,