Selection better JsDoc types documentation

This commit is contained in:
barsdeveloper
2022-12-29 15:17:19 +01:00
parent 8c4ef42d7c
commit d391480f2c
6 changed files with 86 additions and 78 deletions

View File

@@ -1,7 +1,9 @@
import OrderedIndexArray from "./OrderedIndexArray"
/**
* @typedef {import("../Blueprint").BoundariesInfo} BoundariesInfo
* @typedef {import("../element/NodeElement").default} NodeElement
* @typedef {typeof import("../Blueprint").default.nodeBoundariesSupplier} BoundariesFunction
* @typedef {typeof import("../Blueprint").default.nodeSelectToggleFunction} SelectionFunction
* @typedef {{
* primaryBoundary: Number,
* secondaryBoundary: Number,
@@ -9,15 +11,14 @@ import OrderedIndexArray from "./OrderedIndexArray"
* rectangle: Number
* onSecondaryAxis: Boolean
* }} Metadata
* @typedef {any} Rectangle
*/
export default class FastSelectionModel {
/**
* @param {Number[]} initialPosition
* @param {Rectangle[]} rectangles
* @param {(rect: Rectangle) => BoundariesInfo} boundariesFunc
* @param {(rect: Rectangle, selected: Boolean) => void} selectFunc
* @param {NodeElement[]} rectangles
* @param {BoundariesFunction} boundariesFunc
* @param {SelectionFunction} selectFunc
*/
constructor(initialPosition, rectangles, boundariesFunc, selectFunc) {
this.initialPosition = initialPosition
@@ -30,13 +31,14 @@ export default class FastSelectionModel {
this.rectangles = rectangles
this.primaryOrder.reserve(this.rectangles.length)
this.secondaryOrder.reserve(this.rectangles.length)
rectangles.forEach((rect, index) => {
/** @type {Metadata} */
let rectangleMetadata = {
primaryBoundary: this.initialPosition[0],
secondaryBoundary: this.initialPosition[1],
rectangle: index, // used to move both expandings inside the this.metadata array
onSecondaryAxis: false
rectangle: index,
onSecondaryAxis: false,
}
this.metadata[index] = rectangleMetadata
selectFunc(rect, false) // Initially deselected (Eventually)

View File

@@ -1,17 +1,23 @@
/**
* @typedef {import("../element/NodeElement").default} NodeElement
* @typedef {typeof import("../Blueprint").default.nodeBoundariesSupplier} BoundariesFunction
* @typedef {typeof import("../Blueprint").default.nodeSelectToggleFunction} SelectionFunction
* @typedef {{
* primaryBoundary: Number,
* secondaryBoundary: Number,
* insertionPosition?: Number,
* rectangle: Number
* onSecondaryAxis: Boolean
* }} Metadata
*/
export default class SimpleSelectionModel {
/**
* @typedef {{
* primaryInf: number,
* primarySup: number,
* secondaryInf: number,
* secondarySup: number
* }} BoundariesInfo
* @typedef {Number} Rectangle
* @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} selectToggleFunction A function that selects or deselects individual rectangles.
* @param {Number[]} initialPosition
* @param {NodeElement[]} rectangles
* @param {BoundariesFunction} boundariesFunc
* @param {SelectionFunction} selectToggleFunction
*/
constructor(initialPosition, rectangles, boundariesFunc, selectToggleFunction) {
this.initialPosition = initialPosition