Skia
2D Graphics Library
SkPoint Struct Reference

SkPoint holds two 32-bit floating point coordinates. More...

#include <SkPoint.h>

Public Member Functions

constexpr SkScalar x () const
 Returns x-axis value of SkPoint or vector. More...
 
constexpr SkScalar y () const
 Returns y-axis value of SkPoint or vector. More...
 
bool isZero () const
 Returns true if fX and fY are both zero. More...
 
void set (SkScalar x, SkScalar y)
 Sets fX to x and fY to y. More...
 
void iset (int32_t x, int32_t y)
 Sets fX to x and fY to y, promoting integers to SkScalar values. More...
 
void iset (const SkIPoint &p)
 Sets fX to p.fX and fY to p.fY, promoting integers to SkScalar values. More...
 
void setAbs (const SkPoint &pt)
 Sets fX to absolute value of pt.fX; and fY to absolute value of pt.fY. More...
 
void offset (SkScalar dx, SkScalar dy)
 Adds offset (dx, dy) to SkPoint. More...
 
SkScalar length () const
 Returns the Euclidean distance from origin, computed as: More...
 
SkScalar distanceToOrigin () const
 Returns the Euclidean distance from origin, computed as: More...
 
bool normalize ()
 Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY, if possible. More...
 
bool setNormalize (SkScalar x, SkScalar y)
 Sets vector to (x, y) scaled so length() returns one, and so that (fX, fY) is proportional to (x, y). More...
 
bool setLength (SkScalar length)
 Scales vector so that distanceToOrigin() returns length, if possible. More...
 
bool setLength (SkScalar x, SkScalar y, SkScalar length)
 Sets vector to (x, y) scaled to length, if possible. More...
 
void scale (SkScalar scale, SkPoint *dst) const
 Sets dst to SkPoint times scale. More...
 
void scale (SkScalar value)
 Scales SkPoint in place by scale. More...
 
void negate ()
 Changes the sign of fX and fY. More...
 
SkPoint operator- () const
 Returns SkPoint changing the signs of fX and fY. More...
 
void operator+= (const SkVector &v)
 Adds vector v to SkPoint. More...
 
void operator-= (const SkVector &v)
 Subtracts vector v from SkPoint. More...
 
SkPoint operator* (SkScalar scale) const
 Returns SkPoint multiplied by scale. More...
 
SkPointoperator*= (SkScalar scale)
 Multiplies SkPoint by scale. More...
 
bool isFinite () const
 Returns true if both fX and fY are measurable values. More...
 
bool equals (SkScalar x, SkScalar y) const
 Returns true if SkPoint is equivalent to SkPoint constructed from (x, y). More...
 
SkScalar cross (const SkVector &vec) const
 Returns the cross product of vector and vec. More...
 
SkScalar dot (const SkVector &vec) const
 Returns the dot product of vector and vector vec. More...
 

Static Public Member Functions

static constexpr SkPoint Make (SkScalar x, SkScalar y)
 Sets fX to x, fY to y. More...
 
static void Offset (SkPoint points[], int count, const SkVector &offset)
 Adds offset to each SkPoint in points array with count entries. More...
 
static void Offset (SkPoint points[], int count, SkScalar dx, SkScalar dy)
 Adds offset (dx, dy) to each SkPoint in points array of length count. More...
 
static SkScalar Length (SkScalar x, SkScalar y)
 Returns the Euclidean distance from origin, computed as: More...
 
static SkScalar Normalize (SkVector *vec)
 Scales (vec->fX, vec->fY) so that length() returns one, while preserving ratio of vec->fX to vec->fY, if possible. More...
 
static SkScalar Distance (const SkPoint &a, const SkPoint &b)
 Returns the Euclidean distance between a and b. More...
 
static SkScalar DotProduct (const SkVector &a, const SkVector &b)
 Returns the dot product of vector a and vector b. More...
 
static SkScalar CrossProduct (const SkVector &a, const SkVector &b)
 Returns the cross product of vector a and vector b. More...
 

