From 6a62d6bea120a7a67ff373c9fcdd5390b77f0157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cchrisshank=E2=80=9D?= Date: Thu, 5 Dec 2024 12:50:56 -0800 Subject: [PATCH] rename properties in RotatedDOMRect --- src/common/rotated-dom-rect.ts | 48 +++++++++++++++++----------------- src/folk-distance-field.ts | 7 +---- src/folk-rope.ts | 4 +-- src/folk-shape.ts | 16 ++++++------ 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/common/rotated-dom-rect.ts b/src/common/rotated-dom-rect.ts index a145a66..290dfa1 100644 --- a/src/common/rotated-dom-rect.ts +++ b/src/common/rotated-dom-rect.ts @@ -84,44 +84,44 @@ export class RotatedDOMRect implements DOMRect { return this.#center; } - #topLeftCorner: Point | null = null; - get topLeftCorner() { - if (this.#topLeftCorner === null) { - this.#topLeftCorner = Vector.rotateAround({ x: this.x, y: this.y }, this.center, this.rotation); + #topLeft: Point | null = null; + get topLeft() { + if (this.#topLeft === null) { + this.#topLeft = Vector.rotateAround({ x: this.x, y: this.y }, this.center, this.rotation); } - return this.#topLeftCorner; + return this.#topLeft; } - #topRightCorner: Point | null = null; - get topRightCorner() { - if (this.#topRightCorner === null) { - this.#topRightCorner = Vector.rotateAround({ x: this.right, y: this.y }, this.center, this.rotation); + #topRight: Point | null = null; + get topRight() { + if (this.#topRight === null) { + this.#topRight = Vector.rotateAround({ x: this.right, y: this.y }, this.center, this.rotation); } - return this.#topRightCorner; + return this.#topRight; } - #bottomRightCorner: Point | null = null; - get bottomRightCorner() { - if (this.#bottomRightCorner === null) { - this.#bottomRightCorner = Vector.rotateAround({ x: this.right, y: this.bottom }, this.center, this.rotation); + #bottomRight: Point | null = null; + get bottomRight() { + if (this.#bottomRight === null) { + this.#bottomRight = Vector.rotateAround({ x: this.right, y: this.bottom }, this.center, this.rotation); } - return this.#bottomRightCorner; + return this.#bottomRight; } - #bottomLeftCorner: Point | null = null; - get bottomLeftCorner() { - if (this.#bottomLeftCorner === null) { - this.#bottomLeftCorner = Vector.rotateAround({ x: this.x, y: this.bottom }, this.center, this.rotation); + #bottomLeft: Point | null = null; + get bottomLeft() { + if (this.#bottomLeft === null) { + this.#bottomLeft = Vector.rotateAround({ x: this.x, y: this.bottom }, this.center, this.rotation); } - return this.#bottomLeftCorner; + return this.#bottomLeft; } #reset() { this.#center = null; - this.#topLeftCorner = null; - this.#topRightCorner = null; - this.#bottomLeftCorner = null; - this.#bottomRightCorner = null; + this.#topLeft = null; + this.#topRight = null; + this.#bottomLeft = null; + this.#bottomRight = null; } /** Returns all the vertices in worldspace coordinates */ diff --git a/src/folk-distance-field.ts b/src/folk-distance-field.ts index a9d371f..4d09173 100644 --- a/src/folk-distance-field.ts +++ b/src/folk-distance-field.ts @@ -151,12 +151,7 @@ export class FolkDistanceField extends HTMLElement { // Collect positions and assign unique IDs to all shapes this.shapes.forEach((geometry, index) => { const rect = geometry.getClientRect(); - const { - topLeftCorner: topLeft, - topRightCorner: topRight, - bottomRightCorner: bottomRight, - bottomLeftCorner: bottomLeft, - } = rect; + const { topLeft, topRight, bottomRight, bottomLeft } = rect; // Convert rotated coordinates to NDC using container dimensions const x1 = (topLeft.x / containerWidth) * 2 - 1; diff --git a/src/folk-rope.ts b/src/folk-rope.ts index dc8258d..e879468 100644 --- a/src/folk-rope.ts +++ b/src/folk-rope.ts @@ -125,7 +125,7 @@ export class FolkRope extends FolkBaseConnection { let target: Point; if (sourceRect instanceof RotatedDOMRect) { - source = Vector.lerp(sourceRect.bottomRightCorner, sourceRect.bottomLeftCorner, 0.5); + source = Vector.lerp(sourceRect.bottomRight, sourceRect.bottomLeft, 0.5); } else { source = { x: sourceRect.x + sourceRect.width / 2, @@ -134,7 +134,7 @@ export class FolkRope extends FolkBaseConnection { } if (targetRect instanceof RotatedDOMRect) { - target = Vector.lerp(targetRect.bottomRightCorner, targetRect.bottomLeftCorner, 0.5); + target = Vector.lerp(targetRect.bottomRight, targetRect.bottomLeft, 0.5); } else { target = { x: targetRect.x + targetRect.width / 2, diff --git a/src/folk-shape.ts b/src/folk-shape.ts index 24d22b7..019dbc0 100644 --- a/src/folk-shape.ts +++ b/src/folk-shape.ts @@ -396,10 +396,10 @@ export class FolkShape extends HTMLElement { // Map handle names to corner indices const handleToCornerIndex: Record = { - 'resize-nw': rect.topLeftCorner, - 'resize-ne': rect.topRightCorner, - 'resize-se': rect.bottomRightCorner, - 'resize-sw': rect.bottomLeftCorner, + 'resize-nw': rect.topLeft, + 'resize-ne': rect.topRight, + 'resize-se': rect.bottomRight, + 'resize-sw': rect.bottomLeft, }; const currentPos = handleToCornerIndex[handle]; @@ -669,10 +669,10 @@ export class FolkShape extends HTMLElement { // Map each resize handle to its opposite corner index const OPPOSITE_CORNERS = { - 'resize-se': rect.topLeftCorner, - 'resize-sw': rect.topRightCorner, - 'resize-nw': rect.bottomRightCorner, - 'resize-ne': rect.bottomLeftCorner, + 'resize-se': rect.topLeft, + 'resize-sw': rect.topRight, + 'resize-nw': rect.bottomRight, + 'resize-ne': rect.bottomLeft, } as const; // Get the opposite corner for the current resize handle