Skip to content

Commit

Permalink
fix: incongruent behavior as small scales when setting `transform.sca…
Browse files Browse the repository at this point in the history
…le = v` and `transform.scale.setTo(x, y)`
  • Loading branch information
eonarheim committed Mar 1, 2024
1 parent 947aa90 commit 2bf225a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added `GraphicsComponent.bounds` which will report the world bounds of the graphic if applicable!
- Added `ex.Vector.EQUALS_EPSILON` to configure the `ex.Vector.equals(v)` threshold

### Fixed

- Fixed incongruent behavior as small scales when setting `transform.scale = v` and `transform.scale.setTo(x, y)`
- Fixed `ex.coroutine` TypeScript type to include yielding `undefined`
- Fixed issue where Firefox on Linux would throw an error when using custom Materials due to unused attributes caused by glsl compiler optimization.
- Fixed issue where start transition did not work properly if deferred
- Fixed issue where transitions did not cover the whole screen if camera was zoomed
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Math/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class Transform {

private _scale: Vector = vec(1, 1);
set scale(v: Vector) {
if (!v.equals(this._scale)) {
if (v.x !== this._scale.x || v.y !== this._scale.y) {
this._scale.x = v.x;
this._scale.y = v.y;
this.flagDirty();
Expand Down
6 changes: 5 additions & 1 deletion src/engine/Math/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { clamp } from './util';
*/

export class Vector implements Clonable<Vector> {
/**
* Get or set the vector equals epsilon, by default 0.001 meaning vectors within that tolerance on x or y will be considered equal.
*/
public static EQUALS_EPSILON = .001;
/**
* A (0, 0) vector
*/
Expand Down Expand Up @@ -152,7 +156,7 @@ export class Vector implements Clonable<Vector> {
* @param vector The other point to compare to
* @param tolerance Amount of euclidean distance off we are willing to tolerate
*/
public equals(vector: Vector, tolerance: number = 0.001): boolean {
public equals(vector: Vector, tolerance: number = Vector.EQUALS_EPSILON): boolean {
return Math.abs(this.x - vector.x) <= tolerance && Math.abs(this.y - vector.y) <= tolerance;
}

Expand Down

0 comments on commit 2bf225a

Please sign in to comment.