Skip to content

Commit c74c5fb

Browse files
author
DavidQ
committed
BUILD PR: centralize safeNormalize across exact AITargetDummy batch.
1 parent 4ba9b2f commit c74c5fb

9 files changed

Lines changed: 112 additions & 26 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
MODEL: GPT-5.3-codex
22
REASONING: high
33
COMMAND:
4-
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_38_CODE_TO_LETTER_HIGHSCORE_BATCH.md exactly.
4+
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_39_SAFE_NORMALIZE_AITARGETDUMMY_BATCH.md exactly.
55
Edit only these files:
6-
- src/shared/utils/initialsEntryUtils.js (new file)
7-
- games/Asteroids/systems/AsteroidsInitialsEntry.js
8-
- games/SpaceDuel/game/SpaceDuelInitialsEntry.js
9-
- games/SpaceInvaders/game/SpaceInvadersInitialsEntry.js
6+
- src/shared/math/vectorNormalizeUtils.js (new file)
7+
- games/AITargetDummy/game/AITargetDummyController.js
8+
- games/AITargetDummy/game/AITargetDummyWorld.js
109
Do not expand scope.
11-
Package the delta output to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_38_CODE_TO_LETTER_HIGHSCORE_BATCH_delta.zip
10+
Package the delta output to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_39_SAFE_NORMALIZE_AITARGETDUMMY_BATCH_delta.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BUILD PR: centralize codeToLetter across exact initials-entry batch.
1+
BUILD PR: centralize safeNormalize across exact AITargetDummy batch.

docs/dev/NEXT_COMMAND.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Next: continue duplicate-family extraction from the provided duplicate report.
1+
Next: run BUILD_PR_SHARED_EXTRACTION_40_CLONE_SNAPSHOT_NETWORK_SAMPLE_C_BATCH after this batch.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Execution-grade batch for codeToLetter using the exact duplicate-report file list.
1+
Rebuilt 39 as an execution-grade batch using the exact duplicate-report file list for safeNormalize(x, y).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Exact file list present; one PR purpose only; no guessing.
1+
Exact file list present; exact helper list present; one PR purpose only.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# BUILD_PR_SHARED_EXTRACTION_39_SAFE_NORMALIZE_AITARGETDUMMY_BATCH
2+
3+
## Purpose
4+
Centralize duplicated `safeNormalize(x, y)` implementations across the exact AITargetDummy batch identified in the duplicate report.
5+
6+
## Single PR Purpose
7+
Normalize ONLY this helper:
8+
9+
- `safeNormalize(x, y)`
10+
11+
## Exact Files Allowed
12+
13+
### New shared file
14+
1. `src/shared/math/vectorNormalizeUtils.js`
15+
16+
### Consumer files
17+
2. `games/AITargetDummy/game/AITargetDummyController.js`
18+
3. `games/AITargetDummy/game/AITargetDummyWorld.js`
19+
20+
Do not edit any other file.
21+
22+
## Source of Truth
23+
This exact scope comes from the provided duplicate report entry for:
24+
25+
`function safeNormalize(x, y)`
26+
27+
Only the 2 listed consumer files are in scope.
28+
29+
## Exact Shared Helper Creation
30+
Create:
31+
32+
`src/shared/math/vectorNormalizeUtils.js`
33+
34+
Export exactly:
35+
36+
```js
37+
export function safeNormalize(x, y) {
38+
// copy one existing implementation exactly
39+
}
40+
```
41+
42+
Implementation rules:
43+
- use ONE existing local implementation as source-of-truth
44+
- do NOT merge logic
45+
- do NOT generalize behavior
46+
- preserve the function signature exactly:
47+
- `safeNormalize(x, y)`
48+
49+
## Exact Consumer Changes
50+
For each of the 2 listed consumer files:
51+
52+
If the file contains a local function definition matching:
53+
```js
54+
function safeNormalize(x, y)
55+
```
56+
then:
57+
- remove the local `safeNormalize(x, y)` function definition
58+
- import `safeNormalize` from the correct relative path to:
59+
- `src/shared/math/vectorNormalizeUtils.js`
60+
- if the file already imports from that module, add `safeNormalize` with the minimum safe edit
61+
- do not duplicate imports
62+
- do not touch unrelated helpers
63+
- do not change logic
64+
65+
If a listed file already imports and uses shared `safeNormalize`, leave it unchanged.
66+
67+
## Relative Import Rule
68+
Use the correct relative path from each consumer file to:
69+
70+
`src/shared/math/vectorNormalizeUtils.js`
71+
72+
Do not use aliases.
73+
Do not change `.js` extension usage.
74+
75+
## Hard Constraints
76+
- no engine changes
77+
- no game files outside the 2 listed consumers
78+
- no sample files
79+
- no repo-wide normalize/vector helper cleanup
80+
- no behavior changes
81+
- keep one PR purpose only
82+
83+
## Validation Checklist
84+
1. Confirm no more than the 3 listed files changed
85+
2. Confirm `src/shared/math/vectorNormalizeUtils.js` exists and exports `safeNormalize`
86+
3. Confirm local `function safeNormalize(x, y)` definitions no longer exist in changed listed consumer files
87+
4. Confirm changed consumer files import `safeNormalize` from the correct relative path to `src/shared/math/vectorNormalizeUtils.js`
88+
5. Confirm no unrelated engine, game, or sample files changed
89+
6. Confirm no behavior changes were made
90+
91+
## Non-Goals
92+
- no cleanup of other vector/math helpers
93+
- no cleanup outside the 2 listed consumer files
94+
- no refactor beyond this exact duplicate-removal batch

games/AITargetDummy/game/AITargetDummyController.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ AITargetDummyController.js
77
import AITargetDummyConfig from './AITargetDummyConfig.js';
88
import AITargetDummyStateMachine from './AITargetDummyStateMachine.js';
99
import { clamp } from '../../../src/engine/utils/math.js';
10-
11-
function safeNormalize(x, y) {
12-
const length = Math.hypot(x, y);
13-
if (length <= 1e-6) {
14-
return { x: 0, y: 0, length: 0 };
15-
}
16-
return { x: x / length, y: y / length, length };
17-
}
10+
import { safeNormalize } from '../../../src/shared/math/vectorNormalizeUtils.js';
1811

1912
export default class AITargetDummyController {
2013
constructor({ config = AITargetDummyConfig } = {}) {

games/AITargetDummy/game/AITargetDummyWorld.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@ AITargetDummyWorld.js
77
import AITargetDummyConfig from './AITargetDummyConfig.js';
88
import AITargetDummyController from './AITargetDummyController.js';
99
import { clamp } from '../../../src/engine/utils/math.js';
10+
import { safeNormalize } from '../../../src/shared/math/vectorNormalizeUtils.js';
1011

1112
const MAX_STEP_SECONDS = 1 / 120;
1213

13-
function safeNormalize(x, y) {
14-
const length = Math.hypot(x, y);
15-
if (length <= 1e-6) {
16-
return { x: 0, y: 0, length: 0 };
17-
}
18-
return { x: x / length, y: y / length, length };
19-
}
20-
2114
export default class AITargetDummyWorld {
2215
constructor({ width = 960, height = 720, config = AITargetDummyConfig } = {}) {
2316
this.width = width;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function safeNormalize(x, y) {
2+
const length = Math.hypot(x, y);
3+
if (length <= 1e-6) {
4+
return { x: 0, y: 0, length: 0 };
5+
}
6+
return { x: x / length, y: y / length, length };
7+
}

0 commit comments

Comments
 (0)