From 7cc57e966b20b67ecd2bc6dea47a304f96a28d38 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Fri, 24 Apr 2026 13:23:44 +0200 Subject: [PATCH] perf: use cached body dimensions in tick, remove redundant style sets --- lib/gravity-engine.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/gravity-engine.ts b/lib/gravity-engine.ts index 6fe2425..fac6e57 100644 --- a/lib/gravity-engine.ts +++ b/lib/gravity-engine.ts @@ -192,36 +192,23 @@ export class GravityEngine { this.bodies.forEach((body) => { if (body.isDragging) { - // Only update visually while dragging, physics are paused - body.el.style.position = "fixed"; - body.el.style.left = "0px"; - body.el.style.top = "0px"; body.el.style.transform = `translate(${body.x}px, ${body.y}px)`; return; } - // Apply Gravity body.vy += gravity; body.x += body.vx; body.y += body.vy; - // Apply Air Friction body.vx *= 0.99; body.vy *= 0.99; - const rect = body.el.getBoundingClientRect(); - - // Floor Collision - if (body.y + rect.height > floorY) { - body.y = floorY - rect.height; + if (body.y + body.height > floorY) { + body.y = floorY - body.height; body.vy *= bounce; - body.vx *= 0.9; // Ground friction + body.vx *= 0.9; } - // Render Step - body.el.style.position = "fixed"; - body.el.style.left = "0px"; - body.el.style.top = "0px"; body.el.style.transform = `translate(${body.x}px, ${body.y}px)`; });