skia2/site/user/api/SkPoint_Reference.md
Cary Clark 2dc84ad3ef working on global enum and image info
Added global enum support. That exposed one
big hole in bookmaker: The topic overview
should not be in the class or struct if
the topic includes multiple objects, which
is the case for SkImageInfo and enums like
SkColorType.

This straightens that out, and then used that
knowledge to strengthen the topics in
SkRect as a test. Now SkRect has more
groups of methods, and can expose and link
to sets of methods with the same name.

This work also is getting ready for tightening
SeeAlso data, to be checked as part of the
bots' tasks soon.

Also, remove links from markup for lowercase
method names unless the reference has
trailing parentheses.

TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=98782
Bug: skia:6898
Change-Id: I35419c9789da17e272047bf7b9c95b1cf44bb7fe
Reviewed-on: https://skia-review.googlesource.com/98782
Commit-Queue: Cary Clark <caryclark@google.com>
Reviewed-by: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@google.com>
2018-01-26 18:22:10 +00:00

43 KiB

SkPoint Reference

Point

Struct SkPoint

Overview

Subtopics

topics description

Constructors

name description
Make Constructs from SkScalar inputs.

Operators

name description
SkPoint operator*(SkScalar scale) const Returns Point multiplied by scale.
SkPoint operator+(const SkPoint& a, const SkVector& b) Returns Point offset by Vector.
SkPoint operator-() const Reverses sign of Point.
SkPoint& operator*=(SkScalar scale) Multiplies Point by scale factor.
SkVector operator-(const SkPoint& a, const SkPoint& b) Returns Vector between Points.
bool operator!=(const SkPoint& a, const SkPoint& b) Returns true if Point are unequal.
bool operator==(const SkPoint& a, const SkPoint& b) Returns true if Point are equal.
void operator+=(const SkVector& v) Adds Vector to Point.
void operator-=(const SkVector& v) Subtracts Vector from Point.

Member Functions

name description
CrossProduct Returns cross product.
Distance Returns straight-line distance between points.
DotProduct Returns dot product.
Length Returns straight-line distance to origin.
Make Constructs from SkScalar inputs.
Normalize Sets length to one, and returns prior length.
Offset Translates Point array.
cross Returns cross product.
distanceToOrigin Returns straight-line distance to origin.
dot Returns dot product.
equals Returns true if Points are equal.
isFinite Returns true if no member is infinite or NaN.
isZero Returns true if both members equal zero.
iset Sets to integer input.
length Returns straight-line distance to origin.
negate Reverses the sign of both members.
normalize Sets length to one, preserving direction.
offset Translates Point.
scale Multiplies Point by scale factor.
set Sets to SkScalar input.
setAbs Sets sign of both members to positive.
setLength Sets straight-line distance to origin.
setNormalize Sets length to one, in direction of (x, y).
x Returns fX.
y Returns fY.

SkScalar fX

x-axis value used by both Point and Vector. May contain any value, including infinities and NaN.

SkScalar fY

y-axis value used by both Point and Vector. May contain any value, including infinities and NaN.

Make

static constexpr SkPoint Make(SkScalar x, SkScalar y)

Sets fX to x, fY to y. Used both to set Point and Vector.

Parameters

x SkScalar x-axis value of constructed Point or Vector
y SkScalar y-axis value of constructed Point or Vector

Return Value

Point (x, y)

Example

Example Output

all equal

See Also

set iset[2] SkIPoint::Make


x

SkScalar x() const

Returns x-axis value of Point or Vector.

Return Value

fX

Example

Example Output

pt1.fX == pt1.x()

See Also

y SkIPoint::x()


y

SkScalar y() const

Returns y-axis value of Point or Vector.

Return Value

fY

Example

Example Output

pt1.fY == pt1.y()

See Also

x SkIPoint::y()


isZero

bool isZero() const

Returns true if fX and fY are both zero.

Return Value

true if fX is zero and fY is zero

Example

Example Output

pt.fX=+0 pt.fY=-0
pt.isZero() == true

See Also

isFinite SkIPoint::isZero


set

void set(SkScalar x, SkScalar y)

Sets fX to x and fY to y.

Parameters

x new value for fX
y new value for fY

Example

Example Output

pt1 == pt2

See Also

iset[2] Make


