Loading...
Searching...
No Matches
juce::Point< ValueType > Class Template Reference

## Detailed Description

template<typename ValueType>
class juce::Point< ValueType >

A pair of (x, y) coordinates.

The ValueType template should be a primitive type such as int, float, double, rather than a class.

See also
  Line, Path, AffineTransform

The documentation for this class was generated from the following file:

- juce_graphics/geometry/juce_Point.h

## Public Types

using | FloatType = TypeHelpers::SmallestFloatType<ValueType>
| This type will be double if the Point's type is double, otherwise it will be float.

## Public Member Functions

constexpr | Point ()=default
| Creates a point at the origin.
constexpr | Point (const Point &)=default
| Creates a copy of another point.
constexpr | Point (ValueType initialX, ValueType initialY) noexcept
| Creates a point from an (x, y) position.
Point & | operator= (const Point &)=default
| Copies this point from another one.
constexpr bool | operator== (Point other) const noexcept
constexpr bool | operator!= (Point other) const noexcept
constexpr bool | isOrigin () const noexcept
| Returns true if the point is (0, 0).
constexpr bool | isFinite () const noexcept
| Returns true if the coordinates are finite values.
constexpr ValueType | getX () const noexcept
| Returns the point's x coordinate.
constexpr ValueType | getY () const noexcept
| Returns the point's y coordinate.
void | setX (ValueType newX) noexcept
| Sets the point's x coordinate.
void | setY (ValueType newY) noexcept
| Sets the point's y coordinate.
constexpr Point | withX (ValueType newX) const noexcept
| Returns a point which has the same Y position as this one, but a new X.
constexpr Point | withY (ValueType newY) const noexcept
| Returns a point which has the same X position as this one, but a new Y.
void | setXY (ValueType newX, ValueType newY) noexcept
| Changes the point's x and y coordinates.
void | addXY (ValueType xToAdd, ValueType yToAdd) noexcept
| Adds a pair of coordinates to this value.
constexpr Point | translated (ValueType deltaX, ValueType deltaY) const noexcept
| Returns a point with a given offset from this one.
constexpr Point | operator+ (Point other) const noexcept
| Adds two points together.
Point & | operator+= (Point other) noexcept
| Adds another point's coordinates to this one.
constexpr Point | operator- (Point other) const noexcept
| Subtracts one points from another.
Point & | operator-= (Point other) noexcept
| Subtracts another point's coordinates to this one.
template<typename OtherType>
constexpr Point | operator* (Point< OtherType > other) const noexcept
| Multiplies two points together.
template<typename OtherType>
Point & | operator*= (Point< OtherType > other) noexcept
| Multiplies another point's coordinates to this one.
template<typename OtherType>
constexpr Point | operator/ (Point< OtherType > other) const noexcept
| Divides one point by another.
template<typename OtherType>
Point & | operator/= (Point< OtherType > other) noexcept
| Divides this point's coordinates by another.
template<typename OtherType>
constexpr Point | operator* (OtherType multiplier) const noexcept
| Returns a point whose coordinates are multiplied by a given scalar value.
template<typename OtherType>
constexpr Point | operator/ (OtherType divisor) const noexcept
| Returns a point whose coordinates are divided by a given scalar value.
template<typename FloatType>
Point & | operator*= (FloatType multiplier) noexcept
| Multiplies the point's coordinates by a scalar value.
template<typename FloatType>
Point & | operator/= (FloatType divisor) noexcept
| Divides the point's coordinates by a scalar value.
constexpr Point | operator- () const noexcept
| Returns the inverse of this point.
ValueType | getDistanceFromOrigin () const noexcept
| Returns the straight-line distance between this point and the origin.
ValueType | getDistanceFrom (Point other) const noexcept
| Returns the straight-line distance between this point and another one.
constexpr ValueType | getDistanceSquaredFromOrigin () const noexcept
| Returns the square of the straight-line distance between this point and the origin.
constexpr ValueType | getDistanceSquaredFrom (Point other) const noexcept
| Returns the square of the straight-line distance between this point and another one.
FloatType | getAngleToPoint (Point other) const noexcept
| Returns the angle from this point to another one.
template<typename T = ValueType, std::enable_if_t< std::is_floating_point_v< T >, int > = 0>
Point | rotatedAboutOrigin (ValueType angleRadians) const noexcept
| Returns the point that would be reached by rotating this point clockwise about the origin by the specified angle.
Point< FloatType > | getPointOnCircumference (float radius, float angle) const noexcept
| Taking this point to be the centre of a circle, this returns a point on its circumference.
Point< FloatType > | getPointOnCircumference (float radiusX, float radiusY, float angle) const noexcept
| Taking this point to be the centre of an ellipse, this returns a point on its circumference.
constexpr FloatType | getDotProduct (Point other) const noexcept
| Returns the dot-product of two points (x1 * x2 + y1 * y2).
void | applyTransform (const AffineTransform &transform) noexcept
| Uses a transform to change the point's coordinates.
Point | transformedBy (const AffineTransform &transform) const noexcept
| Returns the position of this point, if it is transformed by a given AffineTransform.
constexpr Point< int > | toInt () const noexcept
| Casts this point to a Point<int> object.
constexpr Point< float > | toFloat () const noexcept
| Casts this point to a Point<float> object.
constexpr Point< double > | toDouble () const noexcept
| Casts this point to a Point<double> object.
constexpr Point< int > | roundToInt () const noexcept
| Casts this point to a Point<int> object using roundToInt() to convert the values.
String | toString () const
| Returns the point as a string in the form "x, y".