Public Attributes

SkScalar fX
 x-axis value More...
 
SkScalar fY
 y-axis value More...
 

Friends

bool operator== (const SkPoint &a, const SkPoint &b)
 Returns true if a is equivalent to b. More...
 
bool operator!= (const SkPoint &a, const SkPoint &b)
 Returns true if a is not equivalent to b. More...
 
SkVector operator- (const SkPoint &a, const SkPoint &b)
 Returns vector from b to a, computed as (a.fX - b.fX, a.fY - b.fY). More...
 
SkPoint operator+ (const SkPoint &a, const SkVector &b)
 Returns SkPoint resulting from SkPoint a offset by vector b, computed as: (a.fX + b.fX, a.fY + b.fY). More...
 

Detailed Description

SkPoint holds two 32-bit floating point coordinates.

Member Function Documentation

◆ cross()

SkScalar SkPoint::cross ( const SkVector vec) const
inline

Returns the cross product of vector and vec.

Vector and vec form three-dimensional vectors with z-axis value equal to zero. The cross product is a three-dimensional vector with x-axis and y-axis values equal to zero. The cross product z-axis component is returned.

Parameters
vecright side of cross product
Returns
area spanned by vectors signed by angle direction

◆ CrossProduct()

static SkScalar SkPoint::CrossProduct ( const SkVector a,
const SkVector b 
)
inlinestatic

Returns the cross product of vector a and vector b.

a and b form three-dimensional vectors with z-axis value equal to zero. The cross product is a three-dimensional vector with x-axis and y-axis values equal to zero. The cross product z-axis component is returned.

Parameters
aleft side of cross product
bright side of cross product
Returns
area spanned by vectors signed by angle direction

◆ Distance()

static SkScalar SkPoint::Distance ( const SkPoint a,
const SkPoint b 
)
inlinestatic

Returns the Euclidean distance between a and b.

Parameters
aline end point
bline end point
Returns
straight-line distance from a to b

◆ distanceToOrigin()

SkScalar SkPoint::distanceToOrigin ( ) const
inline

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)

Returns
straight-line distance to origin

◆ dot()

SkScalar SkPoint::dot ( const SkVector vec) const
inline

Returns the dot product of vector and vector vec.

Parameters
vecright side of dot product
Returns
product of input magnitudes and cosine of the angle between them

◆ DotProduct()

static SkScalar SkPoint::DotProduct ( const SkVector a,
const SkVector b 
)
inlinestatic

Returns the dot product of vector a and vector b.

Parameters
aleft side of dot product
bright side of dot product
Returns
product of input magnitudes and cosine of the angle between them

◆ equals()

bool SkPoint::equals ( SkScalar  x,
SkScalar  y 
) const
inline

Returns true if SkPoint is equivalent to SkPoint constructed from (x, y).

Parameters
xvalue compared with fX
yvalue compared with fY
Returns
true if SkPoint equals (x, y)

◆ iset() [1/2]

void SkPoint::iset ( int32_t  x,
int32_t  y 
)
inline

Sets fX to x and fY to y, promoting integers to SkScalar values.

Assigning a large integer value directly to fX or fY may cause a compiler error, triggered by narrowing conversion of int to SkScalar. This safely casts x and y to avoid the error.

Parameters
xnew value for fX
ynew value for fY

◆ iset() [2/2]

void SkPoint::iset ( const SkIPoint p)
inline

Sets fX to p.fX and fY to p.fY, promoting integers to SkScalar values.

Assigning an SkIPoint containing a large integer value directly to fX or fY may cause a compiler error, triggered by narrowing conversion of int to SkScalar. This safely casts p.fX and p.fY to avoid the error.

Parameters
pSkIPoint members promoted to SkScalar

◆ isFinite()

bool SkPoint::isFinite ( ) const
inline

Returns true if both fX and fY are measurable values.

Returns
true for values other than infinities and NaN

◆ isZero()

bool SkPoint::isZero ( ) const
inline

Returns true if fX and fY are both zero.

