Exemple
three 0.185.1: Vector3.subVectors mutates the receiver by setting its coordinates to the difference of two vector arguments (a - b) and returns the mutated instance without altering the operands.
Échantillon vérifié pour npm three 0.185.1: Vector3.subVectors mutates the receiver by setting its coordinates to the difference of two vector arguments (a …
sha256:80950d0757f5ae0a221e8dfc3cb60931b80585e7f66fa2c1f3b62bb048a30399
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 3
- Clés de signature qui l’ont compilé
- 3
Environnement déclaré
node linux x64 node node npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| 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 |
Cas
HOW- Objectif
- Vector3.subVectors mutates the receiver by setting its coordinates to the difference of two vector arguments (a - b) and returns the mutated instance without altering the operands.
- Paquets
- Symboles
-
- THREE.Vector3.subVectors
- Environnement
- node
- Créé
- 2026-08-17T09:17:15Z
Contrat
- Vector3.subVectors(a, b) computes the component-wise difference a - b into the receiver, mutating it in place and returning its reference for chaining while leaving operands a and b unchanged.
- Vector3.subVectors completely replaces existing receiver coordinates rather than subtracting operand vectors from the receiver's prior state.
- Calling subVectors with the receiver as the first operand computes the difference in place equivalently to sub.
- Vector3.subVectors accepts vector-like objects with x, y, and z numeric properties as operands.
Fichiers
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Code source
# three - Vector3.subVectors
## Prior Search
`search_known_solution` returned existing published samples for `three@0.185.1` covering `MeshSurfaceSampler.sample`, `SkinnedMesh.applyBoneTransform`, and `CanvasTexture`, but no match for `THREE.Vector3.subVectors`.
## Pinned Release
- Package: `three`
- Version: `0.185.1` (exact lockfile resolution)
## Observed Behavior
1. **In-place Mutation & Return Value**:
`Vector3.prototype.subVectors(a, b)` computes the component-wise difference `a - b` (`this.x = a.x - b.x; this.y = a.y - b.y; this.z = a.z - b.z;`) and writes the result directly into `this`. It returns `this` (the mutated receiver instance reference) to enable method chaining, rather than allocating and returning a new `Vector3`.
2. **Operand Immutability**:
The input operand vectors `a` and `b` are not modified by the operation (provided they are distinct object references from the receiver).
3. **Complete Receiver Overwrite**:
Prior coordinate values on the receiver vector are completely replaced by `a - b`, rather than subtracted from (unlike `v.sub(a)` which computes `v - a`).
4. **Self-Aliasing**:
When called as `a.subVectors(a, b)`, it safely updates `a` to `a - b` in place, identical to calling `a.sub(b)`.
5. **Structural Duck Typing**:
`subVectors` requires only that operands `a` and `b` expose numeric `x`, `y`, and `z` properties. Plain JavaScript objects or other compatible vector types can be supplied as operands.
## Failure Mode
A caller assuming `const diff = v.subVectors(a, b)` returns a newly allocated vector without modifying `v` will inadvertently mutate `v` and retain a reference to `v` under `diff` (`diff === v`). Modifying `diff` later will silently corrupt `v` (or vice versa). Furthermore, expecting `v.subVectors(a, b)` to subtract `a` and `b` from `v`'s initial coordinates leads to incorrect calculations since `v`'s initial state is discarded.
{"case":{"believed":"Vector3.subVectors returns a new Vector3 instance representing the difference of two vectors or subtracts both arguments from the receiver's initial value.","caseId":"case:sha256:7245eca0fbbf9c892880f90f771025878a86858c511b554a7054cd25646506e0","contract":["Vector3.subVectors(a, b) computes the component-wise difference a - b into the receiver, mutating it in place and returning its reference for chaining while leaving operands a and b unchanged.","Vector3.subVectors completely replaces existing receiver coordinates rather than subtracting operand vectors from the receiver's prior state.","Calling subVectors with the receiver as the first operand computes the difference in place equivalently to sub.","Vector3.subVectors accepts vector-like objects with x, y, and z numeric properties as operands."],"goal":"Vector3.subVectors mutates the receiver by setting its coordinates to the difference of two vector arguments (a - b) and returns the mutated instance without altering the operands.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["THREE.Vector3.subVectors"]},"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":["THREE.Vector3.subVectors"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-three-wanted-0-185-1-three-vector3-subvectors-ac7cfb768c5a10d0b369d9e1",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-three-wanted-0-185-1-three-vector3-subvectors-ac7cfb768c5a10d0b369d9e1",
"version": "1.0.0",
"license": "ISC",
"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"
}
}
}
{
"name": "npm-three-wanted-0-185-1-three-vector3-subvectors",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"three": "0.185.1"
}
}
import assert from 'node:assert/strict';
import * as THREE from 'three';
// 1. Vector3.subVectors(a, b) computes the component-wise difference (a - b) into the receiver,
// mutating the receiver in place and returning its reference for chaining, while leaving operands a and b unchanged.
const target = new THREE.Vector3(100, 200, 300);
const a = new THREE.Vector3(10, 25, 40);
const b = new THREE.Vector3(3, 5, 10);
const result = target.subVectors(a, b);
// Returns the mutated receiver instance itself (reference equality)
assert.strictEqual(result, target, 'subVectors should return this receiver instance');
assert.strictEqual(target.x, 7);
assert.strictEqual(target.y, 20);
assert.strictEqual(target.z, 30);
// Operands a and b remain completely unmodified
assert.strictEqual(a.x, 10);
assert.strictEqual(a.y, 25);
assert.strictEqual(a.z, 40);
assert.strictEqual(b.x, 3);
assert.strictEqual(b.y, 5);
assert.strictEqual(b.z, 10);
// 2. Vector3.subVectors completely replaces existing receiver coordinates rather than subtracting operands from them
const dirtyTarget = new THREE.Vector3(999, 888, 777);
dirtyTarget.subVectors(new THREE.Vector3(1, 2, 3), new THREE.Vector3(1, 2, 3));
assert.strictEqual(dirtyTarget.x, 0);
assert.strictEqual(dirtyTarget.y, 0);
assert.strictEqual(dirtyTarget.z, 0);
// 3. Method chaining enables immediate vector algebra operations on the result
const dist = new THREE.Vector3().subVectors(new THREE.Vector3(0, 4, 0), new THREE.Vector3(3, 0, 0)).length();
assert.strictEqual(dist, 5);
// 4. Aliasing receiver as the first operand computes in-place difference (a.subVectors(a, b) === a.sub(b))
const selfA = new THREE.Vector3(15, 30, 45);
const operandB = new THREE.Vector3(5, 10, 15);
selfA.subVectors(selfA, operandB);
assert.strictEqual(selfA.x, 10);
assert.strictEqual(selfA.y, 20);
assert.strictEqual(selfA.z, 30);
// 5. Duck typing: subVectors accepts plain objects with x, y, z numeric properties
const duckTarget = new THREE.Vector3();
duckTarget.subVectors({ x: 50, y: 40, z: 30 }, { x: 10, y: 15, z: 20 });
assert.strictEqual(duckTarget.x, 40);
assert.strictEqual(duckTarget.y, 25);
assert.strictEqual(duckTarget.z, 10);