JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Public Attributes | List of all members
Point< ValueType > Class Template Reference

A pair of (x, y) co-ordinates. More...

Public Types

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

Public Member Functions

 Point () noexcept
 Creates a point with co-ordinates (0, 0).
 
 Point (const Point &other) noexcept
 Creates a copy of another point.
 
 Point (const ValueType initialX, const ValueType initialY) noexcept
 Creates a point from an (x, y) position.
 
 ~Point () noexcept
 Destructor.
 
Pointoperator= (const Point &other) noexcept
 Copies this point from another one.
 
bool operator== (const Point &other) const noexcept
 
bool operator!= (const Point &other) const noexcept
 
bool isOrigin () const noexcept
 Returns true if the point is (0, 0).
 
ValueType getX () const noexcept
 Returns the point's x co-ordinate.
 
ValueType getY () const noexcept
 Returns the point's y co-ordinate.
 
void setX (const ValueType newX) noexcept
 Sets the point's x co-ordinate.
 
void setY (const ValueType newY) noexcept
 Sets the point's y co-ordinate.
 
Point withX (const ValueType newX) const noexcept
 Returns a point which has the same Y position as this one, but a new X.
 
Point withY (const ValueType newY) const noexcept
 Returns a point which has the same X position as this one, but a new Y.
 
void setXY (const ValueType newX, const ValueType newY) noexcept
 Changes the point's x and y co-ordinates.
 
void addXY (const ValueType xToAdd, const ValueType yToAdd) noexcept
 Adds a pair of co-ordinates to this value.
 
Point translated (const ValueType xDelta, const ValueType yDelta) const noexcept
 Returns a point with a given offset from this one.
 
Point operator+ (const Point &other) const noexcept
 Adds two points together.
 
Pointoperator+= (const Point &other) noexcept
 Adds another point's co-ordinates to this one.
 
Point operator- (const Point &other) const noexcept
 Subtracts one points from another.
 
Pointoperator-= (const Point &other) noexcept
 Subtracts another point's co-ordinates to this one.
 
Point operator* (const ValueType multiplier) const noexcept
 Returns a point whose coordinates are multiplied by a given value.
 
Pointoperator*= (const ValueType multiplier) noexcept
 Multiplies the point's co-ordinates by a value.
 
Point operator/ (const ValueType divisor) const noexcept
 Returns a point whose coordinates are divided by a given value.
 
Pointoperator/= (const ValueType divisor) noexcept
 Divides the point's co-ordinates by a value.
 
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 (const Point &other) const noexcept
 Returns the straight-line distance between this point and another one.
 
FloatType getAngleToPoint (const Point &other) const noexcept
 Returns the angle from this point to another one.
 
Point< FloatTypegetPointOnCircumference (const float radius, const float angle) const noexcept
 Taking this point to be the centre of a circle, this returns a point on its circumference.
 
Point< FloatTypegetPointOnCircumference (const float radiusX, const float radiusY, const float angle) const noexcept
 Taking this point to be the centre of an ellipse, this returns a point on its circumference.
 
void applyTransform (const AffineTransform &transform) noexcept
 Uses a transform to change the point's co-ordinates.
 
Point transformedBy (const AffineTransform &transform) const noexcept
 Returns the position of this point, if it is transformed by a given AffineTransform.
 
FloatType getDotProduct (const Point &other) const noexcept
 Returns the dot-product of two points (x1 * x2 + y1 * y2).
 
Point< int > toInt () const noexcept
 Casts this point to a Point<int> object.
 
Point< float > toFloat () const noexcept
 Casts this point to a Point<float> object.
 
Point< double > toDouble () const noexcept
 Casts this point to a Point<double> object.
 
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.
 

Detailed Description

template<typename ValueType>
class Point< ValueType >

A pair of (x, y) co-ordinates.

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

See Also
Line, Path, AffineTransform

Member Typedef Documentation

template<typename ValueType>
typedef TypeHelpers::SmallestFloatType<ValueType>::type Point< ValueType >::FloatType

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

Constructor & Destructor Documentation

template<typename ValueType>
Point< ValueType >::Point ( )
noexcept
template<typename ValueType>
Point< ValueType >::Point ( const Point< ValueType > &  other)
noexcept

Creates a copy of another point.

template<typename ValueType>
Point< ValueType >::Point ( const ValueType  initialX,
const ValueType  initialY 
)
noexcept

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

template<typename ValueType>
Point< ValueType >::~Point ( )
noexcept

Destructor.

Member Function Documentation

template<typename ValueType>
Point& Point< ValueType >::operator= ( const Point< ValueType > &  other)
noexcept

Copies this point from another one.

template<typename ValueType>
bool Point< ValueType >::operator== ( const Point< ValueType > &  other) const
noexcept
template<typename ValueType>
bool Point< ValueType >::operator!= ( const Point< ValueType > &  other) const
noexcept
template<typename ValueType>
bool Point< ValueType >::isOrigin ( ) const
noexcept

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

