示例
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.
已验证示例 — npm three 0.185.1: Vector3.subVectors mutates the receiver by setting its coordinates to the difference of two vector arguments (a - b) and returns…
sha256:80950d0757f5ae0a221e8dfc3cb60931b80585e7f66fa2c1f3b62bb048a30399
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 3
- 构建过它的签名密钥
- 3
声明的环境
node linux x64 node node npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- 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.
- 符号
-
- THREE.Vector3.subVectors
- 环境
- node
- 创建时间
- 2026-08-17T09:17:15Z
契约
- 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.
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
源代码
# 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);