Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
SkPoint Struct Reference

#include <SkPoint_impl.h>

Public Member Functions

constexpr float x () const
 
constexpr float y () const
 
bool isZero () const
 
void set (float x, float y)
 
void iset (int32_t x, int32_t y)
 
void iset (const SkIPoint &p)
 
void setAbs (const SkPoint &pt)
 
void offset (float dx, float dy)
 
float length () const
 
float distanceToOrigin () const
 
bool normalize ()
 
bool setNormalize (float x, float y)
 
bool setLength (float length)
 
bool setLength (float x, float y, float length)
 
void scale (float scale, SkPoint *dst) const
 
void scale (float value)
 
void negate ()
 
SkPoint operator- () const
 
void operator+= (const SkVector &v)
 
void operator-= (const SkVector &v)
 
SkPoint operator* (float scale) const
 
SkPointoperator*= (float scale)
 
bool isFinite () const
 
bool equals (float x, float y) const
 
float cross (const SkVector &vec) const
 
float dot (const SkVector &vec) const
 

Static Public Member Functions

static constexpr SkPoint Make (float x, float y)
 
static void Offset (SkPoint points[], int count, const SkVector &offset)
 
static void Offset (SkPoint points[], int count, float dx, float dy)
 
static float Length (float x, float y)
 
static float Normalize (SkVector *vec)
 
static float Distance (const SkPoint &a, const SkPoint &b)
 
static float DotProduct (const SkVector &a, const SkVector &b)
 
static float CrossProduct (const SkVector &a, const SkVector &b)
 

Public Attributes

float fX
 x-axis value
 
float fY
 y-axis value
 

Friends

bool operator== (const SkPoint &a, const SkPoint &b)
 
bool operator!= (const SkPoint &a, const SkPoint &b)
 
SkVector operator- (const SkPoint &a, const SkPoint &b)
 
SkPoint operator+ (const SkPoint &a, const SkVector &b)
 

Detailed Description

SkPoint holds two 32-bit floating point coordinates.

Definition at line 163 of file SkPoint_impl.h.

Member Function Documentation

◆ cross()

float 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

Definition at line 545 of file SkPoint_impl.h.

545 {
546 return CrossProduct(*this, vec);
547 }
static float CrossProduct(const SkVector &a, const SkVector &b)

◆ CrossProduct()

static float 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

Definition at line 532 of file SkPoint_impl.h.

532 {
533 return a.fX * b.fY - a.fY * b.fX;
534 }
static bool b
struct MyStruct a[10]

◆ Distance()

static float 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

Definition at line 508 of file SkPoint_impl.h.

508 {
509 return Length(a.fX - b.fX, a.fY - b.fY);
510 }
static float Length(float x, float y)
Definition SkPoint.cpp:79

◆ distanceToOrigin()

float SkPoint::distanceToOrigin ( ) const
inline

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)
Returns
straight-line distance to origin

Definition at line 292 of file SkPoint_impl.h.

292{ return this->length(); }
float length() const

◆ dot()

float 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

Definition at line 554 of file SkPoint_impl.h.

554 {
555 return DotProduct(*this, vec);
556 }
static float DotProduct(const SkVector &a, const SkVector &b)

◆ DotProduct()

static float 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

Definition at line 518 of file SkPoint_impl.h.

518 {
519 return a.fX * b.fX + a.fY * b.fY;
520 }

◆ equals()

bool SkPoint::equals ( float  x,
float  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)

Definition at line 422 of file SkPoint_impl.h.

422 {
423 return fX == x && fY == y;
424 }
float fX
x-axis value
float fY
y-axis value
constexpr float y() const
constexpr float x() const

◆ iset() [1/2]

void SkPoint::iset ( const SkIPoint p)
inline

Sets fX to p.fX and fY to p.fY, promoting integers to float 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 float. This safely casts p.fX and p.fY to avoid the error.

Parameters
pSkIPoint members promoted to float

Definition at line 227 of file SkPoint_impl.h.

227 {
228 fX = static_cast<float>(p.fX);
229 fY = static_cast<float>(p.fY);
230 }

◆ iset() [2/2]

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

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

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

Parameters
xnew value for fX
ynew value for fY

Definition at line 214 of file SkPoint_impl.h.

214 {
215 fX = static_cast<float>(x);
216 fY = static_cast<float>(y);
217 }

◆ 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

Definition at line 412 of file SkPoint_impl.h.

412 {
413 return SkIsFinite(fX, fY);
414 }
static bool SkIsFinite(T x, Pack... values)

◆ 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

Definition at line 193 of file SkPoint_impl.h.

193{ return (0 == fX) & (0 == fY); }

◆ length()

float SkPoint::length ( ) const
inline

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)
Returns
straight-line distance to origin

Definition at line 282 of file SkPoint_impl.h.

282{ return SkPoint::Length(fX, fY); }

◆ Length()