template<typename ValueType>
ValueType Point< ValueType >::getX ( ) const
noexcept

Returns the point's x co-ordinate.

template<typename ValueType>
ValueType Point< ValueType >::getY ( ) const
noexcept

Returns the point's y co-ordinate.

template<typename ValueType>
void Point< ValueType >::setX ( const ValueType  newX)
noexcept

Sets the point's x co-ordinate.

template<typename ValueType>
void Point< ValueType >::setY ( const ValueType  newY)
noexcept

Sets the point's y co-ordinate.

template<typename ValueType>
Point Point< ValueType >::withX ( const ValueType  newX) const
noexcept

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

template<typename ValueType>
Point Point< ValueType >::withY ( const ValueType  newY) const
noexcept

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

template<typename ValueType>
void Point< ValueType >::setXY ( const ValueType  newX,
const ValueType  newY 
)
noexcept

Changes the point's x and y co-ordinates.

template<typename ValueType>
void Point< ValueType >::addXY ( const ValueType  xToAdd,
const ValueType  yToAdd 
)
noexcept

Adds a pair of co-ordinates to this value.

template<typename ValueType>
Point Point< ValueType >::translated ( const ValueType  xDelta,
const ValueType  yDelta 
) const
noexcept

Returns a point with a given offset from this one.

template<typename ValueType>
Point Point< ValueType >::operator+ ( const Point< ValueType > &  other) const
noexcept

Adds two points together.

template<typename ValueType>
Point& Point< ValueType >::operator+= ( const Point< ValueType > &  other)
noexcept

Adds another point's co-ordinates to this one.

template<typename ValueType>
Point Point< ValueType >::operator- ( const Point< ValueType > &  other) const
noexcept

Subtracts one points from another.

template<typename ValueType>
Point& Point< ValueType >::operator-= ( const Point< ValueType > &  other)
noexcept

Subtracts another point's co-ordinates to this one.

template<typename ValueType>
Point Point< ValueType >::operator* ( const ValueType  multiplier) const
noexcept

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

template<typename ValueType>
Point& Point< ValueType >::operator*= ( const ValueType  multiplier)
noexcept

Multiplies the point's co-ordinates by a value.

template<typename ValueType>
Point Point< ValueType >::operator/ ( const ValueType  divisor) const
noexcept

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

template<typename ValueType>
Point& Point< ValueType >::operator/= ( const ValueType  divisor)
noexcept

Divides the point's co-ordinates by a value.

template<typename ValueType>
Point Point< ValueType >::operator- ( ) const
noexcept

Returns the inverse of this point.

template<typename ValueType>
ValueType Point< ValueType >::getDistanceFromOrigin ( ) const
noexcept

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

template<typename ValueType>
ValueType Point< ValueType >::getDistanceFrom ( const Point< ValueType > &  other) const
noexcept

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

Referenced by Line< ValueType >::getDistanceFromPoint().

template<typename ValueType>
FloatType Point< ValueType >::getAngleToPoint ( const Point< ValueType > &  other) const
noexcept

Returns the angle from this point to another one.

The return value is the number of radians clockwise from the 12 o'clock direction, where this point is the centre and the other point is on the circumference.

template<typename ValueType>
Point<FloatType> Point< ValueType >::getPointOnCircumference ( const float  radius,
const float  angle 
) const
noexcept

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

Parameters
radiusthe radius of the circle.
anglethe angle of the point, in radians clockwise from the 12 o'clock position.
template<typename ValueType>
Point<FloatType> Point< ValueType >::getPointOnCircumference ( const float  radiusX,
const float  radiusY,
const float  angle 
) const
noexcept

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

Parameters
radiusXthe horizontal radius of the circle.
radiusYthe vertical radius of the circle.
anglethe angle of the point, in radians clockwise from the 12 o'clock position.
template<typename ValueType>
void Point< ValueType >::applyTransform ( const AffineTransform transform)
noexcept

Uses a transform to change the point's co-ordinates.

This will only compile if ValueType = float!

See Also
AffineTransform::transformPoint
template<typename ValueType>
Point Point< ValueType >::transformedBy ( const AffineTransform transform) const
noexcept

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

template<typename ValueType>
FloatType Point< ValueType >::getDotProduct ( const Point< ValueType > &  other) const
noexcept

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

template<typename ValueType>
Point<int> Point< ValueType >::toInt ( ) const
noexcept

Casts this point to a Point<int> object.

template<typename ValueType>
Point<float> Point< ValueType >::toFloat ( ) const
noexcept

Casts this point to a Point<float> object.

template<typename ValueType>
Point<double> Point< ValueType >::toDouble ( ) const
noexcept

Casts this point to a Point<double> object.

template<typename ValueType>
String Point< ValueType >::toString ( ) const

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

Member Data Documentation

template<typename ValueType>
ValueType Point< ValueType >::x
template<typename ValueType>
ValueType Point< ValueType >::y

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