b64Vecs

See source code
Table of contents

Utilities for encoding and decoding points using base64 and Float16 encoding. Provides functions for converting between VecModel arrays and compact base64 strings, as well as individual point encoding/decoding operations.

class b64Vecs {}

Methods

decodeFirstPoint( )

static

Get the first point from a delta-encoded base64 string. The first point is stored as Float32 for full precision.

static decodeFirstPoint(b64Points: string, dim?: 2 | 3): null | VecModel;

Parameters

NameDescription

b64Points

string;

The delta-encoded base64 string

dim

2 | 3;

Encoding dimension; 2 expects x/y only (z supplied as 0.5), 3 (default) expects x/y/z

Returns

null | VecModel;

The first point as a VecModel, or null if the string is too short


decodeFirstPoint2D( )

static

Get the first point from a 2D delta-encoded base64 string.

static decodeFirstPoint2D(b64Points: string): null | VecModel;

Parameters

NameDescription

b64Points

string;

The 2D delta-encoded base64 string

Returns

null | VecModel;

The first point with z = 0.5, or null if the string is too short


decodeLastPoint( )

static

Get the last point from a delta-encoded base64 string. Requires decoding all points to accumulate deltas.

static decodeLastPoint(b64Points: string, dim?: 2 | 3): null | VecModel;

Parameters

NameDescription

b64Points

string;

The delta-encoded base64 string

dim

2 | 3;

Encoding dimension; 2 expects x/y only (z supplied as 0.5), 3 (default) expects x/y/z

Returns

null | VecModel;

The last point as a VecModel, or null if the string is too short


decodeLastPoint2D( )

static

Get the last point from a 2D delta-encoded base64 string. Requires decoding all points to accumulate deltas.

static decodeLastPoint2D(b64Points: string): null | VecModel;

Parameters

NameDescription

b64Points

string;

The 2D delta-encoded base64 string

Returns

null | VecModel;

The last point with z = 0.5, or null if the string is too short


decodePoints( )

static

Decode a delta-encoded base64 string back to an array of absolute VecModels. The first point is stored as Float32 (high precision), subsequent points are Float16 deltas that are accumulated to reconstruct absolute positions.

static decodePoints(base64: string, dim?: 2 | 3): VecModel[];

Parameters

NameDescription

base64

string;

The base64-encoded string containing delta-encoded point data

dim

2 | 3;

Encoding dimension; 2 expects x/y only (z supplied as 0.5), 3 (default) expects x/y/z

Returns

VecModel[];

An array of VecModel objects with absolute coordinates


decodePoints2D( )

static

Decode a 2D delta-encoded base64 string back to an array of absolute VecModels. The z coordinate is always set to 0.5 (the default pressure value) so downstream consumers don't need a separate code path.

static decodePoints2D(base64: string): VecModel[];

Parameters

NameDescription

base64

string;

The base64-encoded string containing 2D delta-encoded point data

Returns

VecModel[];

An array of VecModel objects with absolute (x, y) and z = 0.5


encodePoints( )

static

Encode an array of VecModels using delta encoding for improved precision. The first point is stored as Float32 (high precision for absolute position), subsequent points are stored as Float16 deltas from the previous point. This provides full precision for the starting position and excellent precision for deltas between consecutive points (which are typically small values).

Format: - First point: 3 Float32 values = 12 bytes = 16 base64 chars - Delta points: 3 Float16 values each = 6 bytes = 8 base64 chars each

static encodePoints(points: VecModel[], dim?: 2 | 3): string;

Parameters

NameDescription

points

VecModel[];

An array of VecModel objects to encode

dim

2 | 3;

Encoding dimension; 2 routes through the 2D variant (drops z), 3 (default) keeps x, y, z

Returns

string;

A base64-encoded string containing delta-encoded points


encodePoints2D( )

static

Encode an array of VecModels as 2D delta-encoded points, dropping z entirely. Use for draw shapes from devices that don't report pressure, where z is a constant 0.5 and storing it wastes ~33% of per-point bytes.

Format: - First point: 2 Float32 values (x, y) = 8 bytes - Delta points: 2 Float16 values (dx, dy) = 4 bytes each

static encodePoints2D(points: VecModel[]): string;

Parameters

NameDescription

points

VecModel[];

An array of VecModel objects to encode (z is discarded)

Returns

string;

A base64-encoded string containing 2D delta-encoded points


isSinglePoint( )

static

Whether an encoded path contains only a single point (a "dot"), inferred from the encoded length without decoding — cheap enough for the render path.

The single-point length depends on the encoding dimension, so this takes the segment's dim: a one-point path is FIRST_POINT_B64_LENGTH chars (3D) or FIRST_POINT_2D_B64_LENGTH chars (2D). Keeping this beside the layout constants is deliberate — it is the single source of truth for "how long is one point", so callers never hard-code a length threshold (which silently breaks when a new encoding is added).

static isSinglePoint(b64Points: string, dim?: 2 | 3): boolean;

Parameters

NameDescription

b64Points

string;

The encoded path string

dim

2 | 3;

Encoding dimension; 2 for (x, y), 3 (default) for (x, y, z)

Returns

boolean;

true if the path encodes exactly one point


Prev
ZoomTool
Next
EnumStyleProp