Example
Create and update a point
const point = new DrawingPoint({
x: 20,
y: 30,
intensity: 0.3
});
point.intensity; // => 0.3
Default Value
{ x: 0, y: 0, intensity: 0.5 }Constructors
Parameters
options{ intensity?: number; x?: number; y?: number }Optional
Properties
intensity
The intensity is used to describe the pressure of a point inside an ink annotation. It is
capped between 0 and 1 inclusive.
If the touch input does not allow to measure the pressure, a value of 0.5 should be used.
Default Value
0.5Methods
Applies a transformation to the point by multiplying the point like a 2D vector to the matrix.
Parameters
matrixTransformationMatrixReturns
this
Calculates the euclidean distance to another point.
Parameters
otherthisThe other point to calculate the distance with.
Returns
numberThe 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
Returns the record's
[key, value]pairs, in the order its fields were defined.Returns
IterableIterator<[string, unknown]>An iterator over the record's fields.
Rotates the point at the origin [0, 0].
Parameters
degnumberReturns
this
Scales
xandyby the givensxandsyfactor. If onlysxis set andsynot defined, it will scalexandybysx.Parameters
sxnumberScale value for the
xcoordinate. Ifsyis not set, this scale will also be applied toy.synumberOptionalIf empty, it will scale
ywithsxas well.Returns
thisA 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
thisA 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
xvalue by a given number.Parameters
txnumberA number to translate the
xvalue.Returns
thisA new
Point.Example
const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
point.translateX(5); // => Point {x: 15, y: 10}
Translate the
yvalue by a given number.Parameters
tynumberA number to translate the
yvalue.Returns
thisA new
Point.Example
const point = new NutrientViewer.Geometry.Point({ x: 10, y: 10 });
point.translateY(5); // => Point {x: 10, y: 15}
Immutable Record API
27
Iterates the record's
[key, value]pairs, in the order its fields were defined.Returns
IterableIterator<[string, unknown]>
Returns a record with every key reset to the default it was defined with.
Returns
thisA new record holding only default values.
- delete<K extends keyof { intensity: number; x: number; y: number }>(
key: K & ("x" | "y" | "intensity"),
): thisReturns a record with
keyreset to the default it was defined with.Type Parameters
Kextends keyof { intensity: number; x: number; y: number }Parameters
keyK & ("x" | "y" | "intensity")One of the keys this record was defined with.
Returns
thisA new record, or this one when the value already equals the default.
Returns a record with the value at
keyPathremoved. A field of this record is reset to its default; a key of a nested collection or plain object is deleted.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
thisA new record, or this one when nothing was removed.
equals
Reports whether
otheris a record holding the same keys with equal values, whatever its class.Parameters
otherunknownThe value to compare against.
Returns
booleantruewhen both hold the same keys and every value matches.Deprecated
Records of different classes with identical values compare equal. Use
isEqual(), which also requires both records to be of the same class.
- get<K extends keyof { intensity: number; x: number; y: number }, N = never>(
key: K & ("x" | "y" | "intensity"),
notSetValue?: N,
): N | { intensity: number; x: number; y: number }[K]Returns the value stored under
key.Type Parameters
Kextends keyof { intensity: number; x: number; y: number }N = neverParameters
Returns the value at
keyPath, walking nested records and collections.A literal key path is checked against the record's fields and gives the value's type; a computed one gives
unknown.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
unknownThe value at that path, or
undefinedwhen it does not resolve.Returns the value at
keyPath, walking nested records and collections.A literal key path is checked against the record's fields and gives the value's type; a computed one gives
unknown.
Reports whether
keyis one of the keys this record was defined with.A literal key must name a field; a key typed as
stringis narrowed to the field names.Parameters
keystringThe key to look for.
Returns
key is "x" | "y" | "intensity"truewhen the record defines that key, even if its value isnull.
Computes a hash of this record from its contents, the same way Immutable.js does. Equal records have equal hashes; records with equal hashes are not necessarily equal. Plain objects, functions and symbols hash by identity, so a hash is only meaningful within the page that computed it.
Returns
numberAn integer hash.
Reports whether
keyPathresolves, walking nested records and collections.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
Returns
booleantruewhen every key along the path is present.
Reports whether
otheris a record of the same class holding equal values. Only the two records' own classes are compared; nested records compare asequals()does.Parameters
otherunknownThe value to compare against.
Returns
booleantruewhen both are the same class and every value matches.
- mergeDeep(
...collections: (
| Partial<{ x: number; y: number; intensity: number }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in, recursing into nested collections and plain objects instead of replacing them.
Keys the record was not defined with are ignored.
Returns a record with each collection merged deeply into the value at
keyPath.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
thisA new record, or this one when the value is unchanged.
- mergeDeepWith(
merger: (previous: unknown, next: unknown, key: unknown) => unknown,
...collections: (
| Partial<{ x: number; y: number; intensity: number }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in deeply, calling
mergerwhere a nested value is not a collection to decide the value that is kept.Keys the record was not defined with are ignored.
Parameters
Returns
thisA new record, or this one when no value changed.
Returns a record with each collection merged into the value at
keyPath, one level at a time.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
...collectionsunknown[]Collections or plain objects to merge into the value there.
Returns
thisA new record, or this one when the value is unchanged.
- mergeWith(
merger: <K extends string | number | symbol>(
previous: { intensity: number; x: number; y: number }[K],
next: { intensity: number; x: number; y: number }[K],
key: K,
) => { intensity: number; x: number; y: number }[K],
...collections: (
| Partial<{ intensity: number; x: number; y: number }>
| Iterable<readonly [string, unknown]>
)[],
): thisReturns a record with the entries of each collection merged in, calling
mergerfor each key the record already holds to decide the value that is kept.Keys the record was not defined with are ignored.
Parameters
merger<K extends string | number | symbol>(
previous: { intensity: number; x: number; y: number }[K],
next: { intensity: number; x: number; y: number }[K],
key: K
) => { intensity: number; x: number; y: number }[K]Receives the current value, the incoming value and the key.
Returns
thisA new record, or this one when no value changed.
- set<K extends keyof { intensity: number; x: number; y: number }>(
key: K & ("x" | "y" | "intensity"),
value: { intensity: number; x: number; y: number }[K],
): thisReturns a record with
keyset tovalue.Setting a key to the value it already holds returns the same instance, so a record can be compared by reference to detect a change.
Type Parameters
Kextends keyof { intensity: number; x: number; y: number }Parameters
Returns
thisA new record, or this one when the value is unchanged or the key is not defined.
Returns a record with
valuewritten atkeyPath.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
valueunknownThe value to store.
Returns
thisA new record, or this one when the value is unchanged.
Converts this record and everything nested inside it to plain JavaScript values.
Returns
{ x: number; y: number; intensity: number }A plain object holding this record's values, converted all the way down.
x: number
The
xcoordinate of the point.Default Value
0y: number
The
ycoordinate of the point.Default Value
0intensity: number
The
intensityis used to describe the pressure of a point inside an ink annotation. It is capped between 0 and 1 inclusive.If the touch input does not allow to measure the pressure, a value of
0.5should be used.Default Value
0.5
An alias for toObject, called by
JSON.stringify.Returns
{ intensity: number; x: number; y: number }A plain object holding this record's values.
intensity: number
The
intensityis used to describe the pressure of a point inside an ink annotation. It is capped between 0 and 1 inclusive.If the touch input does not allow to measure the pressure, a value of
0.5should be used.Default Value
0.5x: number
The
xcoordinate of the point.Default Value
0y: number
The
ycoordinate of the point.Default Value
0
Converts this record to a plain object, one level deep. Nested records are left as they are.
Returns
{ intensity: number; x: number; y: number }A plain object holding this record's values.
intensity: number
The
intensityis used to describe the pressure of a point inside an ink annotation. It is capped between 0 and 1 inclusive.If the touch input does not allow to measure the pressure, a value of
0.5should be used.Default Value
0.5x: number
The
xcoordinate of the point.Default Value
0y: number
The
ycoordinate of the point.Default Value
0
- update<K extends keyof { intensity: number; x: number; y: number }>(
key: K & ("x" | "y" | "intensity"),
updater: (
value: { intensity: number; x: number; y: number }[K],
) => { intensity: number; x: number; y: number }[K],
): thisReturns a record with
keyreplaced by the result of applyingupdaterto its current value.Type Parameters
Kextends keyof { intensity: number; x: number; y: number }Parameters
Returns
thisA new record, or this one when the value is unchanged.
- updateIn<N>(
keyPath: Iterable<unknown>,
notSetValue: N,
updater: (value: unknown) => unknown,
): thisReturns a record with the value at
keyPathreplaced by the result ofupdater. Returns a record with the value at
keyPathreplaced by the result ofupdater.Parameters
keyPathIterable<unknown>The keys to follow, outermost first.
updater(value: unknown) => unknownReceives the current value and returns the new one.
Returns
thisA new record, or this one when the value is unchanged.
Applies several changes as one, so only a single new record is allocated.
The record handed to
mutatormay be written to withset; it is frozen again oncemutatorreturns.Parameters
mutator(mutable: this) => unknownReceives a temporarily writable copy of this record.
Returns
thisA new record holding the applied changes, or this one when nothing changed.
An extension of the NutrientViewer.Geometry.Point that can also store an
intensityvalue. This is used for example inside an ink annotation, where the intensity is the pressure that was exerted by the touch device.