-
+
@@ -44,7 +44,7 @@
-
+
@@ -64,35 +64,18 @@
const source = document.getElementById('source');
const target = document.getElementById('target');
- // Update rope connection points
function updateRopePoints() {
if (!source || !target) return;
- // Get the shapes' transforms
- const sourceTransform = source.getTransformDOMRect();
- const targetTransform = target.getTransformDOMRect();
+ const sourceRect = space.getElementScreenRect(source);
+ const targetRect = space.getElementScreenRect(target);
- // Get center points in local space
- const sourceCenter = {
- x: sourceTransform.x + sourceTransform.width / 2,
- y: sourceTransform.y + sourceTransform.height / 2,
- };
-
- const targetCenter = {
- x: targetTransform.x + targetTransform.width / 2,
- y: targetTransform.y + targetTransform.height / 2,
- };
-
- // Convert to screen space
- const sourcePoint = space.localToScreen(sourceCenter, 'front');
- const targetPoint = space.localToScreen(targetCenter, 'back');
-
- // Update rope
- rope.sourceRect = { x: sourcePoint.x, y: sourcePoint.y, width: 0, height: 0 };
- rope.targetRect = { x: targetPoint.x, y: targetPoint.y, width: 0, height: 0 };
+ if (sourceRect && targetRect) {
+ rope.sourceRect = sourceRect;
+ rope.targetRect = targetRect;
+ }
}
- // Update on animation frame
function animate() {
updateRopePoints();
requestAnimationFrame(animate);