## Public Attributes

ValueType | x {}
| The point's X coordinate.
ValueType | y {}
| The point's Y coordinate.

## Member Typedef Documentation

## FloatType

template<typename ValueType>

using juce::Point< ValueType >::FloatType = TypeHelpers::SmallestFloatType<ValueType>

This type will be double if the Point's type is double, otherwise it will be float.

## Constructors and Destructors

## Point() [1/3]

template<typename ValueType>

juce::Point< ValueType >::Point | ( |  | ) |

constexpr default

Creates a point at the origin.

Referenced by getAngleToPoint(), getDistanceFrom(), getDistanceSquaredFrom(), getDotProduct(), getPointOnCircumference(), getPointOnCircumference(), isOrigin(), operator!=(), operator*(), operator*(), operator*=(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/(), operator/=(), operator/=(), operator=(), operator==(), Point(), rotatedAboutOrigin(), roundToInt(), toDouble(), toFloat(), toInt(), transformedBy(), translated(), withX(), and withY().

## Point() [2/3]

template<typename ValueType>

juce::Point< ValueType >::Point | ( | const Point< ValueType > & |  | ) |

constexpr default

Creates a copy of another point.

References Point().

## Point() [3/3]

template<typename ValueType>

juce::Point< ValueType >::Point | ( | ValueType | initialX,
|  | ValueType | initialY )

inline constexpr noexcept

Creates a point from an (x, y) position.

## Member Functions

## operator=()

template<typename ValueType>

Point & juce::Point< ValueType >::operator= | ( | const Point< ValueType > & |  | ) |

default

Copies this point from another one.

References Point().

## operator==()

template<typename ValueType>

bool juce::Point< ValueType >::operator== | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

References Point().

Referenced by isOrigin(), and operator!=().

## operator!=()

template<typename ValueType>

bool juce::Point< ValueType >::operator!= | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

References operator==(), and Point().

## isOrigin()

template<typename ValueType>

bool juce::Point< ValueType >::isOrigin | ( |  | ) | const

inline constexpr noexcept

Returns true if the point is (0, 0).

References operator==(), and Point().

## isFinite()

template<typename ValueType>

bool juce::Point< ValueType >::isFinite | ( |  | ) | const

inline constexpr noexcept

Returns true if the coordinates are finite values.

References juce::juce_isfinite(), x, and y.

## getX()

template<typename ValueType>

ValueType juce::Point< ValueType >::getX | ( |  | ) | const

inline constexpr noexcept

Returns the point's x coordinate.

References x.

## getY()

template<typename ValueType>

ValueType juce::Point< ValueType >::getY | ( |  | ) | const

inline constexpr noexcept

Returns the point's y coordinate.

References y.

## setX()

template<typename ValueType>

void juce::Point< ValueType >::setX | ( | ValueType | newX | ) |

inline noexcept

Sets the point's x coordinate.

References x.

## setY()

template<typename ValueType>

void juce::Point< ValueType >::setY | ( | ValueType | newY | ) |

inline noexcept

Sets the point's y coordinate.

References y.

## withX()

template<typename ValueType>

Point juce::Point< ValueType >::withX | ( | ValueType | newX | ) | const

inline constexpr noexcept

Returns a point which has the same Y position as this one, but a new X.

References Point(), and y.

## withY()

template<typename ValueType>

Point juce::Point< ValueType >::withY | ( | ValueType | newY | ) | const

inline constexpr noexcept

Returns a point which has the same X position as this one, but a new Y.

References Point(), and x.

## setXY()

template<typename ValueType>

void juce::Point< ValueType >::setXY | ( | ValueType | newX,
|  | ValueType | newY )

inline noexcept

Changes the point's x and y coordinates.

References x, and y.

## addXY()

template<typename ValueType>

void juce::Point< ValueType >::addXY | ( | ValueType | xToAdd,
|  | ValueType | yToAdd )

inline noexcept

Adds a pair of coordinates to this value.

References x, and y.

## translated()

template<typename ValueType>

Point juce::Point< ValueType >::translated | ( | ValueType | deltaX,
|  | ValueType | deltaY ) const

inline constexpr noexcept

Returns a point with a given offset from this one.

References Point(), x, and y.

## operator+()

template<typename ValueType>

Point juce::Point< ValueType >::operator+ | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

Adds two points together.

References Point(), x, and y.

## operator+=()

template<typename ValueType>

Point & juce::Point< ValueType >::operator+= | ( | Point< ValueType > | other | ) |

inline noexcept

Adds another point's coordinates to this one.

References Point(), x, and y.

## operator-() [1/2]

template<typename ValueType>

Point juce::Point< ValueType >::operator- | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

Subtracts one points from another.

References Point(), x, and y.

## operator-=()

template<typename ValueType>

Point & juce::Point< ValueType >::operator-= | ( | Point< ValueType > | other | ) |

inline noexcept

Subtracts another point's coordinates to this one.

References Point(), x, and y.

## operator*() [1/2]

template<typename ValueType>
template<typename OtherType>

Point juce::Point< ValueType >::operator* | ( | Point< OtherType > | other | ) | const

inline constexpr noexcept

Multiplies two points together.

References Point(), x, and y.

## operator*=() [1/2]

template<typename ValueType>
template<typename OtherType>

Point & juce::Point< ValueType >::operator*= | ( | Point< OtherType > | other | ) |

inline noexcept

Multiplies another point's coordinates to this one.

References Point().

## operator/() [1/2]

template<typename ValueType>
template<typename OtherType>

Point juce::Point< ValueType >::operator/ | ( | Point< OtherType > | other | ) | const

inline constexpr noexcept

Divides one point by another.

References Point(), x, and y.

## operator/=() [1/2]

template<typename ValueType>
template<typename OtherType>

Point & juce::Point< ValueType >::operator/= | ( | Point< OtherType > | other | ) |

inline noexcept

Divides this point's coordinates by another.

References Point().

## operator*() [2/2]

template<typename ValueType>
template<typename OtherType>

Point juce::Point< ValueType >::operator* | ( | OtherType | multiplier | ) | const

inline constexpr noexcept

Returns a point whose coordinates are multiplied by a given scalar value.

References Point(), x, and y.

## operator/() [2/2]

template<typename ValueType>
template<typename OtherType>

Point juce::Point< ValueType >::operator/ | ( | OtherType | divisor | ) | const

inline constexpr noexcept

Returns a point whose coordinates are divided by a given scalar value.

References Point(), x, and y.

## operator*=() [2/2]

template<typename ValueType>
template<typename FloatType>

Point & juce::Point< ValueType >::operator*= | ( | FloatType | multiplier | ) |

inline noexcept

Multiplies the point's coordinates by a scalar value.

References Point(), x, and y.

## operator/=() [2/2]

template<typename ValueType>
template<typename FloatType>

Point & juce::Point< ValueType >::operator/= | ( | FloatType | divisor | ) |

inline noexcept

Divides the point's coordinates by a scalar value.

References Point(), x, and y.

## operator-() [2/2]

template<typename ValueType>

Point juce::Point< ValueType >::operator- | ( |  | ) | const

inline constexpr noexcept

Returns the inverse of this point.

References Point(), x, and y.

## getDistanceFromOrigin()

template<typename ValueType>

ValueType juce::Point< ValueType >::getDistanceFromOrigin | ( |  | ) | const

inline noexcept

Returns the straight-line distance between this point and the origin.

References juce::juce_hypot(), x, and y.

## getDistanceFrom()

template<typename ValueType>

ValueType juce::Point< ValueType >::getDistanceFrom | ( | Point< ValueType > | other | ) | const

inline noexcept

Returns the straight-line distance between this point and another one.

References juce::juce_hypot(), Point(), x, and y.

## getDistanceSquaredFromOrigin()

template<typename ValueType>

ValueType juce::Point< ValueType >::getDistanceSquaredFromOrigin | ( |  | ) | const

inline constexpr noexcept

Returns the square of the straight-line distance between this point and the origin.

References x, and y.

## getDistanceSquaredFrom()

template<typename ValueType>

ValueType juce::Point< ValueType >::getDistanceSquaredFrom | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

Returns the square of the straight-line distance between this point and another one.

References Point().

## getAngleToPoint()

template<typename ValueType>

FloatType juce::Point< ValueType >::getAngleToPoint | ( | Point< ValueType > | other | ) | const

inline noexcept

Returns the angle from this point to another one.

Taking this point to be the centre of a circle, and the other point being a position on the circumference, the return value is the number of radians clockwise from the 12 o'clock direction. So 12 o'clock = 0, 3 o'clock = Pi/2, 6 o'clock = Pi, 9 o'clock = -Pi/2

References Point(), x, and y.

## rotatedAboutOrigin()

template<typename ValueType>
template<typename T = ValueType, std::enable_if_t< std::is_floating_point_v< T >, int > = 0>

Point juce::Point< ValueType >::rotatedAboutOrigin | ( | ValueType | angleRadians | ) | const

inline noexcept

Returns the point that would be reached by rotating this point clockwise about the origin by the specified angle.

References Point(), x, and y.

## getPointOnCircumference() [1/2]

template<typename ValueType>

Point< FloatType > juce::Point< ValueType >::getPointOnCircumference | ( | float | radius,
|  | float | angle ) const

inline noexcept

Taking this point to be the centre of a circle, this returns a point on its circumference.

Parameters

  radius | the radius of the circle.
  angle | the angle of the point, in radians clockwise from the 12 o'clock position.

References Point(), x, and y.

## getPointOnCircumference() [2/2]

template<typename ValueType>

Point< FloatType > juce::Point< ValueType >::getPointOnCircumference | ( | float | radiusX,
|  | float | radiusY,
|  | float | angle ) const

inline noexcept

Taking this point to be the centre of an ellipse, this returns a point on its circumference.

Parameters

  radiusX | the horizontal radius of the circle.
  radiusY | the vertical radius of the circle.
  angle | the angle of the point, in radians clockwise from the 12 o'clock position.

References Point(), x, and y.

## getDotProduct()

template<typename ValueType>

FloatType juce::Point< ValueType >::getDotProduct | ( | Point< ValueType > | other | ) | const

inline constexpr noexcept

Returns the dot-product of two points (x1 * x2 + y1 * y2).

References Point(), x, and y.

## applyTransform()

template<typename ValueType>

void juce::Point< ValueType >::applyTransform | ( | const AffineTransform & | transform | ) |

inline noexcept

Uses a transform to change the point's coordinates.

This will only compile if ValueType = float!

See also
  AffineTransform::transformPoint

References x, and y.

## transformedBy()

template<typename ValueType>

Point juce::Point< ValueType >::transformedBy | ( | const AffineTransform & | transform | ) | const

inline noexcept

Returns the position of this point, if it is transformed by a given AffineTransform.

References Point(), x, and y.

## toInt()

template<typename ValueType>

Point< int > juce::Point< ValueType >::toInt | ( |  | ) | const

inline constexpr noexcept

Casts this point to a Point<int> object.

References Point(), x, and y.

## toFloat()

template<typename ValueType>

Point< float > juce::Point< ValueType >::toFloat | ( |  | ) | const

inline constexpr noexcept

Casts this point to a Point<float> object.

References Point(), x, and y.

## toDouble()

template<typename ValueType>

Point< double > juce::Point< ValueType >::toDouble | ( |  | ) | const

inline constexpr noexcept

Casts this point to a Point<double> object.

References Point(), x, and y.

## roundToInt()

template<typename ValueType>

Point< int > juce::Point< ValueType >::roundToInt | ( |  | ) | const

inline constexpr noexcept

Casts this point to a Point<int> object using roundToInt() to convert the values.

References Point(), juce::roundToInt(), x, and y.

## toString()

template<typename ValueType>

String juce::Point< ValueType >::toString | ( |  | ) | const

inline

Returns the point as a string in the form "x, y".

References x, and y.

## Member Data Documentation

## x

template<typename ValueType>

ValueType juce::Point< ValueType >::x {}

The point's X coordinate.

Referenced by addXY(), applyTransform(), getAngleToPoint(), getDistanceFrom(), getDistanceFromOrigin(), getDistanceSquaredFromOrigin(), getDotProduct(), getPointOnCircumference(), getPointOnCircumference(), getX(), isFinite(), operator*(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/(), operator/=(), rotatedAboutOrigin(), roundToInt(), setX(), setXY(), toDouble(), toFloat(), toInt(), toString(), transformedBy(), translated(), and withY().

## y

template<typename ValueType>

ValueType juce::Point< ValueType >::y {}

The point's Y coordinate.

Referenced by addXY(), applyTransform(), getAngleToPoint(), getDistanceFrom(), getDistanceFromOrigin(), getDistanceSquaredFromOrigin(), getDotProduct(), getPointOnCircumference(), getPointOnCircumference(), getY(), isFinite(), operator*(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/(), operator/=(), rotatedAboutOrigin(), roundToInt(), setXY(), setY(), toDouble(), toFloat(), toInt(), toString(), transformedBy(), translated(), and withX().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited