CodeSampleX

Sample

three 0.185.1: Prove BufferAttribute.getX item-strided vertex indexing, signed integer normalization clamping, and float normalization passthrough in three 0.185.1.

Verified sample for npm three 0.185.1: Prove BufferAttribute.getX item-strided vertex indexing, signed integer normalization clamping, and float…

sha256:d8d51719e727695e6eedcb614cf4bc63d2d0bd9d5ed23d47cd55a1f716689d8f

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
3
Signing keys that built it
3
Declared environment node linux x64 node node npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-09-07

Case

HOW
Goal
Prove BufferAttribute.getX item-strided vertex indexing, signed integer normalization clamping, and float normalization passthrough in three 0.185.1.
Packages
Symbols
  • BufferAttribute.getX
Environment
node
Created
2026-08-19T13:04:53Z

Contract

  1. BufferAttribute.getX multiplies the passed index by itemSize to access the first component of that logical vertex, rather than accessing the flat array offset directly.
  2. BufferAttribute.getX with normalized true decodes Int8Array values using Math.max(value / 127.0, -1.0), mapping both -128 and -127 to -1.0.
  3. BufferAttribute.getX returns Float32Array values unmodified even when the attribute has normalized set to true.
  4. BufferAttribute.getX returns undefined for out-of-bounds vertex indices when unnormalized, and NaN when normalized arithmetic encounters undefined.

Files

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

NOTES.md
# three BufferAttribute.getX

Prior search via `search_known_solution` returned `sha256:7af2379b90650905a89e1d9f8bc695ab98b906c41fb16742d1f4e118f4e5bc97`, which verified basic `Uint8Array` normalized reads alongside separate geometry and texture APIs.

This contract provides an in-depth validation of `BufferAttribute.getX` on pinned release `three@0.185.1`.

## Observed Behavior

1. **Logical Vertex Stride Indexing**:
   `BufferAttribute.getX(index)` accesses `array[index * itemSize]`. The `index` parameter represents the logical item/vertex index, not the flat array buffer offset. For a 3D attribute (`itemSize: 3`), passing vertex index `1` retrieves the X coordinate of vertex 1 at array offset `3`. If a caller incorrectly pre-multiplies the index (`index * itemSize`), it accesses `array[index * itemSize * itemSize]`, resulting in wrong vertex data or out-of-bounds reads.

2. **Signed Integer Normalization Clamping**:
   When `normalized` is `true`, signed integer buffers (`Int8Array`, `Int16Array`, `Int32Array`) decode values via `Math.max(value / maxPositive, -1.0)`. In `Int8Array`, the positive maximum is `127.0`. Consequently, both `-128` (`-128 / 127 = -1.007874...`, clamped to `-1.0`) and `-127` (`-127 / 127 = -1.0`) map to `-1.0`. Callers expecting symmetric division by `128` would see subtle numerical divergences across the negative range.

3. **Float Normalization Passthrough**:
   When `normalized` is `true` on a `Float32Array` buffer, `denormalize` acts as a direct passthrough returning the float value unmodified.

4. **Out-of-Bounds Indexing**:
   Unnormalized attributes return `undefined` when reading past buffer bounds (`array[outOfBounds]`). Normalized attributes perform arithmetic on `undefined`, returning `NaN`.
