Skip to content

Commit

Permalink
rename properties in RotatedDOMRect
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Dec 5, 2024
1 parent 07203f0 commit 6a62d6b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
48 changes: 24 additions & 24 deletions src/common/rotated-dom-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 1 addition & 6 deletions src/folk-distance-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/folk-rope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/folk-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ export class FolkShape extends HTMLElement {

// Map handle names to corner indices
const handleToCornerIndex: Record<string, Point> = {
'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];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a62d6b

Please sign in to comment.