Binary pointer frames

Test vectors: Binary pointer frames. Shown here as it is in conformance/vectors/pointer.json.

Generated at build time from conformance/vectors/pointer.json.

Protocol 0.1. Covers: SPEC.md section 11, "Pointer stream" (layout table and encoding of fractions).

Download pointer.json: the file itself, as the conformance suite reads it.

How to use it #

Encode frame and compare with hex; decode hex and compare with frame; clamp and rounding cases check the encoding of fractions and dt; invalid must be refused.

Layout #

Text
offset 0  u8   kind  0x01 (BIN_POINTER)
offset 1  u8   flags 0x01 PTR_FLAG_DROPPABLE, 0x02 PTR_FLAG_END
offset 2  u16  ch
offset 4  u32  seq of the first point
offset 8  u16  n, number of points
offset 10 n x { u16 x, u16 y, u16 dt }, all little-endian
a fraction f is sent as round(f x 65535) after clamping to 0..1 (non-finite as 0), halves up; read back as u / 65535; dt is rounded and clamped to 0..65535

Notes #

The layout and the rounding rule are in SPEC 11. cases use exact multiples of 1/65535; rounding checks fractions between two steps; clamp checks out-of-range values; invalid frames are not pointer frames.

cases #

4 cases.

JSON
[
  {
    "name": "one point, no flags",
    "frame": {
      "ch": 1,
      "seq": 0,
      "flags": 0,
      "points": [
        {
          "x": 0,
          "y": 1,
          "dt": 0
        }
      ]
    },
    "hex": "010001000000000001000000ffff0000"
  },
  {
    "name": "three points, droppable",
    "frame": {
      "ch": 7,
      "seq": 1000,
      "flags": 1,
      "points": [
        {
          "x": 0.000015259021896696422,
          "y": 0.000030518043793392844,
          "dt": 16
        },
        {
          "x": 0.49999237048905165,
          "y": 0.5000076295109483,
          "dt": 17
        },
        {
          "x": 0.9999847409781033,
          "y": 1,
          "dt": 65535
        }
      ]
    },
    "hex": "01010700e80300000300010002001000ff7f00801100feffffffffff"
  },
  {
    "name": "end of stroke, no points",
    "frame": {
      "ch": 65535,
      "seq": 4294967295,
      "flags": 2,
      "points": []
    },
    "hex": "0102ffffffffffff0000"
  },
  {
    "name": "end and droppable bits together",
    "frame": {
      "ch": 2,
      "seq": 5,
      "flags": 3,
      "points": [
        {
          "x": 0.2,
          "y": 0.8,
          "dt": 8
        }
      ]
    },
    "hex": "010302000500000001003333cccc0800"
  }
]

clamp #

3 cases.

JSON
[
  {
    "name": "x below 0 and y above 1",
    "point": {
      "x": -0.25,
      "y": 1.5,
      "dt": 10
    },
    "expect": {
      "xu": 0,
      "yu": 65535,
      "dt": 10
    }
  },
  {
    "name": "dt above 65535",
    "point": {
      "x": 0,
      "y": 0,
      "dt": 70000
    },
    "expect": {
      "xu": 0,
      "yu": 0,
      "dt": 65535
    }
  },
  {
    "name": "negative dt",
    "point": {
      "x": 1,
      "y": 0,
      "dt": -5
    },
    "expect": {
      "xu": 65535,
      "yu": 0,
      "dt": 0
    }
  }
]

rounding #

3 cases.

JSON
[
  {
    "name": "halves round up",
    "point": {
      "x": 0.5,
      "y": 0.25,
      "dt": 16.5
    },
    "expect": {
      "xu": 32768,
      "yu": 16384,
      "dt": 17
    }
  },
  {
    "name": "0.1 and 0.9 land on halves and round up; dt rounds to nearest",
    "point": {
      "x": 0.1,
      "y": 0.9,
      "dt": 16.4
    },
    "expect": {
      "xu": 6554,
      "yu": 58982,
      "dt": 16
    }
  },
  {
    "name": "between steps",
    "point": {
      "x": 0.123,
      "y": 0.876,
      "dt": 0
    },
    "expect": {
      "xu": 8061,
      "yu": 57409,
      "dt": 0
    }
  }
]

invalid #

4 entries.

name hex
shorter than the header 0100010000000000
wrong kind byte 02000100000000000000
n says one point, none present 01000100000000000100
one trailing byte 0100010000000000000000

Generated by conformance/tools/make-vectors.mjs from the formulas in the specification, with node:crypto only.