Nutrient Web SDK

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

Class

Example

Create and update a point.

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

Default Value

{ x: 0, y: 0 }

Hierarchy

ReadonlyInheritableImmutableRecordPoint

Constructors

  • Parameters

    options{ x?: number; y?: number; [key: string]: unknown }
    Optional

Properties

x

Readonly
number

The x coordinate of the point.

Default Value

0

y

Readonly
number

The y coordinate of the point.

Default Value

0

Methods

  • Calculates the euclidean distance to another point.

    Parameters

    otherthis

    The other point to calculate the distance with.

    Returns

    number

    The distance between the two points.

    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
  • Rotates the point at the origin [0, 0].

    Parameters

    degnumber

    Returns

    this
  • 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

    sxnumber

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

    synumber
    Optional

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

    Returns

    this

    A new Point.

    Example

    const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
    point.scale(2); // => Point {x: 20, y: 20}
  • Translate all values of the point by a given Point.

    Parameters

    point{ x: number; y: number }

    A point that describes the translation distance.

    Returns

    this

    A new 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}
  • Translate the x value by a given number.

    Parameters

    txnumber

    A number to translate the x value.

    Returns

    this

    A new Point.

    Example

    const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
    point.translateX(5); // => Point {x: 15, y: 10}
  • Translate the y value by a given number.

    Parameters

    tynumber

    A number to translate the y value.

    Returns

    this

    A new Point.

    Example

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

Immutable Record API

24

asImmutable

Deprecated
  • Deprecated

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Build the value once, or use withMutations().

    See Also

    • Map#asImmutable

asMutable

Deprecated
  • Deprecated

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use withMutations().

    See Also

    • Map#asMutable

  • Returns a new instance of this Record type with all values set to their default values.

    Returns

    this
  • Returns a new instance of this Record type with the value for the specific key set to its default value.

    Type Parameters

    Kextends "x" | "y"

    Parameters

    keyK

    Returns

    this
  • Returns a new instance of this Record type with the value at the given key path removed.

    Also available as removeIn.

    Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Parameters

    otherunknown

    Returns

    boolean
  • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

    If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

    Type Parameters

    Kextends "x" | "y"

    Parameters

    keyK

    Returns

    { x: number; y: number }[K]
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    Optional

    Returns

    unknown
  • Parameters

    keyunknown

    Returns

    boolean
  • Parameters

    ...collectionsPartial<{ x: number; y: number }>[]

    Returns

    this
  • Parameters

    ...collections(Iterable<[string, unknown], any, any> | Partial<{ x: number; y: number }>)[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collections(Iterable<[string, unknown], any, any> | Partial<{ x: number; y: number }>)[]

    Returns

    this
  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections(Iterable<[string, unknown], any, any> | Partial<{ x: number; y: number }>)[]

    Returns

    this

mergeIn

Deprecated
  • Deprecated

    Parameters

    keyPathIterable<unknown>
    ...collections(Iterable<[string, unknown], any, any> | Partial<{ x: number; y: number }>)[]

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use update() followed by merge().

  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections(Iterable<[string, unknown], any, any> | Partial<{ x: number; y: number }>)[]

    Returns

    this

removeIn

Deprecated
  • Deprecated

    Parameters

    keyPathIterable<unknown>

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use deleteIn(), or update() followed by delete().

  • Type Parameters

    Kextends "x" | "y"

    Parameters

    keyK
    value{ x: number; y: number }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    valueunknown

    Returns

    this
  • Deeply converts this Record to equivalent native JavaScript Object.

    Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.

    Returns

    { x: number; y: number }
    • x: number

      The x coordinate of the point.

      Default Value

      0
    • y: number

      The y coordinate of the point.

      Default Value

      0
  • Shallowly converts this Record to equivalent native JavaScript Object.

    Returns

    { x: number; y: number }
    • x: number

      The x coordinate of the point.

      Default Value

      0
    • y: number

      The y coordinate of the point.

      Default Value

      0

toSeq

Deprecated
  • Deprecated

    Returns

    Keyed<string, unknown>

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use entries().

  • Type Parameters

    Kextends "x" | "y"

    Parameters

    keyK
    updater(value: { x: number; y: number }[K]) => { x: number; y: number }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    updater(value: unknown) => unknown

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown

    Returns

    this
  • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

    Parameters

    mutator(mutable: this) => unknown

    Returns

    this

    See Also

    • Map#withMutations