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 NutrientViewer.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 NutrientViewer.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 NutrientViewer.Geometry.Point

The other point to calculate the distance with.

Returns:

The distance between the two points.

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

scale(sx, synullable) → {NutrientViewer.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
NutrientViewer.Geometry.Point
Example
const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
point.scale(2); // => Point {x: 20, y: 20}

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

Translate all values of the point by a given Point.

Parameters:
Name Type Description
point NutrientViewer.Geometry.Point

A point that describes the translation distance.

Returns:

A new Point.

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

translateX(tx) → {NutrientViewer.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
NutrientViewer.Geometry.Point
Example
const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
point.translateX(5); // => Point {x: 15, y: 10}

translateY(ty) → {NutrientViewer.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
NutrientViewer.Geometry.Point
Example
const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
point.translateY(5); // => Point {x: 10, y: 15}