@pixi-essentials/area-allocator
Advanced tools
Comparing version 2.0.0 to 3.0.0
/* eslint-disable */ | ||
/*! | ||
* @pixi-essentials/area-allocator - v2.0.0 | ||
* Compiled Sun, 05 Mar 2023 04:38:13 UTC | ||
* @pixi-essentials/area-allocator - v3.0.0 | ||
* Compiled Tue, 08 Oct 2024 01:10:18 UTC | ||
* | ||
@@ -14,20 +14,21 @@ * @pixi-essentials/area-allocator is licensed under the MIT License. | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pixi/math')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@pixi/math'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('pixi.js')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'pixi.js'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global._pixi_essentials_area_allocator = {}, global.PIXI)); | ||
}(this, (function (exports, math) { 'use strict'; | ||
}(this, (function (exports, pixi_js) { 'use strict'; | ||
/** | ||
* The orientation of an area indicates the axis along which it is split. This is a 1-bit field. | ||
* | ||
* | ||
* @public | ||
*/ | ||
(function (AreaOrientation) { | ||
(function (AreaOrientation) | ||
{ | ||
const HORIZONTAL = 0; AreaOrientation[AreaOrientation["HORIZONTAL"] = HORIZONTAL] = "HORIZONTAL"; | ||
const VERTICAL = 1; AreaOrientation[AreaOrientation["VERTICAL"] = VERTICAL] = "VERTICAL"; | ||
})(exports.AreaOrientation || (exports.AreaOrientation = {}));; | ||
})(exports.AreaOrientation || (exports.AreaOrientation = {})); | ||
/** | ||
* Alias for the 31-bit field texture-area type. | ||
* | ||
* | ||
* @public | ||
@@ -42,9 +43,9 @@ */ | ||
* children will be along its own orientation axis. | ||
* | ||
* | ||
* The orientation axes flip-flop along the hierarchy, i.e. an area's parent's orientation is always opposite to | ||
* the area's own orientation. This is because if the orientation were to be same, the area's children could be | ||
* "pulled up" to the parent making itself redundant. | ||
* | ||
* | ||
* All four edges of an area can be retrieved from it and its parent. | ||
* | ||
* | ||
* <table> | ||
@@ -85,3 +86,3 @@ * <thead> | ||
* </table> | ||
* | ||
* | ||
* @public | ||
@@ -135,3 +136,4 @@ */ | ||
(function (SPLIT_ORIENTATION) { | ||
(function (SPLIT_ORIENTATION) | ||
{ | ||
const HOR = 0; SPLIT_ORIENTATION[SPLIT_ORIENTATION["HOR"] = HOR] = "HOR"; | ||
@@ -142,3 +144,3 @@ const VERT = 1; SPLIT_ORIENTATION[SPLIT_ORIENTATION["VERT"] = VERT] = "VERT"; | ||
const tempRect = new math.Rectangle(); | ||
const tempRect = new pixi_js.Rectangle(); | ||
@@ -185,3 +187,3 @@ /** @public */ | ||
{ | ||
rect = new math.Rectangle(); | ||
rect = new pixi_js.Rectangle(); | ||
} | ||
@@ -191,6 +193,7 @@ | ||
const hole = new math.Rectangle(rect.x, rect.y, width, height); | ||
const hole = new pixi_js.Rectangle(rect.x, rect.y, width, height); | ||
const node = this.split(area, rect, hole); | ||
rect.copyFrom(hole); | ||
// eslint-disable-next-line camelcase | ||
(rect ).__mem_area = node; | ||
@@ -205,3 +208,3 @@ | ||
* | ||
* @param areaPtr | ||
* @param areaPtr | ||
*/ | ||
@@ -229,3 +232,3 @@ free(areaPtr) | ||
* | ||
* @param node | ||
* @param node | ||
* @returns The area data for the node. | ||
@@ -249,3 +252,3 @@ */ | ||
{ | ||
rect = new math.Rectangle(); | ||
rect = new pixi_js.Rectangle(); | ||
} | ||
@@ -259,3 +262,4 @@ | ||
const parentOpen = nodeParent ? Area.getOpenOffset(nodeParent[1]) : 0; | ||
const parentClose = nodeParent ? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
const parentClose = nodeParent | ||
? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
@@ -268,3 +272,3 @@ if (nodeOrientation) // VERTICAL | ||
rect.height = parentClose - parentOpen; | ||
} | ||
} | ||
else // HORIZONTAL | ||
@@ -284,3 +288,3 @@ { | ||
* | ||
* @param node | ||
* @param node | ||
* @return The parent of `node` | ||
@@ -296,3 +300,3 @@ */ | ||
* | ||
* @param node | ||
* @param node | ||
* @return Whether the given node has any children. | ||
@@ -312,4 +316,5 @@ */ | ||
{ | ||
if (!Array.isArray(node[2])) { | ||
throw new Error("Children don't exist") | ||
if (!Array.isArray(node[2])) | ||
{ | ||
throw new Error('Children don\'t exist'); | ||
} | ||
@@ -329,4 +334,4 @@ | ||
* | ||
* @param aw | ||
* @param ah | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -341,5 +346,5 @@ findArea(aw, ah) | ||
* | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -414,9 +419,12 @@ findAreaRecursive(rootArea, aw, ah) | ||
{ | ||
if (hole.width === host.width && hole.height === host.height) { | ||
if (hole.width === host.width && hole.height === host.height) | ||
{ | ||
return exports.SPLIT_ORIENTATION.NONE; | ||
} | ||
if (hole.width === host.width) { | ||
if (hole.width === host.width) | ||
{ | ||
return exports.SPLIT_ORIENTATION.VERT; | ||
} | ||
if (hole.height === host.height) { | ||
if (hole.height === host.height) | ||
{ | ||
return exports.SPLIT_ORIENTATION.HOR; | ||
@@ -437,6 +445,6 @@ } | ||
// (Primary) Right | ||
(host.width - hole.width) * host.height - | ||
((host.width - hole.width) * host.height) | ||
// (Secondary) Bottom | ||
hole.width * (host.height - hole.height) | ||
); | ||
- (hole.width * (host.height - hole.height)) | ||
); | ||
@@ -454,4 +462,4 @@ // ____________________ | ||
// (Primary) Bottom | ||
host.width * (host.height - hole.height) - | ||
(host.width - hole.width) * hole.height | ||
(host.width * (host.height - hole.height)) | ||
- ((host.width - hole.width) * hole.height) | ||
); | ||
@@ -461,8 +469,6 @@ | ||
{ | ||
return exports.SPLIT_ORIENTATION.HOR | ||
} | ||
else | ||
{ | ||
return exports.SPLIT_ORIENTATION.VERT | ||
return exports.SPLIT_ORIENTATION.HOR; | ||
} | ||
return exports.SPLIT_ORIENTATION.VERT; | ||
} | ||
@@ -474,8 +480,9 @@ | ||
holeFrame, | ||
orientation = this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : exports.SPLIT_ORIENTATION.HOR | ||
orientation = | ||
this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : exports.SPLIT_ORIENTATION.HOR | ||
) | ||
{ | ||
if (area[2] === true) | ||
if (area[2] === true) | ||
{ | ||
throw new Error('Cannot deallocate') | ||
throw new Error('Cannot deallocate'); | ||
} | ||
@@ -485,7 +492,8 @@ if (orientation === exports.SPLIT_ORIENTATION.NONE) | ||
area[2] = true; | ||
return area; | ||
} | ||
return this[orientation === exports.SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
return this[orientation === exports.SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
: 'splitPrimaryVertical'](area, areaFrame, holeFrame); | ||
@@ -502,3 +510,3 @@ } | ||
{ | ||
throw new Error("Can't split non-leaf node") | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -518,4 +526,4 @@ | ||
Area.makeArea( | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
exports.AreaOrientation.VERTICAL | ||
@@ -526,5 +534,8 @@ ), | ||
if (axis === exports.AreaOrientation.HORIZONTAL) { | ||
if (axis === exports.AreaOrientation.HORIZONTAL) | ||
{ | ||
this.addChild(area, firstChild, secondChild); | ||
} else { | ||
} | ||
else | ||
{ | ||
const i = this.getChildren(parent).indexOf(area); | ||
@@ -563,7 +574,5 @@ | ||
} | ||
else | ||
{ | ||
(firstChild )[2] = true; | ||
} | ||
(firstChild )[2] = true; | ||
return firstChild; | ||
@@ -578,4 +587,5 @@ } | ||
if (this.hasChildren(area)) { | ||
throw new Error("Can't split non-leaf node") | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -602,3 +612,3 @@ | ||
if (axis === exports.AreaOrientation.VERTICAL) | ||
if (axis === exports.AreaOrientation.VERTICAL) | ||
{ | ||
@@ -610,2 +620,3 @@ this.addChild(area, primaryFirstChild, primarySecondChild); | ||
const i = this.getChildren(parent).indexOf(area); | ||
primaryFirstChild[0] = parent; | ||
@@ -641,7 +652,5 @@ primarySecondChild[0] = parent; | ||
} | ||
else | ||
{ | ||
(primaryFirstChild )[2] = true; | ||
} | ||
(primaryFirstChild )[2] = true; | ||
return primaryFirstChild; | ||
@@ -652,6 +661,7 @@ } | ||
area | ||
) { | ||
) | ||
{ | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error("Cannot merge a non-leaf node"); | ||
throw new Error('Cannot merge a non-leaf node'); | ||
} | ||
@@ -685,3 +695,4 @@ | ||
if (siblings.length === 1) { | ||
if (siblings.length === 1) | ||
{ | ||
parent[2] = false; | ||
@@ -691,11 +702,2 @@ this.merge(parent); | ||
} | ||
printState(area) | ||
{ | ||
if (!this.hasChildren(area)) { | ||
console.log({ ...this.getFrame(area) }, area[2]); | ||
} else { | ||
this.getChildren(area).forEach(n => this.printState(n)); | ||
} | ||
} | ||
} | ||
@@ -702,0 +704,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Rectangle } from '@pixi/math'; | ||
import { Rectangle } from 'pixi.js'; | ||
@@ -194,3 +194,2 @@ /** | ||
protected merge(area: AreaNode): void; | ||
private printState; | ||
} | ||
@@ -197,0 +196,0 @@ |
/* eslint-disable */ | ||
/*! | ||
* @pixi-essentials/area-allocator - v2.0.0 | ||
* Compiled Sun, 05 Mar 2023 04:38:13 UTC | ||
* @pixi-essentials/area-allocator - v3.0.0 | ||
* Compiled Tue, 08 Oct 2024 01:10:18 UTC | ||
* | ||
@@ -12,16 +12,18 @@ * @pixi-essentials/area-allocator is licensed under the MIT License. | ||
*/ | ||
import { Rectangle } from '@pixi/math'; | ||
import { Rectangle } from 'pixi.js'; | ||
/** | ||
* The orientation of an area indicates the axis along which it is split. This is a 1-bit field. | ||
* | ||
* | ||
* @public | ||
*/ | ||
var AreaOrientation; (function (AreaOrientation) { | ||
var AreaOrientation; (function (AreaOrientation) | ||
{ | ||
const HORIZONTAL = 0; AreaOrientation[AreaOrientation["HORIZONTAL"] = HORIZONTAL] = "HORIZONTAL"; | ||
const VERTICAL = 1; AreaOrientation[AreaOrientation["VERTICAL"] = VERTICAL] = "VERTICAL"; | ||
})(AreaOrientation || (AreaOrientation = {})); | ||
/** | ||
* Alias for the 31-bit field texture-area type. | ||
* | ||
* | ||
* @public | ||
@@ -36,9 +38,9 @@ */ | ||
* children will be along its own orientation axis. | ||
* | ||
* | ||
* The orientation axes flip-flop along the hierarchy, i.e. an area's parent's orientation is always opposite to | ||
* the area's own orientation. This is because if the orientation were to be same, the area's children could be | ||
* "pulled up" to the parent making itself redundant. | ||
* | ||
* | ||
* All four edges of an area can be retrieved from it and its parent. | ||
* | ||
* | ||
* <table> | ||
@@ -79,3 +81,3 @@ * <thead> | ||
* </table> | ||
* | ||
* | ||
* @public | ||
@@ -125,3 +127,3 @@ */ | ||
/** | ||
* An allocator node is represented as a tuple. The zeroth element is the parent of the node. The first element | ||
* An allocator node is represented as a tuple. The zeroth element is the parent of the node. The first element | ||
* always exists and is the texture area it wholly represents. The second element is whether the rectangle | ||
@@ -144,2 +146,3 @@ * is allocated or free. The last element is optional and is the list | ||
/** | ||
@@ -149,3 +152,4 @@ * @public | ||
*/ | ||
var SPLIT_ORIENTATION; (function (SPLIT_ORIENTATION) { | ||
var SPLIT_ORIENTATION; (function (SPLIT_ORIENTATION) | ||
{ | ||
const HOR = 0; SPLIT_ORIENTATION[SPLIT_ORIENTATION["HOR"] = HOR] = "HOR"; | ||
@@ -207,2 +211,3 @@ const VERT = 1; SPLIT_ORIENTATION[SPLIT_ORIENTATION["VERT"] = VERT] = "VERT"; | ||
rect.copyFrom(hole); | ||
// eslint-disable-next-line camelcase | ||
(rect ).__mem_area = node; | ||
@@ -217,3 +222,3 @@ | ||
* | ||
* @param areaPtr | ||
* @param areaPtr | ||
*/ | ||
@@ -241,3 +246,3 @@ free(areaPtr) | ||
* | ||
* @param node | ||
* @param node | ||
* @returns The area data for the node. | ||
@@ -270,3 +275,4 @@ */ | ||
const parentOpen = nodeParent ? Area.getOpenOffset(nodeParent[1]) : 0; | ||
const parentClose = nodeParent ? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
const parentClose = nodeParent | ||
? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
@@ -279,3 +285,3 @@ if (nodeOrientation) // VERTICAL | ||
rect.height = parentClose - parentOpen; | ||
} | ||
} | ||
else // HORIZONTAL | ||
@@ -295,3 +301,3 @@ { | ||
* | ||
* @param node | ||
* @param node | ||
* @return The parent of `node` | ||
@@ -307,3 +313,3 @@ */ | ||
* | ||
* @param node | ||
* @param node | ||
* @return Whether the given node has any children. | ||
@@ -323,4 +329,5 @@ */ | ||
{ | ||
if (!Array.isArray(node[2])) { | ||
throw new Error("Children don't exist") | ||
if (!Array.isArray(node[2])) | ||
{ | ||
throw new Error('Children don\'t exist'); | ||
} | ||
@@ -340,4 +347,4 @@ | ||
* | ||
* @param aw | ||
* @param ah | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -352,5 +359,5 @@ findArea(aw, ah) | ||
* | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -425,9 +432,12 @@ findAreaRecursive(rootArea, aw, ah) | ||
{ | ||
if (hole.width === host.width && hole.height === host.height) { | ||
if (hole.width === host.width && hole.height === host.height) | ||
{ | ||
return SPLIT_ORIENTATION.NONE; | ||
} | ||
if (hole.width === host.width) { | ||
if (hole.width === host.width) | ||
{ | ||
return SPLIT_ORIENTATION.VERT; | ||
} | ||
if (hole.height === host.height) { | ||
if (hole.height === host.height) | ||
{ | ||
return SPLIT_ORIENTATION.HOR; | ||
@@ -448,6 +458,6 @@ } | ||
// (Primary) Right | ||
(host.width - hole.width) * host.height - | ||
((host.width - hole.width) * host.height) | ||
// (Secondary) Bottom | ||
hole.width * (host.height - hole.height) | ||
); | ||
- (hole.width * (host.height - hole.height)) | ||
); | ||
@@ -465,4 +475,4 @@ // ____________________ | ||
// (Primary) Bottom | ||
host.width * (host.height - hole.height) - | ||
(host.width - hole.width) * hole.height | ||
(host.width * (host.height - hole.height)) | ||
- ((host.width - hole.width) * hole.height) | ||
); | ||
@@ -472,8 +482,6 @@ | ||
{ | ||
return SPLIT_ORIENTATION.HOR | ||
} | ||
else | ||
{ | ||
return SPLIT_ORIENTATION.VERT | ||
return SPLIT_ORIENTATION.HOR; | ||
} | ||
return SPLIT_ORIENTATION.VERT; | ||
} | ||
@@ -485,8 +493,9 @@ | ||
holeFrame, | ||
orientation = this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : SPLIT_ORIENTATION.HOR | ||
orientation = | ||
this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : SPLIT_ORIENTATION.HOR | ||
) | ||
{ | ||
if (area[2] === true) | ||
if (area[2] === true) | ||
{ | ||
throw new Error('Cannot deallocate') | ||
throw new Error('Cannot deallocate'); | ||
} | ||
@@ -496,7 +505,8 @@ if (orientation === SPLIT_ORIENTATION.NONE) | ||
area[2] = true; | ||
return area; | ||
} | ||
return this[orientation === SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
return this[orientation === SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
: 'splitPrimaryVertical'](area, areaFrame, holeFrame); | ||
@@ -513,3 +523,3 @@ } | ||
{ | ||
throw new Error("Can't split non-leaf node") | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -529,4 +539,4 @@ | ||
Area.makeArea( | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
AreaOrientation.VERTICAL | ||
@@ -537,5 +547,8 @@ ), | ||
if (axis === AreaOrientation.HORIZONTAL) { | ||
if (axis === AreaOrientation.HORIZONTAL) | ||
{ | ||
this.addChild(area, firstChild, secondChild); | ||
} else { | ||
} | ||
else | ||
{ | ||
const i = this.getChildren(parent).indexOf(area); | ||
@@ -574,7 +587,5 @@ | ||
} | ||
else | ||
{ | ||
(firstChild )[2] = true; | ||
} | ||
(firstChild )[2] = true; | ||
return firstChild; | ||
@@ -589,4 +600,5 @@ } | ||
if (this.hasChildren(area)) { | ||
throw new Error("Can't split non-leaf node") | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -613,3 +625,3 @@ | ||
if (axis === AreaOrientation.VERTICAL) | ||
if (axis === AreaOrientation.VERTICAL) | ||
{ | ||
@@ -621,2 +633,3 @@ this.addChild(area, primaryFirstChild, primarySecondChild); | ||
const i = this.getChildren(parent).indexOf(area); | ||
primaryFirstChild[0] = parent; | ||
@@ -652,7 +665,5 @@ primarySecondChild[0] = parent; | ||
} | ||
else | ||
{ | ||
(primaryFirstChild )[2] = true; | ||
} | ||
(primaryFirstChild )[2] = true; | ||
return primaryFirstChild; | ||
@@ -663,6 +674,7 @@ } | ||
area | ||
) { | ||
) | ||
{ | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error("Cannot merge a non-leaf node"); | ||
throw new Error('Cannot merge a non-leaf node'); | ||
} | ||
@@ -696,3 +708,4 @@ | ||
if (siblings.length === 1) { | ||
if (siblings.length === 1) | ||
{ | ||
parent[2] = false; | ||
@@ -702,11 +715,2 @@ this.merge(parent); | ||
} | ||
printState(area) | ||
{ | ||
if (!this.hasChildren(area)) { | ||
console.log({ ...this.getFrame(area) }, area[2]); | ||
} else { | ||
this.getChildren(area).forEach(n => this.printState(n)); | ||
} | ||
} | ||
} | ||
@@ -713,0 +717,0 @@ |
/* eslint-disable */ | ||
/*! | ||
* @pixi-essentials/area-allocator - v2.0.0 | ||
* Compiled Sun, 05 Mar 2023 04:38:13 UTC | ||
* @pixi-essentials/area-allocator - v3.0.0 | ||
* Compiled Tue, 08 Oct 2024 01:10:18 UTC | ||
* | ||
@@ -16,16 +16,18 @@ * @pixi-essentials/area-allocator is licensed under the MIT License. | ||
var math = require('@pixi/math'); | ||
var pixi_js = require('pixi.js'); | ||
/** | ||
* The orientation of an area indicates the axis along which it is split. This is a 1-bit field. | ||
* | ||
* | ||
* @public | ||
*/ | ||
(function (AreaOrientation) { | ||
(function (AreaOrientation) | ||
{ | ||
const HORIZONTAL = 0; AreaOrientation[AreaOrientation["HORIZONTAL"] = HORIZONTAL] = "HORIZONTAL"; | ||
const VERTICAL = 1; AreaOrientation[AreaOrientation["VERTICAL"] = VERTICAL] = "VERTICAL"; | ||
})(exports.AreaOrientation || (exports.AreaOrientation = {})); | ||
/** | ||
* Alias for the 31-bit field texture-area type. | ||
* | ||
* | ||
* @public | ||
@@ -40,9 +42,9 @@ */ | ||
* children will be along its own orientation axis. | ||
* | ||
* | ||
* The orientation axes flip-flop along the hierarchy, i.e. an area's parent's orientation is always opposite to | ||
* the area's own orientation. This is because if the orientation were to be same, the area's children could be | ||
* "pulled up" to the parent making itself redundant. | ||
* | ||
* | ||
* All four edges of an area can be retrieved from it and its parent. | ||
* | ||
* | ||
* <table> | ||
@@ -83,3 +85,3 @@ * <thead> | ||
* </table> | ||
* | ||
* | ||
* @public | ||
@@ -128,3 +130,4 @@ */ | ||
(function (SPLIT_ORIENTATION) { | ||
(function (SPLIT_ORIENTATION) | ||
{ | ||
const HOR = 0; SPLIT_ORIENTATION[SPLIT_ORIENTATION["HOR"] = HOR] = "HOR"; | ||
@@ -135,3 +138,3 @@ const VERT = 1; SPLIT_ORIENTATION[SPLIT_ORIENTATION["VERT"] = VERT] = "VERT"; | ||
const tempRect = new math.Rectangle(); | ||
const tempRect = new pixi_js.Rectangle(); | ||
@@ -178,3 +181,3 @@ /** @public */ | ||
{ | ||
rect = new math.Rectangle(); | ||
rect = new pixi_js.Rectangle(); | ||
} | ||
@@ -184,6 +187,7 @@ | ||
const hole = new math.Rectangle(rect.x, rect.y, width, height); | ||
const hole = new pixi_js.Rectangle(rect.x, rect.y, width, height); | ||
const node = this.split(area, rect, hole); | ||
rect.copyFrom(hole); | ||
// eslint-disable-next-line camelcase | ||
(rect ).__mem_area = node; | ||
@@ -198,3 +202,3 @@ | ||
* | ||
* @param areaPtr | ||
* @param areaPtr | ||
*/ | ||
@@ -222,3 +226,3 @@ free(areaPtr) | ||
* | ||
* @param node | ||
* @param node | ||
* @returns The area data for the node. | ||
@@ -242,3 +246,3 @@ */ | ||
{ | ||
rect = new math.Rectangle(); | ||
rect = new pixi_js.Rectangle(); | ||
} | ||
@@ -252,3 +256,4 @@ | ||
const parentOpen = nodeParent ? Area.getOpenOffset(nodeParent[1]) : 0; | ||
const parentClose = nodeParent ? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
const parentClose = nodeParent | ||
? Area.getCloseOffset(nodeParent[1]) : this._width;// (because root node is horizontal) | ||
@@ -261,3 +266,3 @@ if (nodeOrientation) // VERTICAL | ||
rect.height = parentClose - parentOpen; | ||
} | ||
} | ||
else // HORIZONTAL | ||
@@ -277,3 +282,3 @@ { | ||
* | ||
* @param node | ||
* @param node | ||
* @return The parent of `node` | ||
@@ -289,3 +294,3 @@ */ | ||
* | ||
* @param node | ||
* @param node | ||
* @return Whether the given node has any children. | ||
@@ -305,4 +310,5 @@ */ | ||
{ | ||
if (!Array.isArray(node[2])) { | ||
throw new Error("Children don't exist") | ||
if (!Array.isArray(node[2])) | ||
{ | ||
throw new Error('Children don\'t exist'); | ||
} | ||
@@ -322,4 +328,4 @@ | ||
* | ||
* @param aw | ||
* @param ah | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -334,5 +340,5 @@ findArea(aw, ah) | ||
* | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
* @param rootArea | ||
* @param aw | ||
* @param ah | ||
*/ | ||
@@ -407,9 +413,12 @@ findAreaRecursive(rootArea, aw, ah) | ||
{ | ||
if (hole.width === host.width && hole.height === host.height) { | ||
if (hole.width === host.width && hole.height === host.height) | ||
{ | ||
return exports.SPLIT_ORIENTATION.NONE; | ||
} | ||
if (hole.width === host.width) { | ||
if (hole.width === host.width) | ||
{ | ||
return exports.SPLIT_ORIENTATION.VERT; | ||
} | ||
if (hole.height === host.height) { | ||
if (hole.height === host.height) | ||
{ | ||
return exports.SPLIT_ORIENTATION.HOR; | ||
@@ -430,6 +439,6 @@ } | ||
// (Primary) Right | ||
(host.width - hole.width) * host.height - | ||
((host.width - hole.width) * host.height) | ||
// (Secondary) Bottom | ||
hole.width * (host.height - hole.height) | ||
); | ||
- (hole.width * (host.height - hole.height)) | ||
); | ||
@@ -447,4 +456,4 @@ // ____________________ | ||
// (Primary) Bottom | ||
host.width * (host.height - hole.height) - | ||
(host.width - hole.width) * hole.height | ||
(host.width * (host.height - hole.height)) | ||
- ((host.width - hole.width) * hole.height) | ||
); | ||
@@ -454,8 +463,6 @@ | ||
{ | ||
return exports.SPLIT_ORIENTATION.HOR | ||
} | ||
else | ||
{ | ||
return exports.SPLIT_ORIENTATION.VERT | ||
return exports.SPLIT_ORIENTATION.HOR; | ||
} | ||
return exports.SPLIT_ORIENTATION.VERT; | ||
} | ||
@@ -467,8 +474,9 @@ | ||
holeFrame, | ||
orientation = this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : exports.SPLIT_ORIENTATION.HOR | ||
orientation = | ||
this.getParent(area) ? this.splitOrientation(areaFrame, holeFrame) : exports.SPLIT_ORIENTATION.HOR | ||
) | ||
{ | ||
if (area[2] === true) | ||
if (area[2] === true) | ||
{ | ||
throw new Error('Cannot deallocate') | ||
throw new Error('Cannot deallocate'); | ||
} | ||
@@ -478,7 +486,8 @@ if (orientation === exports.SPLIT_ORIENTATION.NONE) | ||
area[2] = true; | ||
return area; | ||
} | ||
return this[orientation === exports.SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
return this[orientation === exports.SPLIT_ORIENTATION.HOR | ||
? 'splitPrimaryHorizontal' | ||
: 'splitPrimaryVertical'](area, areaFrame, holeFrame); | ||
@@ -495,3 +504,3 @@ } | ||
{ | ||
throw new Error("Can't split non-leaf node") | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -511,4 +520,4 @@ | ||
Area.makeArea( | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
areaFrame.x + holeFrame.width, | ||
areaFrame.right, | ||
exports.AreaOrientation.VERTICAL | ||
@@ -519,5 +528,8 @@ ), | ||
if (axis === exports.AreaOrientation.HORIZONTAL) { | ||
if (axis === exports.AreaOrientation.HORIZONTAL) | ||
{ | ||
this.addChild(area, firstChild, secondChild); | ||
} else { | ||
} | ||
else | ||
{ | ||
const i = this.getChildren(parent).indexOf(area); | ||
@@ -556,7 +568,5 @@ | ||
} | ||
else | ||
{ | ||
(firstChild )[2] = true; | ||
} | ||
(firstChild )[2] = true; | ||
return firstChild; | ||
@@ -571,4 +581,5 @@ } | ||
if (this.hasChildren(area)) { | ||
throw new Error("Can't split non-leaf node") | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error('Can\'t split non-leaf node'); | ||
} | ||
@@ -595,3 +606,3 @@ | ||
if (axis === exports.AreaOrientation.VERTICAL) | ||
if (axis === exports.AreaOrientation.VERTICAL) | ||
{ | ||
@@ -603,2 +614,3 @@ this.addChild(area, primaryFirstChild, primarySecondChild); | ||
const i = this.getChildren(parent).indexOf(area); | ||
primaryFirstChild[0] = parent; | ||
@@ -634,7 +646,5 @@ primarySecondChild[0] = parent; | ||
} | ||
else | ||
{ | ||
(primaryFirstChild )[2] = true; | ||
} | ||
(primaryFirstChild )[2] = true; | ||
return primaryFirstChild; | ||
@@ -645,6 +655,7 @@ } | ||
area | ||
) { | ||
) | ||
{ | ||
if (this.hasChildren(area)) | ||
{ | ||
throw new Error("Cannot merge a non-leaf node"); | ||
throw new Error('Cannot merge a non-leaf node'); | ||
} | ||
@@ -678,3 +689,4 @@ | ||
if (siblings.length === 1) { | ||
if (siblings.length === 1) | ||
{ | ||
parent[2] = false; | ||
@@ -684,11 +696,2 @@ this.merge(parent); | ||
} | ||
printState(area) | ||
{ | ||
if (!this.hasChildren(area)) { | ||
console.log({ ...this.getFrame(area) }, area[2]); | ||
} else { | ||
this.getChildren(area).forEach(n => this.printState(n)); | ||
} | ||
} | ||
} | ||
@@ -695,0 +698,0 @@ |
{ | ||
"name": "@pixi-essentials/area-allocator", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Efficient texture area allocator for on-demand atlases", | ||
@@ -10,8 +10,4 @@ "main": "lib/area-allocator.js", | ||
"peerDependencies": { | ||
"@pixi/math": "^7.0.0" | ||
"pixi.js": "^8.4.0" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c node_modules/@pixi-build-tools/rollup-configurator/index.js --silent", | ||
"build:types": "rm -rf compile && tsc && api-extractor run" | ||
}, | ||
"repository": { | ||
@@ -42,8 +38,13 @@ "type": "git", | ||
"eslint": "~7.13.0", | ||
"typescript": "~4.0.5", | ||
"typescript": "~5.3.3", | ||
"tslib": "~2.0.3", | ||
"@pixi-build-tools/rollup-configurator": "^1.0.10", | ||
"chai": "~4.2.0", | ||
"@microsoft/api-extractor": "~7.16.1" | ||
"@microsoft/api-extractor": "~7.47.9" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c node_modules/@pixi-build-tools/rollup-configurator/index.js --silent", | ||
"build:types": "rm -rf compile index.d.ts && tsc && api-extractor run && rm -rf compile", | ||
"lint": "eslint --ext .ts,.js src/ test/" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
132573
1933