b64Vecs
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( )
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
| Name | Description |
|---|---|
| The delta-encoded base64 string |
| Encoding dimension; |
Returns
null | VecModel;The first point as a VecModel, or null if the string is too short
decodeFirstPoint2D( )
Get the first point from a 2D delta-encoded base64 string.
static decodeFirstPoint2D(b64Points: string): null | VecModel;Parameters
| Name | Description |
|---|---|
| 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( )
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
| Name | Description |
|---|---|
| The delta-encoded base64 string |
| Encoding dimension; |
Returns
null | VecModel;The last point as a VecModel, or null if the string is too short
decodeLastPoint2D( )
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
| Name | Description |
|---|---|
| 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( )
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
| Name | Description |
|---|---|
| The base64-encoded string containing delta-encoded point data |
| Encoding dimension; |
Returns
VecModel[];An array of VecModel objects with absolute coordinates
decodePoints2D( )
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
| Name | Description |
|---|---|
| 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( )
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
| Name | Description |
|---|---|
| An array of VecModel objects to encode |
| Encoding dimension; |
Returns
string;A base64-encoded string containing delta-encoded points
encodePoints2D( )
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
| Name | Description |
|---|---|
| An array of VecModel objects to encode (z is discarded) |
Returns
string;A base64-encoded string containing 2D delta-encoded points
isSinglePoint( )
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
| Name | Description |
|---|---|
| The encoded path string |
| Encoding dimension; |
Returns
boolean;true if the path encodes exactly one point