Returns
true if fX is zero and fY is zero

◆ length()

SkScalar SkPoint::length ( ) const
inline

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)

Returns
straight-line distance to origin

◆ Length()

static SkScalar SkPoint::Length ( SkScalar  x,
SkScalar  y 
)
static

Returns the Euclidean distance from origin, computed as:

sqrt(x * x + y * y)

Parameters
xcomponent of length
ycomponent of length
Returns
straight-line distance to origin

example: https://fiddle.skia.org/c/@Point_Length

◆ Make()

static constexpr SkPoint SkPoint::Make ( SkScalar  x,
SkScalar  y 
)
inlinestatic

Sets fX to x, fY to y.

Used both to set SkPoint and vector.

Parameters
xSkScalar x-axis value of constructed SkPoint or vector
ySkScalar y-axis value of constructed SkPoint or vector
Returns
SkPoint (x, y)

◆ negate()

void SkPoint::negate ( )
inline

Changes the sign of fX and fY.

◆ normalize()

bool SkPoint::normalize ( )

Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY, if possible.

If prior length is nearly zero, sets vector to (0, 0) and returns false; otherwise returns true.

Returns
true if former length is not zero or nearly zero

example: https://fiddle.skia.org/c/@Point_normalize_2

◆ Normalize()

static SkScalar SkPoint::Normalize ( SkVector vec)
static

Scales (vec->fX, vec->fY) so that length() returns one, while preserving ratio of vec->fX to vec->fY, if possible.

If original length is nearly zero, sets vec to (0, 0) and returns zero; otherwise, returns length of vec before vec is scaled.

Returned prior length may be SK_ScalarInfinity if it can not be represented by SkScalar.

Note that normalize() is faster if prior length is not required.

Parameters
vecnormalized to unit length
Returns
original vec length

example: https://fiddle.skia.org/c/@Point_Normalize

◆ Offset() [1/2]

static void SkPoint::Offset ( SkPoint  points[],
int  count,
const SkVector offset 
)
inlinestatic

Adds offset to each SkPoint in points array with count entries.

Parameters
pointsSkPoint array
countentries in array
offsetvector added to points

◆ Offset() [2/2]

static void SkPoint::Offset ( SkPoint  points[],
int  count,
SkScalar  dx,
SkScalar  dy 
)
inlinestatic

Adds offset (dx, dy) to each SkPoint in points array of length count.

Parameters
pointsSkPoint array
countentries in array
dxadded to fX in points
dyadded to fY in points

◆ offset()

void SkPoint::offset ( SkScalar  dx,
SkScalar  dy 
)
inline

Adds offset (dx, dy) to SkPoint.

Parameters
dxadded to fX
dyadded to fY

◆ operator*()

SkPoint SkPoint::operator* ( SkScalar  scale) const
inline

Returns SkPoint multiplied by scale.

Parameters
scalescalar to multiply by
Returns
SkPoint as (fX * scale, fY * scale)

◆ operator*=()

SkPoint& SkPoint::operator*= ( SkScalar  scale)
inline

Multiplies SkPoint by scale.

Sets SkPoint to: (fX * scale, fY * scale).

Parameters
scalescalar to multiply by
Returns
reference to SkPoint

◆ operator+=()

void SkPoint::operator+= ( const SkVector v)
inline

Adds vector v to SkPoint.

Sets SkPoint to: (fX + v.fX, fY + v.fY).

Parameters
vvector to add

◆ operator-()

SkPoint SkPoint::operator- ( ) const
inline

Returns SkPoint changing the signs of fX and fY.

Returns
SkPoint as (-fX, -fY)

◆ operator-=()

void SkPoint::operator-= ( const SkVector v)
inline

Subtracts vector v from SkPoint.

Sets SkPoint to: (fX - v.fX, fY - v.fY).

Parameters
vvector to subtract

◆ scale() [1/2]

void SkPoint::scale ( SkScalar  scale,
SkPoint dst 
) const

Sets dst to SkPoint times scale.

