mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
JSDoc complete type check
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import OrderedIndexArray from "./OrderedIndexArray"
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* primaryInf: Number,
|
||||
* primarySup: Number,
|
||||
* secondaryInf: Number,
|
||||
* secondarySup: Number
|
||||
* }} BoundariesInfo
|
||||
* @typedef {import("../Blueprint").BoundariesInfo} BoundariesInfo
|
||||
* @typedef {{
|
||||
* primaryBoundary: Number,
|
||||
* secondaryBoundary: Number,
|
||||
@@ -19,15 +14,15 @@ import OrderedIndexArray from "./OrderedIndexArray"
|
||||
export default class FastSelectionModel {
|
||||
|
||||
/**
|
||||
* @param {Number[]} initialPosition Coordinates of the starting point of selection [primaryAxisValue, secondaryAxisValue].
|
||||
* @param {Rectangle[]} rectangles Rectangles that can be selected by this object.
|
||||
* @param {(rect: Rectangle) => BoundariesInfo} boundariesFunc A function that, given a rectangle, it provides the boundaries of such rectangle.
|
||||
* @param {(rect: Rectangle, selected: Boolean) => void} selectFunc A function that selects or deselects individual rectangles.
|
||||
* @param {Number[]} initialPosition
|
||||
* @param {Rectangle[]} rectangles
|
||||
* @param {(rect: Rectangle) => BoundariesInfo} boundariesFunc
|
||||
* @param {(rect: Rectangle, selected: Boolean) => void} selectFunc
|
||||
*/
|
||||
constructor(initialPosition, rectangles, boundariesFunc, selectFunc) {
|
||||
this.initialPosition = initialPosition
|
||||
this.finalPosition = initialPosition
|
||||
/** @type Metadata[] */
|
||||
/** @type {Metadata[]} */
|
||||
this.metadata = new Array(rectangles.length)
|
||||
this.primaryOrder = new OrderedIndexArray((element) => this.metadata[element].primaryBoundary)
|
||||
this.secondaryOrder = new OrderedIndexArray((element) => this.metadata[element].secondaryBoundary)
|
||||
@@ -36,7 +31,7 @@ export default class FastSelectionModel {
|
||||
this.primaryOrder.reserve(this.rectangles.length)
|
||||
this.secondaryOrder.reserve(this.rectangles.length)
|
||||
rectangles.forEach((rect, index) => {
|
||||
/** @type Metadata */
|
||||
/** @type {Metadata} */
|
||||
let rectangleMetadata = {
|
||||
primaryBoundary: this.initialPosition[0],
|
||||
secondaryBoundary: this.initialPosition[1],
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
export default class OrderedIndexArray {
|
||||
|
||||
/**
|
||||
* @param {(arrayElement: number) => number} compareFunction A function that, given acouple of elements of the array telles what order are they on.
|
||||
* @param {(number|array)} value Initial length or array to copy from
|
||||
* @param {(arrayElement: number) => number} comparisonValueSupplier
|
||||
* @param {number} value
|
||||
*/
|
||||
constructor(comparisonValueSupplier = (a) => a, value = null) {
|
||||
constructor(comparisonValueSupplier = v => v, value = null) {
|
||||
this.array = new Uint32Array(value)
|
||||
this.comparisonValueSupplier = comparisonValueSupplier
|
||||
this.length = 0
|
||||
this.currentPosition = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index The index of the value to return
|
||||
* @returns The element of the array
|
||||
*/
|
||||
/** @param {number} index */
|
||||
get(index) {
|
||||
if (index >= 0 && index < this.length) {
|
||||
return this.array[index]
|
||||
@@ -22,19 +19,11 @@ export default class OrderedIndexArray {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array used by this object.
|
||||
* @returns The array.
|
||||
*/
|
||||
getArray() {
|
||||
return this.array
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position that the value supplied should (or does) occupy in the aray.
|
||||
* @param {number} value The value to look for (it doesn't have to be part of the array).
|
||||
* @returns The position index.
|
||||
*/
|
||||
/** @param {number} value */
|
||||
getPosition(value) {
|
||||
let l = 0
|
||||
let r = this.length
|
||||
@@ -57,11 +46,7 @@ export default class OrderedIndexArray {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the element in the array.
|
||||
* @param element {number} The value to insert into the array.
|
||||
* @returns {number} The position into occupied by value into the array.
|
||||
*/
|
||||
/** @param {number} element */
|
||||
insert(element, comparisonValue = null) {
|
||||
let position = this.getPosition(this.comparisonValueSupplier(element))
|
||||
if (
|
||||
@@ -75,10 +60,7 @@ export default class OrderedIndexArray {
|
||||
return position
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element from the array.
|
||||
* @param {number} value The value of the element to be remove.
|
||||
*/
|
||||
/** @param {number} element */
|
||||
remove(element) {
|
||||
let position = this.getPosition(this.comparisonValueSupplier(element))
|
||||
if (this.array[position] == element) {
|
||||
@@ -86,10 +68,7 @@ export default class OrderedIndexArray {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element into the specified position from the array.
|
||||
* @param {number} position The index of the element to be remove.
|
||||
*/
|
||||
/** @param {number} position */
|
||||
removeAt(position) {
|
||||
if (position < this.currentPosition) {
|
||||
--this.currentPosition
|
||||
|
||||
Reference in New Issue
Block a user