Skip to content

Commit

Permalink
Add internal PIXI.Point._invertKey method
Browse files Browse the repository at this point in the history
Used when inverting non x,y keys. Such as grid offsets.
  • Loading branch information
caewok committed Jun 11, 2024
1 parent a0e49a7 commit 23173f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.3.4
Handle Wall, Edge classes in Draw.segment.
Add an internal PIXI.Point.invert that returns object, for non-keys.

## 0.3.3
Switch to using TextureLoader.getTextureAlphaData.
Expand Down
12 changes: 9 additions & 3 deletions PIXI/Point.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ PIXI.Point._tmp3 = new PIXI.Point();
* @param {number} key Integer key
* @returns {PIXI.Point} coordinates
*/
function invertKey(key) {
function invertKey(key, outPoint) {
outPoint ??= new this();
return outPoint.copyFrom(this._invertKey(key));
}

function _invertKey(key) {
const x = Math.floor(key * MAX_TEXTURE_SIZE_INV);
const y = key - (MAX_TEXTURE_SIZE * x);
return new PIXI.Point(x, y);
return { x, y };
}

/**
Expand Down Expand Up @@ -431,7 +436,8 @@ PATCHES.PIXI.STATIC_METHODS = {
angleBetween,
flatMapPoints,
fromObject,
invertKey
invertKey,
_invertKey
};

PATCHES.PIXI.METHODS = {
Expand Down

0 comments on commit 23173f2

Please sign in to comment.