Class: Point

A point describes a 2D vector in space consisting of an x and y coordinate. Provided values are defined in same units used by the page, point units. Point units are only equal to pixels when zoom value is 1.

It is an Immutable.Record and thus can be updated using set(key, value), for example: point.set("x", 20).

Constructor

new PSPDFKit.Geometry.Point(args)

A 2D vector that describes a point in space.

Parameters:
Name Type Description
args object

An object used to initialize the Point. If x or y is omitted, 0 will be used instead.

Default Value:
  • { x: 0, y: 0 }
Example

Create and update a point

const point = new PSPDFKit.Geometry.Point({ x: 20, y: 30 });
point = point.set("y", 20);
point.y; // => 20

Extends

  • Immutable.Record

Members

Methods




Members

x: number

The x coordinate of the point.

Type:
  • number
Default Value:
  • 0

y: number

The y coordinate of the point.

Type:
  • number
Default Value:
  • 0

Methods

distance(other) → {number}

Calculates the euclidean distance to another point.

Parameters:
Name Type Description
other PSPDFKit.Geometry.Point

The other point to calculate the distance with.

Returns:

The distance between the two points.

Type
number
Example
var point1 = new PSPDFKit.Geometry.Point({ x: 10, y: 10 });
var point2 = new PSPDFKit.Geometry.Point({ x: 20, y: 10 });
point1.distance(point2); // => 10

scale(sx, synullable) → {PSPDFKit.Geometry.Point}

Scales x and y by the given sx and sy factor. If only sx is set and sy not defined, it will scale x and y by sx.

Parameters:
Name Type Attributes Description
sx number

Scale value for the x coordinate. If sy is not set, this scale will also be applied to y.

sy number <nullable>

If empty, it will scale y with sx as well.

Returns:

A new Point.

Type
PSPDFKit.Geometry.Point
Example
const point = new PSPDFKit.Geometry.Point({ x: 10, y: 10 });
point.scale(2); // => Point {x: 20, y: 20}

translate(point) → {PSPDFKit.Geometry.Point}

Translate all values of the point by a given Point.

Parameters:
Name Type Description
point PSPDFKit.Geometry.Point

A point that describes the translation distance.

Returns:

A new Point.

Type
PSPDFKit.Geometry.Point
Example
const point = new PSPDFKit.Geometry.Point({ x: 10, y: 10 });
point.translate(new PSPDFKit.Geometry.Point({ x: 5, y: -5 })); // => Point {x: 15, y: 5}

translateX(tx) → {PSPDFKit.Geometry.Point}

Translate the x value by a given number.

Parameters:
Name Type Description
tx number

A number to translate the x value.

Returns:

A new Point.

Type
PSPDFKit.Geometry.Point
Example
const point = new PSPDFKit.Geometry.Point({ x: 10, y: 10 });
point.translateX(5); // => Point {x: 15, y: 10}

translateY(ty) → {PSPDFKit.Geometry.Point}

Translate the y value by a given number.

Parameters:
Name Type Description
ty number

A number to translate the y value.

Returns:

A new Point.

Type
PSPDFKit.Geometry.Point
Example
const point = new PSPDFKit.Geometry.Point({ x: 10, y: 10 });
point.translateY(5); // => Point {x: 10, y: 15}