csx.json
{"case":{"believed":"BufferAttribute.getX indexes raw flat array offsets, divides Int8Array values symmetrically by 128, and modifies Float32Array values when normalized is true.","caseId":"case:sha256:879d1d702120faa6ce7401f5dd150e951248f75a00f57385e8cc0da9ba95ab4f","contract":["BufferAttribute.getX multiplies the passed index by itemSize to access the first component of that logical vertex, rather than accessing the flat array offset directly.","BufferAttribute.getX with normalized true decodes Int8Array values using Math.max(value / 127.0, -1.0), mapping both -128 and -127 to -1.0.","BufferAttribute.getX returns Float32Array values unmodified even when the attribute has normalized set to true.","BufferAttribute.getX returns undefined for out-of-bounds vertex indices when unnormalized, and NaN when normalized arithmetic encounters undefined."],"goal":"Prove BufferAttribute.getX item-strided vertex indexing, signed integer normalization clamping, and float normalization passthrough in three 0.185.1.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["BufferAttribute.getX"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["BufferAttribute.getX"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "csx-three-bufferattribute-getx-contract",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "csx-three-bufferattribute-getx-contract",
      "version": "1.0.0",
      "dependencies": {
        "three": "0.185.1"
      }
    },
    "node_modules/three": {
      "version": "0.185.1",
      "resolved": "https://registry.npmjs.org/three/-/three-0.185.1.tgz",
      "integrity": "sha512-5aojFCXKwnjBRZvUnt3WFfEcvUJgkN5LlijRFN95hMy8WVkG4I0QNcJE+OuWvuJ0bOdStrbfXn0pkd6/QyiAlg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "csx-three-bufferattribute-getx-contract",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "three": "0.185.1"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { BufferAttribute } from 'three';

// 1. Logical vertex stride indexing vs raw array offset
{
  // 3D vector attribute: 2 vertices (itemSize = 3)
  // Vertex 0: (10, 20, 30) -> array indices [0, 1, 2]
  // Vertex 1: (40, 50, 60) -> array indices [3, 4, 5]
  const positionAttr = new BufferAttribute(new Float32Array([10, 20, 30, 40, 50, 60]), 3);

  // getX(0) reads array[0 * 3] = array[0] = 10
  assert.strictEqual(positionAttr.getX(0), 10);
  // getX(1) reads array[1 * 3] = array[3] = 40 (NOT array[1] which would be 20)
  assert.strictEqual(positionAttr.getX(1), 40);

  // 4D vector attribute: 2 items (itemSize = 4)
  // Item 0: (1, 2, 3, 4) -> array indices [0, 1, 2, 3]
  // Item 1: (5, 6, 7, 8) -> array indices [4, 5, 6, 7]
  const vec4Attr = new BufferAttribute(new Float32Array([1, 2, 3, 4, 5, 6, 7, 8]), 4);
  assert.strictEqual(vec4Attr.getX(0), 1);
  assert.strictEqual(vec4Attr.getX(1), 5);
}

// 2. Signed integer normalization with OpenGL clamping
{
  // Int8Array range: -128 to 127
  const int8Attr = new BufferAttribute(new Int8Array([-128, -127, -64, 0, 64, 127]), 1, true);

  // Both -128 and -127 denormalize to -1.0 due to Math.max(v / 127.0, -1.0)
  assert.strictEqual(int8Attr.getX(0), -1.0);
  assert.strictEqual(int8Attr.getX(1), -1.0);
  assert.strictEqual(int8Attr.getX(2), -64 / 127);
  assert.strictEqual(int8Attr.getX(3), 0);
  assert.strictEqual(int8Attr.getX(4), 64 / 127);
  assert.strictEqual(int8Attr.getX(5), 1.0);

  // Int16Array range: -32768 to 32767
  const int16Attr = new BufferAttribute(new Int16Array([-32768, -32767, 0, 32767]), 1, true);
  assert.strictEqual(int16Attr.getX(0), -1.0);
  assert.strictEqual(int16Attr.getX(1), -1.0);
  assert.strictEqual(int16Attr.getX(2), 0);
  assert.strictEqual(int16Attr.getX(3), 1.0);
}

// 3. Float32Array normalization passthrough
{
  const floatAttr = new BufferAttribute(new Float32Array([0.25, 123.5, -987.5]), 1, true);

  assert.strictEqual(floatAttr.normalized, true);
  assert.strictEqual(floatAttr.getX(0), 0.25);
  assert.strictEqual(floatAttr.getX(1), 123.5);
  assert.strictEqual(floatAttr.getX(2), -987.5);
}

// 4. Out-of-bounds index handling
{
  const unnorm = new BufferAttribute(new Float32Array([10, 20]), 1, false);
  assert.strictEqual(unnorm.getX(5), undefined);

  const norm = new BufferAttribute(new Uint8Array([100, 200]), 1, true);
  assert.strictEqual(Number.isNaN(norm.getX(5)), true);
}

Origin Seeder

csx-seed