Geometry primitives

Since JavaScript does not ship geometry helpers by default, we at Nutrient developed a set of tested geometry classes that we use throughout all our classes. These types are based on the Immutable.js(opens in a new tab) library in order to work with immutable data.

This article should give you a quick overview of the basic data types we expose right now and when you want to use them. Refer to the PSPDFKit.Geometry documentation for an in-depth look at the APIs.

Nutrient classUse case
PointDescribe a point in 2D space.
DrawingPointAn extension of the point with an intensity value. This is used for storing pressure while drawing an InkAnnotation.
RectDescribes a rectangle in space. This is the combination of a location (point) and a dimension (size).
SizeDescribes the size of an element. This is similar to point, but its value should be interpreted as a dimension.

All of these classes come with a number of geometric helpers. For a full list, refer to the PSPDFKit.Geometry documentation:

const { Point } = PSPDFKit.Geometry;
const point = new Point({ x: 10, y: 20 })
.translateX(20)
.translateY(40)
.scale(1.5);
console.log(point); // => Point({ x: 45, y: 90 })