float SkPoint::Length ( float  x,
float  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

Definition at line 79 of file SkPoint.cpp.

79 {
80 float mag2 = dx * dx + dy * dy;
81 if (SkIsFinite(mag2)) {
82 return std::sqrt(mag2);
83 } else {
84 double xx = dx;
85 double yy = dy;
86 return sk_double_to_float(sqrt(xx * xx + yy * yy));
87 }
88}
static constexpr float sk_double_to_float(double x)
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition SkRecords.h:208
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706

◆ Make()

static constexpr SkPoint SkPoint::Make ( float  x,
float  y 
)
inlinestaticconstexpr

Sets fX to x, fY to y. Used both to set SkPoint and vector.

Parameters
xfloat x-axis value of constructed SkPoint or vector
yfloat y-axis value of constructed SkPoint or vector
Returns
SkPoint (x, y)

Definition at line 173 of file SkPoint_impl.h.

173 {
174 return {x, y};
175 }

◆ negate()

void SkPoint::negate ( )
inline

Changes the sign of fX and fY.

Definition at line 357 of file SkPoint_impl.h.

357 {
358 fX = -fX;
359 fY = -fY;
360 }

◆ 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

Definition at line 22 of file SkPoint.cpp.

22 {
23 return this->setLength(fX, fY, 1);
24}
#define setLength(p, len)

◆ Normalize()

float 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 INFINITY if it can not be represented by float.

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

Definition at line 71 of file SkPoint.cpp.

71 {
72 float mag;
73 if (set_point_length<false>(pt, pt->fX, pt->fY, 1.0f, &mag)) {
74 return mag;
75 }
76 return 0;
77}

◆ offset()

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

Adds offset (dx, dy) to SkPoint.

Parameters
dxadded to fX
dyadded to fY

Definition at line 269 of file SkPoint_impl.h.

269 {
270 fX += dx;
271 fY += dy;
272 }

◆ 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

Definition at line 247 of file SkPoint_impl.h.

247 {
248 Offset(points, count, offset.fX, offset.fY);
249 }
int count
static const int points[]
Point offset
static void Offset(SkPoint points[], int count, const SkVector &offset)

◆ Offset() [2/2]

static void SkPoint::Offset ( SkPoint  points[],
int  count,
float  dx,
float  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

Definition at line 258 of file SkPoint_impl.h.

258 {
259 for (int i = 0; i < count; ++i) {
260 points[i].offset(dx, dy);
261 }
262 }

◆ operator*()

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

Returns SkPoint multiplied by scale.

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

Definition at line 393 of file SkPoint_impl.h.

393 {
394 return {fX * scale, fY * scale};
395 }
const Scalar scale

◆ operator*=()

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

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

Parameters
scalefloat to multiply by
Returns
reference to SkPoint

Definition at line 402 of file SkPoint_impl.h.

402 {
403 fX *= scale;
404 fY *= scale;
405 return *this;
406 }

◆ 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

Definition at line 374 of file SkPoint_impl.h.

374 {
375 fX += v.fX;
376 fY += v.fY;
377 }

◆ operator-()

SkPoint SkPoint::operator- ( ) const
inline

Returns SkPoint changing the signs of fX and fY.

Returns
SkPoint as (-fX, -fY)

Definition at line 366 of file SkPoint_impl.h.

366 {
367 return {-fX, -fY};
368 }

◆ 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

Definition at line 383 of file SkPoint_impl.h.

383 {
384 fX -= v.fX;
385 fY -= v.fY;
386 }

◆ scale() [1/2]

void SkPoint::scale ( float  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

Definition at line 17 of file SkPoint.cpp.

17 {
18 SkASSERT(dst);
19 dst->set(fX * scale, fY * scale);
20}
#define SkASSERT(cond)
Definition SkAssert.h:116
dst
Definition cp.py:12

◆ scale() [2/2]

void SkPoint::scale ( float  value)
inline

Scales SkPoint in place by scale.

Parameters
valuefactor to multiply SkPoint by

Definition at line 353 of file SkPoint_impl.h.

353{ this->scale(value, this); }

◆ set()

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

Sets fX to x and fY to y.

Parameters
xnew value for fX
ynew value for fY

Definition at line 200 of file SkPoint_impl.h.

200 {
201 fX = x;
202 fY = y;
203 }

◆ 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

Definition at line 236 of file SkPoint_impl.h.

236 {
237 fX = std::abs(pt.fX);
238 fY = std::abs(pt.fY);
239 }

◆ setLength() [1/2]

bool SkPoint::setLength ( float  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

Definition at line 30 of file SkPoint.cpp.

30 {
31 return this->setLength(fX, fY, length);
32}

◆ setLength() [2/2]

bool SkPoint::setLength ( float  x,
float  y,
float  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

Definition at line 90 of file SkPoint.cpp.

90 {
91 return set_point_length<false>(this, x, y, length);
92}

◆ setNormalize()

bool SkPoint::setNormalize ( float  x,
float  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

Definition at line 26 of file SkPoint.cpp.

26 {
27 return this->setLength(x, y, 1);
28}

◆ x()

constexpr float SkPoint::x ( ) const
inlineconstexpr

Returns x-axis value of SkPoint or vector.

Returns
fX

Definition at line 181 of file SkPoint_impl.h.

181{ return fX; }

◆ y()

constexpr float SkPoint::y ( ) const
inlineconstexpr

Returns y-axis value of SkPoint or vector.

Returns
fY

Definition at line 187 of file SkPoint_impl.h.

187{ return fY; }

Friends And Related Symbol 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

Definition at line 442 of file SkPoint_impl.h.

442 {
443 return a.fX != b.fX || a.fY != b.fY;
444 }

◆ 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

Definition at line 469 of file SkPoint_impl.h.

469 {
470 return {a.fX + b.fX, a.fY + b.fY};
471 }

◆ 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

Definition at line 455 of file SkPoint_impl.h.

455 {
456 return {a.fX - b.fX, a.fY - b.fY};
457 }

◆ 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

Definition at line 432 of file SkPoint_impl.h.

432 {
433 return a.fX == b.fX && a.fY == b.fY;
434 }

Member Data Documentation

◆ fX

float SkPoint::fX

x-axis value

Definition at line 164 of file SkPoint_impl.h.

◆ fY

float SkPoint::fY

y-axis value

Definition at line 165 of file SkPoint_impl.h.


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