fix distance
This commit is contained in:
parent
9f99ae5bae
commit
83aa0b9af5
|
|
@ -150,18 +150,21 @@ export class FolkDistanceField extends HTMLElement {
|
||||||
|
|
||||||
// Collect positions and assign unique IDs to all shapes
|
// Collect positions and assign unique IDs to all shapes
|
||||||
this.shapes.forEach((geometry, index) => {
|
this.shapes.forEach((geometry, index) => {
|
||||||
const rect = geometry.getClientRect();
|
const rect = geometry.getTransformDOMRect();
|
||||||
const { topLeft, topRight, bottomRight, bottomLeft } = rect;
|
const topLeftParent = rect.toParentSpace(rect.topLeft);
|
||||||
|
const topRightParent = rect.toParentSpace(rect.topRight);
|
||||||
|
const bottomLeftParent = rect.toParentSpace(rect.bottomLeft);
|
||||||
|
const bottomRightParent = rect.toParentSpace(rect.bottomRight);
|
||||||
|
|
||||||
// Convert rotated coordinates to NDC using container dimensions
|
// Convert rotated coordinates to NDC using container dimensions
|
||||||
const x1 = (topLeft.x / containerWidth) * 2 - 1;
|
const x1 = (topLeftParent.x / containerWidth) * 2 - 1;
|
||||||
const y1 = -((topLeft.y / containerHeight) * 2 - 1);
|
const y1 = -((topLeftParent.y / containerHeight) * 2 - 1);
|
||||||
const x2 = (topRight.x / containerWidth) * 2 - 1;
|
const x2 = (topRightParent.x / containerWidth) * 2 - 1;
|
||||||
const y2 = -((topRight.y / containerHeight) * 2 - 1);
|
const y2 = -((topRightParent.y / containerHeight) * 2 - 1);
|
||||||
const x3 = (bottomLeft.x / containerWidth) * 2 - 1;
|
const x3 = (bottomLeftParent.x / containerWidth) * 2 - 1;
|
||||||
const y3 = -((bottomLeft.y / containerHeight) * 2 - 1);
|
const y3 = -((bottomLeftParent.y / containerHeight) * 2 - 1);
|
||||||
const x4 = (bottomRight.x / containerWidth) * 2 - 1;
|
const x4 = (bottomRightParent.x / containerWidth) * 2 - 1;
|
||||||
const y4 = -((bottomRight.y / containerHeight) * 2 - 1);
|
const y4 = -((bottomRightParent.y / containerHeight) * 2 - 1);
|
||||||
|
|
||||||
const shapeID = index + 1; // Avoid zero to prevent hash function issues
|
const shapeID = index + 1; // Avoid zero to prevent hash function issues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -281,10 +281,12 @@ export class FolkShape extends HTMLElement {
|
||||||
this.#update();
|
this.#update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename to getTransformDOMRect()
|
getTransformDOMRectReadonly() {
|
||||||
getClientRect() {
|
|
||||||
return new TransformDOMRectReadonly(this.#rect);
|
return new TransformDOMRectReadonly(this.#rect);
|
||||||
}
|
}
|
||||||
|
getTransformDOMRect() {
|
||||||
|
return this.#rect;
|
||||||
|
}
|
||||||
|
|
||||||
// Similar to `Element.getClientBoundingRect()`, but returns an SVG path that precisely outlines the shape.
|
// Similar to `Element.getClientBoundingRect()`, but returns an SVG path that precisely outlines the shape.
|
||||||
getBoundingPath(): string {
|
getBoundingPath(): string {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue