Point

class Point

Point holds two 32-bit floating point coordinates.

Example:

point = skia.Point(0.0, 0.0)
point = skia.Point((0.0, 0.0))  # Convert from tuple
print(point.fX, point.fY)
point + (1, 1)   # Add offset
point - (0, 0)   # Subtract offset
point * 2.0      # Scale
x, y = tuple(point)  # Convert to tuple

Methods

CrossProduct

Returns the cross product of vector a and vector b.

Distance

Returns the Euclidean distance between a and b.

DotProduct

Returns the dot product of vector a and vector b.

Length

Returns the Euclidean distance from origin, computed as:

Make

Sets fX to x, fY to y.

Normalize

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

Offset

Overloaded function.

__init__

Overloaded function.

cross

Returns the cross product of vector and vec.

distanceToOrigin

Returns the Euclidean distance from origin, computed as:

dot

Returns the dot product of vector and vector vec.

equals

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

isFinite

Returns true if both fX and fY are measurable values.

isZero

Returns true if fX and fY are both zero.

iset

Overloaded function.

length

Returns the Euclidean distance from origin, computed as:

negate

Changes the sign of fX and fY.

normalize

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

offset

Adds offset (dx, dy) to Point.

scale

Sets dst to Point times scale.

set

Sets fX to x and fY to y.

setAbs

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

setLength

Overloaded function.

setNormalize

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

x

Returns x-axis value of Point or vector.

y

Returns y-axis value of Point or vector.

Attributes

fX

x-axis value

fY

y-axis value

Methods

static Point.CrossProduct(a: skia.Point, b: skia.Point) float

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:
  • a – left side of cross product

  • b – right side of cross product

Returns:

area spanned by vectors signed by angle direction

static Point.Distance(a: skia.Point, b: skia.Point) float

Returns the Euclidean distance between a and b.

Parameters:
  • a – line end point

  • b – line end point

Returns:

straight-line distance from a to b

static Point.DotProduct(a: skia.Point, b: skia.Point) float

Returns the dot product of vector a and vector b.

Parameters:
  • a – left side of dot product

  • b – right side of dot product

Returns:

product of input magnitudes and cosine of the angle between them

static Point.Length(x: float, y: float) float

Returns the Euclidean distance from origin, computed as:

sqrt(x * x + y * y)

Parameters:
  • x – component of length

  • y – component of length

Returns:

straight-line distance to origin

static Point.Make(x: float, y: float) skia.Point

Sets fX to x, fY to y.

Used both to set Point and vector.

Parameters:
  • x – Scalar x-axis value of constructed Point or vector

  • y – Scalar y-axis value of constructed Point or vector

Returns:

Point (x, y)

static Point.Normalize(vec: skia.Point) float

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

Returns:

original vec length

static Point.Offset(*args, **kwargs)

Overloaded function.

  1. Offset(points: std::vector<SkPoint, std::allocator<SkPoint> >, offset: skia.Point) -> std::vector<SkPoint, std::allocator<SkPoint> >

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

    points:

    Point array

    offset:

    vector added to points

    return:

    Point array applied offset

  2. Offset(points: std::vector<SkPoint, std::allocator<SkPoint> >, dx: float, dy: float) -> std::vector<SkPoint, std::allocator<SkPoint> >

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

    points:

    Point array

    dx:

    added to fX in points

    dy:

    added to fY in points

Point.__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: skia.Point, x: float, y: float) -> None

    Sets fX to x, fY to y.

    Used both to set Point and vector.

    param float x:

    Scalar x-axis value of constructed Point or vector

    param float y:

    Scalar y-axis value of constructed Point or vector

    return:

    Point (x, y)

  2. __init__(self: skia.Point, ipoint: skia.IPoint) -> None

  3. __init__(self: skia.Point, t: tuple) -> None

Point.cross(self: skia.Point, vec: skia.Point) float

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:

vec – right side of cross product

Returns:

area spanned by vectors signed by angle direction

Point.distanceToOrigin(self: skia.Point) float

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)

Returns:

straight-line distance to origin

Point.dot(self: skia.Point, vec: skia.Point) float

Returns the dot product of vector and vector vec.

Parameters:

vec – right side of dot product

Returns:

product of input magnitudes and cosine of the angle between them

Point.equals(self: skia.Point, x: float, y: float) bool

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

Parameters:
  • x – value compared with fX

  • y – value compared with fY

Returns:

true if Point equals (x, y)

Point.isFinite(self: skia.Point) bool

Returns true if both fX and fY are measurable values.

Returns:

true for values other than infinities and NaN

Point.isZero(self: skia.Point) bool

Returns true if fX and fY are both zero.

Returns:

true if fX is zero and fY is zero

Point.iset(*args, **kwargs)

Overloaded function.

  1. iset(self: skia.Point, x: int, y: int) -> None

    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.

    x:

    new value for fX

    y:

    new value for fY

  2. iset(self: skia.Point, p: skia.IPoint) -> None

    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.

    p:

    IPoint members promoted to SkScalar

Point.length(self: skia.Point) float

Returns the Euclidean distance from origin, computed as:

sqrt(fX * fX + fY * fY)

Returns:

straight-line distance to origin

Point.negate(self: skia.Point) None

Changes the sign of fX and fY.

Point.normalize(self: skia.Point) bool

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

Point.offset(self: skia.Point, dx: float, dy: float) None

Adds offset (dx, dy) to Point.

Parameters:
  • dx – added to fX

  • dy – added to fY

Point.scale(self: skia.Point, scale: float) skia.Point

Sets dst to Point times scale.

dst may be Point to modify Point in place.

It is also possible to use operators:

p * scale
p *= scale  # in-place
Parameters:

scale – factor to multiply Point by

Point.set(self: skia.Point, x: float, y: float) None

Sets fX to x and fY to y.

Parameters:
  • x – new value for fX

  • y – new value for fY

Point.setAbs(self: skia.Point, pt: skia.Point) None

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

Point.setLength(*args, **kwargs)

Overloaded function.

  1. setLength(self: skia.Point, length: float) -> bool

    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.

    length:

    straight-line distance to origin

    return:

    true if former length is not zero or nearly zero

  2. setLength(self: skia.Point, x: float, y: float, length: float) -> bool

    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.

    x:

    proportional value for fX

    y:

    proportional value for fY

    length:

    straight-line distance to origin

    return:

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

Point.setNormalize(self: skia.Point, x: float, y: float) bool

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

Returns:

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

Point.x(self: skia.Point) float

Returns x-axis value of Point or vector.

Point.y(self: skia.Point) float

Returns y-axis value of Point or vector.

Attributes

Point.fX

x-axis value

Point.fY

y-axis value