iset

void iset(int32_t x, int32_t y)

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

x new value for fX
y new value for fY

Example

See Also

set Make SkIPoint::set


void iset(const SkIPoint& p)

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

Assigning an IPoint 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

p IPoint members promoted to SkScalar

Example

Example Output

iPt: -2147483647, 2147483647
fPt: -2.14748e+09, 2.14748e+09

See Also

set Make SkIPoint::set


setAbs

void setAbs(const SkPoint& pt)

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

Parameters

pt members providing magnitude for fX and fY

Example

Example Output

pt: 0, -0  abs: 0, 0
pt: -1, -2  abs: 1, 2
pt: inf, -inf  abs: inf, inf
pt: nan, -nan  abs: nan, nan

See Also

set Make negate


Offset

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

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

Parameters

points Point array
count entries in array
offset Vector added to points

Example

See Also

offset operator+=(const SkVector& v)


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

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

Parameters

points Point array
count entries in array
dx added to fX in points
dy added to fY in points

Example

See Also

offset operator+=(const SkVector& v)


offset

void offset(SkScalar dx, SkScalar dy)

Adds offset (dx, dy) to Point.

Parameters

dx added to fX
dy added to fY

Example

See Also

Offset[2] operator+=(const SkVector& v)


length

SkScalar length() const

Returns the Euclidean_Distance from origin, computed as:

sqrt(fX * fX + fY * fY)

.

Return Value

straight-line distance to origin

Example

See Also

distanceToOrigin Length setLength[2] Distance


distanceToOrigin

SkScalar distanceToOrigin() const

Returns the Euclidean_Distance from origin, computed as:

sqrt(fX * fX + fY * fY)

.

Return Value

straight-line distance to origin

Example

See Also

length Length setLength[2] Distance


normalize

bool 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.

Return Value

true if former length is not zero or nearly zero

Example

See Also

Normalize setLength[2] length Length


setNormalize

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). If (x, y) length is nearly zero, sets Vector to (0, 0) and returns false; otherwise returns true.

Parameters

x proportional value for fX
y proportional value for fY

Return Value

true if (x, y) length is not zero or nearly zero

Example

See Also

normalize setLength[2]


setLength

bool 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

length straight-line distance to origin

Return Value

true if former length is not zero or nearly zero

Example

See Also

length Length setNormalize setAbs


bool 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

x proportional value for fX
y proportional value for fY
length straight-line distance to origin

Return Value

true if (x, y) length is not zero or nearly zero

Example

See Also

length Length setNormalize setAbs


scale

void scale(SkScalar scale, SkPoint* dst) const

Sets dst to Point times scale. dst may be Point to modify Point in place.

Parameters

scale factor to multiply Point by
dst storage for scaled Point

Example

See Also

operator*(SkScalar scale) const operator*=(SkScalar scale) setLength[2]


void scale(SkScalar value)

Scales Point in place by scale.

Parameters

value factor to multiply Point by

Example

See Also

operator*(SkScalar scale) const operator*=(SkScalar scale) setLength[2]


negate

void negate()

Changes the sign of fX and fY.

Example

Example Output

pt: 0, -0  negate: -0, 0
pt: -1, -2  negate: 1, 2
pt: inf, -inf  negate: -inf, inf
pt: nan, -nan  negate: -nan, nan

See Also

operator-() const setAbs


operator-

SkPoint operator-() _const

Returns Point changing the signs of fX and fY.

Return Value

Point as (-fX, -fY)

Example

Example Output

pt: 0, -0  negate: -0, 0
pt: -1, -2  negate: 1, 2
pt: inf, -inf  negate: -inf, inf
pt: nan, -nan  negate: -nan, nan

See Also

negate operator-(const SkPoint& a, const SkPoint& b) operator-=(const SkVector& v) SkIPoint::operator-() const


operator+=

void operator+=(const SkVector& v)

Adds Vector v to Point. Sets Point to: (fX + v.fX, fY + v.fY).

Parameters

v Vector to add

Example

See Also

offset operator+(const SkPoint& a, const SkVector& b) SkIPoint::operator+=(const SkIVector& v)


operator-=

void operator-=(const SkVector& v)

Subtracts Vector v from Point. Sets Point to: (fX - v.fX, fY - v.fY).

