Skip to content

Commit 8588c38

Browse files
authored
Remove redundant _isDirty sets (#17407)
Vector **classes** already set _isDirty to true when setting individual properties like `x`, `y`, and `z`, so the _isDirty handling from the previous change is not actually needed. Keeping the tests but removing the _isDirty-related validation.
1 parent 812e65a commit 8588c38

File tree

3 files changed

+18
-43
lines changed

3 files changed

+18
-43
lines changed

packages/dev/core/src/Maths/math.like.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,11 @@ export interface IVector3Like extends IVector2Like {
3434
/**
3535
* @internal
3636
*/
37-
export interface IDirtyFlagLike {
38-
_isDirty?: boolean;
39-
}
40-
41-
/**
42-
* @internal
43-
*/
44-
export interface IVector3LikeInternal extends IDirtyFlagLike {
37+
export interface IVector3LikeInternal {
4538
_x: number;
4639
_y: number;
4740
_z: number;
41+
_isDirty?: boolean;
4842
}
4943

5044
/**

packages/dev/core/src/Maths/math.vector.functions.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { Clamp } from "./math.scalar.functions";
22
import type { DeepImmutable } from "../types";
3-
import type { IDirtyFlagLike, IQuaternionLike, IVector2Like, IVector3Like, IVector4Like } from "./math.like";
3+
import type { IQuaternionLike, IVector2Like, IVector3Like, IVector4Like } from "./math.like";
44
import { Quaternion, Vector3 } from "./math.vector";
55

6-
function SetDirtyFlag(x: IDirtyFlagLike) {
7-
if (x._isDirty !== undefined) {
8-
x._isDirty = true;
9-
}
10-
}
11-
126
/**
137
* Creates a string representation of the IVector2Like
148
* @param vector defines the IVector2Like to stringify
@@ -72,49 +66,43 @@ export function Vector3Distance(a: DeepImmutable<IVector3Like>, b: DeepImmutable
7266

7367
/**
7468
* Sets the given floats into the result.
75-
* Marks the result as dirty if an `_isDirty` flag is defined on the object.
7669
* @param x defines the x coordinate
7770
* @param y defines the y coordinate
7871
* @param z defines the z coordinate
79-
* @param result defines the target vector
72+
* @param result defines the result vector
8073
* @returns the result vector
8174
*/
82-
export function Vector3FromFloatsToRef<T extends IVector3Like & IDirtyFlagLike>(x: number, y: number, z: number, result: T): T {
75+
export function Vector3FromFloatsToRef<T extends IVector3Like>(x: number, y: number, z: number, result: T): T {
8376
result.x = x;
8477
result.y = y;
8578
result.z = z;
86-
SetDirtyFlag(result);
8779
return result;
8880
}
8981

9082
/**
9183
* Stores the scaled values of a vector into the result.
92-
* Marks the result as dirty if an `_isDirty` flag is defined on the object.
9384
* @param a defines the source vector
9485
* @param scale defines the scale factor
95-
* @param result defines the target vector
86+
* @param result defines the result vector
9687
* @returns the scaled vector
9788
*/
98-
export function Vector3ScaleToRef<T extends IVector3Like & IDirtyFlagLike>(a: DeepImmutable<IVector3Like>, scale: number, result: T): T {
89+
export function Vector3ScaleToRef<T extends IVector3Like>(a: DeepImmutable<IVector3Like>, scale: number, result: T): T {
9990
result.x = a.x * scale;
10091
result.y = a.y * scale;
10192
result.z = a.z * scale;
102-
SetDirtyFlag(result);
10393
return result;
10494
}
10595

10696
/**
10797
* Scales the current vector values in place by a factor.
108-
* Marks the result as dirty if an `_isDirty` flag is defined on the object.
10998
* @param vector defines the vector to scale
11099
* @param scale defines the scale factor
111-
* @returns the input scaled vector
100+
* @returns the scaled vector
112101
*/
113-
export function Vector3ScaleInPlace<T extends IVector3Like & IDirtyFlagLike>(vector: T, scale: number): T {
102+
export function Vector3ScaleInPlace<T extends IVector3Like>(vector: T, scale: number): T {
114103
vector.x *= scale;
115104
vector.y *= scale;
116105
vector.z *= scale;
117-
SetDirtyFlag(vector);
118106
return vector;
119107
}
120108

packages/dev/core/test/unit/Math/babylon.math.vector.functions.test.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,26 @@ import { Vector3FromFloatsToRef, Vector3ScaleInPlace, Vector3ScaleToRef } from "
22

33
describe("Vector functions tests", () => {
44
describe("Vector3", () => {
5-
it("writes floats into result and honors dirty flag", () => {
6-
const target = { x: 0, y: 0, z: 0, _isDirty: false };
7-
const result = Vector3FromFloatsToRef(7, 8, 9, target);
8-
expect(result).toBe(target);
9-
expect(target).toEqual({ x: 7, y: 8, z: 9, _isDirty: true });
10-
});
11-
12-
it("does not create a dirty flag when one is absent", () => {
5+
it("writes floats into result", () => {
136
const target = { x: 0, y: 0, z: 0 };
14-
const result = Vector3FromFloatsToRef(1, 2, 3, target);
7+
const result = Vector3FromFloatsToRef(7, 8, 9, target);
158
expect(result).toBe(target);
16-
expect(Object.prototype.hasOwnProperty.call(target, "_isDirty")).toBe(false);
9+
expect(target).toEqual({ x: 7, y: 8, z: 9 });
1710
});
1811

19-
it("scales to ref and sets the dirty flag", () => {
12+
it("scales to ref", () => {
2013
const target = { x: 1, y: 2, z: 3 };
21-
const result = Vector3ScaleToRef(target, 2, { x: 0, y: 0, z: 0, _isDirty: false });
14+
const result = Vector3ScaleToRef(target, 2, { x: 0, y: 0, z: 0 });
2215
expect(result).not.toBe(target);
2316
expect(target).toEqual({ x: 1, y: 2, z: 3 });
24-
expect(result).toEqual({ x: 2, y: 4, z: 6, _isDirty: true });
17+
expect(result).toEqual({ x: 2, y: 4, z: 6 });
2518
});
2619

27-
it("scales in place and sets the dirty flag", () => {
28-
const vector = { x: -1, y: 2, z: -3, _isDirty: false };
20+
it("scales in place", () => {
21+
const vector = { x: -1, y: 2, z: -3 };
2922
const result = Vector3ScaleInPlace(vector, 3);
3023
expect(result).toBe(vector);
31-
expect(vector).toEqual({ x: -3, y: 6, z: -9, _isDirty: true });
24+
expect(vector).toEqual({ x: -3, y: 6, z: -9 });
3225
});
3326
});
3427
});

0 commit comments

Comments
 (0)