mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-22 14:17:30 +08:00
Avoid using arrays when unnecessary
This commit is contained in:
@@ -6,13 +6,17 @@ import Utility from "../Utility"
|
||||
/** @extends {IDraggableControlTemplate<ColorHandlerElement>} */
|
||||
export default class ColorHandlerTemplate extends IDraggableControlTemplate {
|
||||
|
||||
/** @param {[Number, Number]} param0 */
|
||||
adjustLocation([x, y]) {
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @returns {[Number, Number]}
|
||||
*/
|
||||
adjustLocation(x, y) {
|
||||
const radius = Math.round(this.movementSpaceSize[0] / 2)
|
||||
x = x - radius
|
||||
y = -(y - radius)
|
||||
let [r, theta] = Utility.getPolarCoordinates([x, y])
|
||||
r = Math.min(r, radius), [x, y] = Utility.getCartesianCoordinates([r, theta])
|
||||
let [r, theta] = Utility.getPolarCoordinates(x, y)
|
||||
r = Math.min(r, radius), [x, y] = Utility.getCartesianCoordinates(r, theta)
|
||||
this.locationChangeCallback?.(x / radius, y / radius)
|
||||
x = Math.round(x + radius)
|
||||
y = Math.round(-y + radius)
|
||||
|
||||
@@ -125,7 +125,7 @@ export default class ColorPickerWindowTemplate extends WindowTemplate {
|
||||
* @param {Number} y in the range [0, 1]
|
||||
*/
|
||||
(x, y) => {
|
||||
this.color.setFromWheelLocation([x, y], this.color.V.value, this.color.A.value)
|
||||
this.color.setFromWheelLocation(x, y, this.color.V.value, this.color.A.value)
|
||||
this.fullColor.setFromHSVA(this.color.H.value, 1, 1, 1)
|
||||
this.element.requestUpdate()
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ import Utility from "../Utility"
|
||||
/** @extends {IDraggableControlTemplate<ColorHandlerElement>} */
|
||||
export default class ColorSliderTemplate extends IDraggableControlTemplate {
|
||||
|
||||
/** @param {[Number, Number]} param0 */
|
||||
adjustLocation([x, y]) {
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {[Number, Number]}
|
||||
*/
|
||||
adjustLocation(x, y) {
|
||||
x = Utility.clamp(x, 0, this.movementSpaceSize[0])
|
||||
y = Utility.clamp(y, 0, this.movementSpaceSize[1])
|
||||
this.locationChangeCallback?.(x / this.movementSpaceSize[0], 1 - y / this.movementSpaceSize[1])
|
||||
|
||||
@@ -47,8 +47,12 @@ export default class IDraggableControlTemplate extends IDraggableTemplate {
|
||||
})
|
||||
}
|
||||
|
||||
/** @param {[Number, Number]} param0 */
|
||||
adjustLocation([x, y]) {
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @returns {[Number, Number]}
|
||||
*/
|
||||
adjustLocation(x, y) {
|
||||
this.locationChangeCallback?.(x, y)
|
||||
return [x, y]
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ export default class IDraggableTemplate extends ITemplate {
|
||||
const dt = this.topBoundary() - this.blueprint.template.gridTopVisibilityBoundary()
|
||||
const db = this.blueprint.template.gridBottomVisibilityBoundary() - this.bottomBoundary()
|
||||
let avgY = Math.max((dt + db) / 2, minMargin)
|
||||
const delta = [dl - avgX, dt - avgY]
|
||||
this.blueprint.scrollDelta(delta, true)
|
||||
this.blueprint.scrollDelta(dl - avgX, dt - avgY, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export default class IResizeableTemplate extends NodeTemplate {
|
||||
onDrag: (location, movement) => {
|
||||
movement[1] = location[1] - this.element.topBoundary()
|
||||
if (this.setSizeY(this.element.sizeY - movement[1])) {
|
||||
this.element.addLocation([0, movement[1]], false)
|
||||
this.element.addLocation(0, movement[1], false)
|
||||
}
|
||||
},
|
||||
onEndDrag: () => this.endResize(),
|
||||
@@ -87,7 +87,7 @@ export default class IResizeableTemplate extends NodeTemplate {
|
||||
onDrag: (location, movement) => {
|
||||
movement[0] = location[0] - this.element.leftBoundary()
|
||||
if (this.setSizeX(this.element.sizeX - movement[0])) {
|
||||
this.element.addLocation([movement[0], 0], false)
|
||||
this.element.addLocation(movement[0], 0, false)
|
||||
}
|
||||
},
|
||||
onEndDrag: () => this.endResize(),
|
||||
@@ -98,7 +98,7 @@ export default class IResizeableTemplate extends NodeTemplate {
|
||||
movement[1] = location[1] - this.element.topBoundary()
|
||||
this.setSizeX(this.element.sizeX + movement[0])
|
||||
if (this.setSizeY(this.element.sizeY - movement[1])) {
|
||||
this.element.addLocation([0, movement[1]], false)
|
||||
this.element.addLocation(0, movement[1], false)
|
||||
}
|
||||
},
|
||||
onEndDrag: () => this.endResize(),
|
||||
@@ -117,7 +117,7 @@ export default class IResizeableTemplate extends NodeTemplate {
|
||||
movement[0] = location[0] - this.element.leftBoundary()
|
||||
movement[1] = location[1] - this.element.bottomBoundary()
|
||||
if (this.setSizeX(this.element.sizeX - movement[0])) {
|
||||
this.element.addLocation([movement[0], 0], false)
|
||||
this.element.addLocation(movement[0], 0, false)
|
||||
}
|
||||
this.setSizeY(this.element.sizeY + movement[1])
|
||||
},
|
||||
@@ -128,10 +128,10 @@ export default class IResizeableTemplate extends NodeTemplate {
|
||||
movement[0] = location[0] - this.element.leftBoundary()
|
||||
movement[1] = location[1] - this.element.topBoundary()
|
||||
if (this.setSizeX(this.element.sizeX - movement[0])) {
|
||||
this.element.addLocation([movement[0], 0], false)
|
||||
this.element.addLocation(movement[0], 0, false)
|
||||
}
|
||||
if (this.setSizeY(this.element.sizeY - movement[1])) {
|
||||
this.element.addLocation([0, movement[1]], false)
|
||||
this.element.addLocation(0, movement[1], false)
|
||||
}
|
||||
},
|
||||
onEndDrag: () => this.endResize(),
|
||||
|
||||
@@ -63,12 +63,12 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
|
||||
|
||||
static c2Clamped = LinkTemplate.clampedLine([0, 100], [200, 30])
|
||||
|
||||
/** @type {(location: Number[]) => void} */
|
||||
/** @param {[Number, Number]} location */
|
||||
#createKnot = location => {
|
||||
const knotEntity = new KnotEntity({}, this.element.sourcePin.entity)
|
||||
const knot = /** @type {NodeElementConstructor} */(ElementFactory.getConstructor("ueb-node"))
|
||||
.newObject(knotEntity)
|
||||
knot.setLocation(this.blueprint.snapToGrid(location))
|
||||
knot.setLocation(...this.blueprint.snapToGrid(...location))
|
||||
this.blueprint.addGraphElement(knot) // Important: keep it before changing existing links
|
||||
const link = /** @type {LinkElementConstructor} */(ElementFactory.getConstructor("ueb-link"))
|
||||
.newObject(
|
||||
@@ -86,7 +86,8 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
|
||||
this.element.querySelector(".ueb-link-area"),
|
||||
this.blueprint,
|
||||
undefined,
|
||||
(location) => this.#createKnot(location)
|
||||
/** @param {[Number, Number]} location */
|
||||
location => this.#createKnot(location)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ export default class KnotPinTemplate extends PinTemplate {
|
||||
],
|
||||
this.blueprint.template.gridElement
|
||||
)
|
||||
return this.blueprint.compensateTranslation(location)
|
||||
return this.blueprint.compensateTranslation(location[0], location[1])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ export default class PinTemplate extends ITemplate {
|
||||
[(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2],
|
||||
this.blueprint.template.gridElement
|
||||
)
|
||||
return this.blueprint.compensateTranslation(location)
|
||||
return this.blueprint.compensateTranslation(location[0], location[1])
|
||||
}
|
||||
|
||||
getClickableElement() {
|
||||
|
||||
Reference in New Issue
Block a user