Parameters

v Vector to subtract

Example

See Also

offset operator-(const SkPoint& a, const SkPoint& b) SkIPoint::operator-=(const SkIVector& v)


operator*

SkPoint operator*(SkScalar scale) _const

Returns Point multiplied by scale.

Parameters

scale Scalar to multiply by

Return Value

Point as (fX * scale, fY * scale)

Example

See Also

operator*=(SkScalar scale) scale[2] setLength[2] setNormalize


operator*=

SkPoint& operator*=(SkScalar scale)

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

Parameters

scale Scalar to multiply by

Return Value

reference to Point

Example

See Also

operator*(SkScalar scale) const scale[2] setLength[2] setNormalize


isFinite

bool isFinite() const

Returns true if both fX and fY are measurable values.

Return Value

true for values other than infinities and NaN

Example

Example Output

pt: 0, -0  finite: true
pt: -1, -2  finite: true
pt: inf, 1  finite: false
pt: nan, -1  finite: false

See Also

SkRect::isFinite SkPath::isFinite


equals

bool equals(SkScalar x, SkScalar y) const

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

Parameters

x value compared with fX
y value compared with fY

Return Value

true if Point equals (x, y)

Example

Example Output

pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt

See Also

operator==(const SkPoint& a, const SkPoint& b)


operator==

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

Returns true if a is equivalent to b.

Parameters

a Point to compare
b Point to compare

Return Value

true if a.fX == b.fX and a.fY == b.fY

Example

Example Output

pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt

See Also

equals operator!=(const SkPoint& a, const SkPoint& b)


operator!=

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

Returns true if a is not equivalent to b.

Parameters

a Point to compare
b Point to compare

Return Value

true if a.fX != b.fX or a.fY != b.fY

Example

Example Output

pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt

See Also

operator==(const SkPoint& a, const SkPoint& b) equals


operator-

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

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

Can also be used to subtract Vector from Point, returning Point. Can also be used to subtract Vector from Vector, returning Vector.

Parameters

a Point to subtract from
b Point to subtract

Return Value

Vector from b to a

Example

See Also

operator-=(const SkVector& v) offset


operator+

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

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

Can also be used to offset Point b by Vector a, returning Point. Can also be used to add Vector to Vector, returning Vector.

Parameters

a Point or Vector to add to
b Point or Vector to add

Return Value

Point equal to a offset by b

Example

See Also

operator+=(const SkVector& v) offset


Length

static SkScalar Length(SkScalar x, SkScalar y)

Returns the Euclidean_Distance from origin, computed as:

sqrt(x * x + y * y)

.

Parameters

x component of length
y component of length

Return Value

straight-line distance to origin

Example

See Also

length Distance setLength[2]


Normalize

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

vec normalized to unit length

Return Value

original vec length

Example

See Also

normalize setLength[2] Length


Distance

static SkScalar Distance(const SkPoint& a, const SkPoint& b)

Returns the Euclidean_Distance between a and b.

Parameters

a line end point
b line end point

Return Value

straight-line distance from a to b

Example

See Also

length setLength[2]


DotProduct

static SkScalar DotProduct(const SkVector& a, const SkVector& b)

Returns the dot product of Vector a and Vector b.

Parameters

a left side of dot product
b right side of dot product

Return Value

product of input magnitudes and cosine of the angle between them

Example

See Also

dot CrossProduct


CrossProduct

static SkScalar CrossProduct(const SkVector& a, const SkVector& b)

Returns the cross product of Vector a and Vector b.

a and b form three-dimensional vectors with z equal to zero. The cross product is a three-dimensional vector with x and y equal to zero. The cross product z term equals the returned value.

Parameters

a left side of cross product
b right side of cross product

Return Value

area spanned by Vectors signed by angle direction

Example

See Also

cross DotProduct


cross

SkScalar cross(const SkVector& vec) const

Returns the cross product of Vector and vec.

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

Parameters

vec right side of cross product

Return Value

area spanned by Vectors signed by angle direction

Example

See Also

CrossProduct dot


dot

SkScalar dot(const SkVector& vec) const

Returns the dot product of Vector and Vector vec.

Parameters

vec right side of dot product

Return Value

product of input magnitudes and cosine of the angle between them

Example

See Also

DotProduct cross


Vector