dst may be SkPoint to modify SkPoint in place.

Parameters
scalefactor to multiply SkPoint by
dststorage for scaled SkPoint

example: https://fiddle.skia.org/c/@Point_scale

◆ scale() [2/2]

void SkPoint::scale ( SkScalar  value)
inline

Scales SkPoint in place by scale.

Parameters
valuefactor to multiply SkPoint by

◆ set()

void SkPoint::set ( SkScalar  x,
SkScalar  y 
)
inline

Sets fX to x and fY to y.

Parameters
xnew value for fX
ynew value for fY

◆ setAbs()

void SkPoint::setAbs ( const SkPoint pt)
inline

Sets fX to absolute value of pt.fX; and fY to absolute value of pt.fY.

Parameters
ptmembers providing magnitude for fX and fY

◆ setLength() [1/2]

bool SkPoint::setLength ( SkScalar  length)

Scales vector so that distanceToOrigin() returns length, if possible.

If former length is nearly zero, sets vector to (0, 0) and return false; otherwise returns true.

Parameters
lengthstraight-line distance to origin
Returns
true if former length is not zero or nearly zero

example: https://fiddle.skia.org/c/@Point_setLength

◆ setLength() [2/2]

bool SkPoint::setLength ( SkScalar  x,
SkScalar  y,
SkScalar  length 
)

Sets vector to (x, y) scaled to length, if possible.

If former length is nearly zero, sets vector to (0, 0) and return false; otherwise returns true.

Parameters
xproportional value for fX
yproportional value for fY
lengthstraight-line distance to origin
Returns
true if (x, y) length is not zero or nearly zero

example: https://fiddle.skia.org/c/@Point_setLength_2

◆ setNormalize()

bool SkPoint::setNormalize ( SkScalar  x,
SkScalar  y 
)

Sets vector to (x, y) scaled so length() returns one, and so that (fX, fY) is proportional to (x, y).

If (x, y) length is nearly zero, sets vector to (0, 0) and returns false; otherwise returns true.

Parameters
xproportional value for fX
yproportional value for fY
Returns
true if (x, y) length is not zero or nearly zero

example: https://fiddle.skia.org/c/@Point_setNormalize

◆ x()

constexpr SkScalar SkPoint::x ( ) const
inline

Returns x-axis value of SkPoint or vector.

Returns
fX

◆ y()

constexpr SkScalar SkPoint::y ( ) const
inline

Returns y-axis value of SkPoint or vector.

Returns
fY

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const SkPoint a,
const SkPoint b 
)
friend

Returns true if a is not equivalent to b.

Parameters
aSkPoint to compare
bSkPoint to compare
Returns
true if a.fX != b.fX or a.fY != b.fY

◆ operator+

SkPoint operator+ ( const SkPoint a,
const SkVector b 
)
friend

Returns SkPoint resulting from SkPoint a offset by vector b, computed as: (a.fX + b.fX, a.fY + b.fY).

Can also be used to offset SkPoint b by vector a, returning SkPoint. Can also be used to add vector to vector, returning vector.

Parameters
aSkPoint or vector to add to
bSkPoint or vector to add
Returns
SkPoint equal to a offset by b

◆ operator-

SkVector operator- ( const SkPoint a,
const SkPoint b 
)
friend

Returns vector from b to a, computed as (a.fX - b.fX, a.fY - b.fY).

Can also be used to subtract vector from SkPoint, returning SkPoint. Can also be used to subtract vector from vector, returning vector.

Parameters
aSkPoint to subtract from
bSkPoint to subtract
Returns
vector from b to a

◆ operator==

bool operator== ( const SkPoint a,
const SkPoint b 
)
friend

Returns true if a is equivalent to b.

Parameters
aSkPoint to compare
bSkPoint to compare
Returns
true if a.fX == b.fX and a.fY == b.fY

Member Data Documentation

◆ fX

SkScalar SkPoint::fX

x-axis value

◆ fY

SkScalar SkPoint::fY

y-axis value


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